设置默认值内联添加Jqgrid [英] Setting default Value Inline Add Jqgrid

查看:192
本文介绍了设置默认值内联添加Jqgrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我在系统中有一个需求,在该系统中,我需要重复输入最后一行中的许多数据. 实际上,这是我的网格:

Currently I have a requirement in a system where I need to repeat much of the data from the last row entered. Actualy this is my Grid:

$('#list').jqGrid({
        colNames: ['VendedorId', 'Vendedor', 'Especie', 'Cabezas', 'Kilos', 'Precio', 'Guías Venta', 'Vencimiento'],
        colModel: [
            { hidden: true, name: 'VendedorId' },
            { editable: true, width: 160, edittype: 'select', editoptions: { dataUrl: '/Clientes/CmbClientes' }, editrules: { required: true }, name: 'Vendedor' },
            { editable: true, width: 70, edittype: 'select', editoptions: { dataUrl: '/Especies/CmbEspecie' }, editrules: { required: true }, name: 'Especie' },
            { align: 'right', width: 50, editable: true, editoptions: { size: 3, maxlength: 3 }, editrules: { number: true }, formatter: 'number', formatoptions: { decimalPlaces: 0 }, name: 'Cabezas' },
            { align: 'right', width: 50, editable: true, editrules: { number: true }, formatter: 'number', formatoptions: { decimalPlaces: 0 }, name: 'Kilos' },
            { align: 'right', width: 50, editable: true, editrules: { number: true, required: true }, formatter: 'currency', formatoptions: { prefix: '$',decimalPlaces: 2  }, name: 'Precio' },
            { editable: true, width: 50, editoptions: { maxlength: 20 }, name: 'GuiasVenta' },
            { align: 'right', width: 70, editable: true, editoptions: { size: 3, maxlength: 3 }, editrules: { number: true, required: true }, formatter: 'number', formatoptions: { decimalPlaces: 0 }, name: 'Vencimiento' }
        ],
        url: '@Url.Action("ListVendedores")',
        datatype: 'json',
        editurl: '@Url.Action("SaveVendedor")',
        mtype: 'POST',
        pager: '#vendedoresPager',
        prmNames: { id: 'RemateId' },
        rowList: [5, 10, 15, 20],
        sortname: 'FeriaId',
        viewrecords: true,
        width: 850
    }).jqGrid('navGrid', '#vendedoresPager', { add: false, edit: false, del:true ), search: false },{},{},{ url: '/Remates/BorrarVendedor' }).
        jqGrid('inlineNav', '#vendedoresPager',
            {
                add : true,
                edit : true,
                save : true,
                addParams: {
                    addRowParams: {
                        position: "afterSelected",
                        keys: true,
                        extraparam: {
                            ...
                        }
                    }
                },
                editParams: {
                    keys: true,
                    extraparam: {
                        ...
                    }
                }
            });

在添加第一行时,没有默认数据,但是字段Vendedor,Especie,GuíasVenta和Vencimiento应当重复最后输入的内容.

When adding the first row no default data, but then fields Vendedor, Especie, Guías Venta and Vencimiento should repeat the last entered.

在这种情况下,我想象有两种可能的解决方案,一种是使用事件jqGridInlineEditRow,另一种是使用自动完成. 已阅读此有关qGridInlineEditRow的问题.但是在这种情况下,因为我可以从网格的最后一行获取数据,以及如何将数据加载到新行中. 并阅读此有关自动填充的问题.

In this scenario I imagine two possible solutions, one is using the event jqGridInlineEditRow, and the other is using autocomplete. Have read this Question about qGridInlineEditRow. But in this case as I can get the data from the last row of the grid and how it should load the data into the new row. And read this Question about autocomplete.

也许还有其他解决方案可以阅读以更好地近似该解决方案.

Maybe there other solutions that can read to get a better approximation to the solution.

任何人都可以帮忙吗?

更新15/04/2013

我将添加按钮替换为自定义按钮,这是代码:

i replace the Add button for a custom button this is the code:

    $("#Agregar").click(function () {
    var parameters =
        {
            initdata: {},
            position: "first",
            useDefValues: true,
            useFormatter: false,
            addRowParams: {
                keys: true,
                extraparam: {
                    ...
                },
                aftersavefunc: function (rowid) {
                    var grid = jQuery('#vendedores');
                    lastSavedAddData = grid.jqGrid("getRowData", rowid);
                },
                oneditfunc: function (rowid) {
                    var name;
                    var grid = jQuery('#vendedores');
                    for (name in lastSavedAddData) {
                        if (lastSavedAddData.hasOwnProperty(name)) {
                            $('#' + rowid +"_"+  name).val(lastSavedAddData[name]);
                        }
                    }
                }
            }
        };
    jQuery("#vendedores").jqGrid('addRow', parameters);
});

但这仅适用于文本框,不适用于组合框

But this work only for text box but not for a combo

推荐答案

如果我正确理解您的问题,则在开始下一个要添加的过程中,jQuery UI自动完成的用法独立于对最后添加的行的输入字段的初始填充

If I understand correctly your question the usage of jQuery UI Autocomplete is independent from initial filling of the input fields of the last added line during starting the next like to add.

在我看来,您可以保存保存在addRowParams中定义的aftersavefunc回调内的最后添加的行中的数据(或替代使用jqGridInlineAfterSaveRow事件).您可以使用oneditfunc来设置新的类似值中最后输入的值.例如,您可以使用

It seems to me that you can save data saved in the last added line inside of aftersavefunc callback defined in addRowParams (or use jqGridInlineAfterSaveRow event alternatively). You can use oneditfunc to set the last entered values in the new like. For example you can use

addRowParams: {
    position: "afterSelected",
    keys: true,
    extraparam: {
        ...
    },
    aftersavefunc: function (rowid) {
        lastSavedAddData = $(this).jqGrid("getRowData", rowid);
    },
    oneditfunc: function (rowid) {
        var name;
        for (name in lastSavedAddData) {
            if (lastSavedAddData.hasOwnProperty(name)) {
                $("#" + $.jgrid.jqID(rowid + "_" + name)).val(lastSavedAddData[name]);
            }
        }
    }
}

其中,lastSavedAddData应该在某些外部范围中定义.它不是经过测试的代码.我只是想展示主要思想.您可以扩展oneditfunc的代码以支持在编辑行中使用的更多不同控件.

where lastSavedAddData should be defined in some outer scope. It's not tested code. I just wanted to show the main idea. You can extend the code of oneditfunc to support more different controls which you use in editing line.

这篇关于设置默认值内联添加Jqgrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆