将 jqGrid 数据添加回 json



使用 jqGrid 的内联编辑:

我在变量"jsonDataStr"中有json数据。数据使用 jqGrid 显示。

 $("#myGrid").jqGrid({
            colModel: [
                { name: 'authenticate', width: "80" ,align: 'center',formatter: 'checkbox',editable:true,edittype:"checkbox", editoptions:{value: "Yes:No"}, formoptions:{ rowpos:1, label: "Authenticate ", elmprefix:"(*)"},editrules:{required:true} },
                { name: 'authorize', width: "80" ,align: 'center',formatter: 'checkbox',editable:true,edittype:"checkbox", editoptions:{value: "Yes:No"}, formoptions:{ rowpos:1, label: "Authorize ", elmprefix:"(*)"},editrules:{required:true}},
            ],
            pager: '#pagerTable',
            colNames:[ 'authenticate','authorize'],
            datatype: "jsonstring",
            datastr: jsonDataStr,
            jsonReader: { repeatitems: false },
            viewrecords: true,pginput : false, forceFit :true,
            height: 83,caption :"Permissions",
            ignoreCase: true,scrollBar : false
        });

        $("#myGrid").navGrid("#pagerTable",{edit:false,add:false,del:false,search:false,refresh:false});
        $("#myGrid").inlineNav("#pagerTable");

它正在正确显示。

现在,当我保存行时,我想将数据保存到同一个json变量'jsonDataStr'。此外,我想在 json 行中添加信息,

如添加、修改或删除。有什么简单的方法可以做到这一点吗?

谁能帮忙?

也许这会有所帮助

var jsonDataStr = "some Data you need";
$("#YourGrid").jqGrid('setGridParam', { jsonDataStr: jsonDataStr }); 
$('#YourGrid').trigger('reloadGrid');

最新更新