jqgrid将数据添加到网格而不回发

jqgrid将数据添加到网格而不回发,jqgrid,Jqgrid,我需要让用户在不发回数据的情况下将数据添加到网格中。我原以为cellsubmit:'clientArray'可以实现这一点,但我仍然遇到“未设置URL”错误。下面的代码是我从Oleg“借用”的网格,但带有cellsubmit集 $(document).ready(function () { 'use strict'; var myData = [ { id: "1", invdate: "2007-10-01", name:

我需要让用户在不发回数据的情况下将数据添加到网格中。我原以为cellsubmit:'clientArray'可以实现这一点,但我仍然遇到“未设置URL”错误。下面的代码是我从Oleg“借用”的网格,但带有cellsubmit集

    $(document).ready(function () {
        'use strict';
        var myData = [
                { id: "1", invdate: "2007-10-01", name: "test", note: "note", amount: "200.00", tax: "10.00", closed: true, ship_via: "TN", total: "210.00" },
                { id: "2", invdate: "2007-10-02", name: "test2", note: "note2", amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                { id: "3", invdate: "2011-07-30", name: "test3", note: "note3", amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
                { id: "4", invdate: "2007-10-04", name: "test4", note: "note4", amount: "200.00", tax: "10.00", closed: true, ship_via: "TN", total: "210.00" },
                { id: "5", invdate: "2007-10-31", name: "test5", note: "note5", amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                { id: "6", invdate: "2007-09-06", name: "test6", note: "note6", amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
                { id: "7", invdate: "2011-07-30", name: "test7", note: "note7", amount: "200.00", tax: "10.00", closed: true, ship_via: "TN", total: "210.00" },
                { id: "8", invdate: "2007-10-03", name: "test8", note: "note8", amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                { id: "9", invdate: "2007-09-01", name: "test9", note: "note9", amount: "400.00", tax: "30.00", closed: false, ship_via: "TN", total: "430.00" },
                { id: "10", invdate: "2007-09-08", name: "test10", note: "note10", amount: "500.00", tax: "30.00", closed: true, ship_via: "TN", total: "530.00" },
                { id: "11", invdate: "2007-09-08", name: "test11", note: "note11", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" },
                { id: "12", invdate: "2007-09-10", name: "test12", note: "note12", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" }
            ],
            myGrid = $("#list"),
            lastSel = -1,
            inEdit;

        myGrid.jqGrid({
            datatype: 'local',
            data: myData,
            colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Closed', 'Shipped via', 'Notes'],
            colModel: [
                { name: 'id', index: 'id', width: 70, align: 'center', sorttype: 'int', formatter: 'int', editable: true,
                    editoptions: {
                        //readonly: 'readonly',
                        disabled: 'disabled',
                        dataInit: function (elem) {
                            if (!inEdit) {
                                $(elem).val($.jgrid.randId());
                            }
                        }
                    }
                },
                { name: 'invdate', index: 'invdate', width: 75, align: 'center', sorttype: 'date',
                    formatter: 'date', formatoptions: { newformat: 'd-M-Y' }, datefmt: 'd-M-Y',
                    editable: true
                },
                { name: 'name', index: 'name', width: 65, editable: true },
                { name: 'amount', index: 'amount', width: 75, sorttype: 'int', formatter: 'int', editable: true,
                    editoptions: {
                        dataInit: function (elem) {
                            $(elem).mask("99:99");
                        }
                    }
                },
                { name: 'tax', index: 'tax', width: 52, sorttype: 'int', formatter: 'int', editable: true },
                { name: 'total', index: 'total', width: 60, sorttype: 'int', formatter: 'int', editable: true },
                { name: 'closed', index: 'closed', width: 67, align: 'center', formatter: 'checkbox', editable: true,
                    edittype: 'checkbox', editoptions: { value: 'Yes:No', defaultValue: 'Yes' }
                },
                { name: 'ship_via', index: 'ship_via', width: 95, align: 'center', formatter: 'select', editable: true,
                    edittype: 'select', editoptions: { value: 'FE:FedEx;TN:TNT;IN:Intim', defaultValue: 'Intime' }
                },
                { name: 'note', index: 'note', width: 60, sortable: false, editable: true,
                    editoptions: {
                        dataInit: function (elem) {
                            $(elem).val(inEdit ? "in Edit" : "in Add");
                        }
                    }
                }
            ],
            rowNum: 10,
            rowList: [5, 10, 20],
            pager: '#pager',
            gridview: true,
            ignoreCase: true,
            rownumbers: true,
            sortname: 'invdate',
            viewrecords: true,
            cellsubmit: 'clientArray',
            sortorder: 'desc',
            caption: 'Combining Advanced Searching and Toolbar Searching in one grid',
            height: 'auto'
        });
        myGrid.jqGrid('navGrid', '#pager',
            { del: false, search: false },
            { // Edit
                recreateForm: true,
                beforeInitData: function () {
                    inEdit = true;
                }
            },
            { // Add
                recreateForm: true,
                beforeInitData: function () {
                    inEdit = false;
                }
            });
    });

您尝试使用表单编辑来编辑jqGrid当前不支持的本地数据。然而,我是如何描述的,一个人可以实现这一点


我从jqGrid获得了演示,并进行了一些修改,以使用当前版本的jqGrid。相应的。演示可以根据需要进行更多操作,例如上下文菜单。您可以删除不需要的功能。

谢谢,这就是我一直在寻找的功能。我不知道为什么我在搜索中没有找到最初的答案,但我投了赞成票,因为它确实回答了我的问题。