0

我在 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,如何使用clientArray中的数据并发送到服务器?谢谢你的帮助。

4

1 回答 1

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)
});
于 2012-09-03T15:25:46.260 回答