在jqgrid中使用内联编辑时如何将所有数据发送到服务器

时间:2012-09-03 09:39:54

标签: jqgrid jqgrid-asp.net jqgrid-formatter jqgrid-inlinenav

我在jqgrid中首发。我在页面中有一个jqgrid和按钮。我希望用户编辑行示例row1,row2,row3,...,然后单击按钮,单击按钮时将数据rows1,2,3发送到服务器。但是jqGrid在用户编辑行时向服务器发送数据。请给我解决我的问题的方法。谢谢所有

我写这段代码

  var mydata = [
{ id: "1", REQUEST_ID: "2007-10-01", WAYBILL_NO: "test", COST_ID: "note", COST_NAME: "200.00", COST_AMOUNT: "10.00", Subcategory: "1" },
{ id: "2", REQUEST_ID: "2007-10-02", WAYBILL_NO: "test2", COST_ID: "note2", COST_NAME: "300.00", COST_AMOUNT: "20.00", Subcategory: "2" },
{ id: "3", REQUEST_ID: "2007-09-01", WAYBILL_NO: "test3", COST_ID: "note3", COST_NAME: "400.00", COST_AMOUNT: "30.00", Subcategory: "1" },
{ id: "12", REQUEST_ID: "2007-09-10", WAYBILL_NO: "test11", COST_ID: "note12", COST_NAME: "500.00", COST_AMOUNT: "30.00", Subcategory: "1" }
];



            var localstr = "0:Select Ones;";
            localstr += "1:Dollar";
            localstr += ";2:Pond";
            localstr += ";3:Youro";
            localstr += ";4:Derham";

            var lastSel;
            var grid = jQuery("#list");
            grid.jqGrid({

                datatype: "local",
                data: mydata,
                ajaxGridOptions: { cache: false },
                loadonce: true,
                direction: "rtl",


                height: 'auto',
                colNames: ['RequestID', 'WayBillNo', 'CostId', 'CostName', 'Amount', 'CurrencyUnit '],
                colModel: [
                    { name: 'REQUEST_ID', width: 100, sortable: true, hidden: true },
                        { name: 'WAYBILL_NO', width: 100, sortable: true, hidden: true },
                        { name: 'COST_ID', index: 'COST_ID', width: 200, sortable: true, hidden: true },
                        { name: 'COST_NAME', width: 200, sortable: true },
                        { name: 'COST_AMOUNT', width: 100, sortable: true, editable: true },
                      { name: 'Subcategory', index: 'Subcategory', width: 200, formatter: 'select', editable: true, edittype: 'select', editoptions: { value: localstr} }
                ],
                sortname: 'Name',
                viewrecords: true,
                rownumbers: true,
                sortorder: "desc",
                editurl: 'clientArray',
                onSelectRow: function (id) {

                    if (id && id !== lastSel) {

                        grid.saveRow(lastSel, true, 'clientArray'); 

                        grid.jqGrid('restoreRow', lastSel);
                        grid.jqGrid('editRow', id, true, null, null, 'clientArray');
                        lastSel = id;

                    }


                },

                pager: '#pager',
                caption: ""
            }).jqGrid('navGrid', '#pager', { edit: true, add: true, del: false, search: false, refresh: false });

但是什么是clientArray,如何使用数据ino clientArray并发送到服务器? 谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

您可以将所有数据更改存储到网格中,然后创建按钮以便用户单击此按钮将所有数据发送到服务器

您将代码更改为此

onSelectRow: function (id) {
                    if (id && id !== lastSel) {
                        grid.jqGrid('restoreRow', lastSel);
                        grid.saveRow(lastSel,true,'clientArray');
                        grid.jqGrid('restoreRow',lastSel);

                        grid.jqGrid('editRow', id, true, null, null, 'clientArray');

                    }
                },

以及从网格中读取数据

$("#btnSave").click(function(){
    var row=$("#list").jqGrid('getRowData',1);
alert(row.cost_id)
});