javascript - 当json值发生变化时,如何重新加载jquery jqGrid中的数据?

标签 javascript jquery json jqgrid

我创建了一个 jquery 网格并将 json 数据加载到其中..并且我弹出了一些单选按钮..根据该选择,json 值发生了更改。第一次,json 被加载到 gqgrid 中。但是当我选择其他单选按钮时,json 值会更改,但新的 json 不会加载到 jqgrid 中。显示旧的 json。

我已经尝试过,

    obj.datatype = "local";
        obj.viewrecords = true;
        obj.rowNum = 20;
        obj.pager = "#jqGridPager";
        obj.data = jsonValue;
        obj.localReader = {repeatitems: true};
        obj.rowList = [20,30,50];
        obj.loadonce = true; 
        obj.colModel = [
                        { "label": 'Id', "name": 'studentId', "width": "150" , "key" : true},
                        { "label": 'No', "name": 'studentNo', "width": "150"},
                        { "label": 'Name', "name": 'studentName', "width": "150"},
                        { "label": 'Phone', "name": 'studentPhone', "width": "150"},
                        { "label":'Email', "name": 'primaryContactEmail', "width": "150" },
                        { "label":'Address', "name": 'studentAddress', "width": "150" }

                    ];
        obj.multiselect = true;
        obj.navOptions = { reloadGridOptions: { fromServer: true } };
        //console.log(obj)
    $("#grid_json").jqGrid(obj).jqGrid('filterToolbar').navGrid('#jqGridPager',
                { edit: false, add: false, del: false, search: true, refresh: true, view: true, position: "left", cloneToTop: true },
    {
        editCaption: "The Edit Dialog",
        recreateForm: true,
        checkOnUpdate : true,
        checkOnSubmit : true,
        closeAfterEdit: true,
        errorTextFormat: function (data) {
            return 'Error: ' + data.responseText
        }
    },
    // options for the Add Dialog
    {
        closeAfterAdd: true,
        recreateForm: true,
        errorTextFormat: function (data) {
            return 'Error: ' + data.responseText
        }
    },
    // options for the Delete Dailog
    {
        errorTextFormat: function (data) {
            return 'Error: ' + data.responseText
        }
    },
    {
     multipleSearch: true
   }

    )
    // add first custom button
   /*  $('#grid_json').navButtonAdd('#jqGridPager',
        {
            buttonicon: "ui-icon-mail-closed",
            title: "Send Mail",
            caption: "Send Mail",
            position: "last",
           // onClickButton: customButtonClicked
        }); */


   /// add second custom button
   $('#grid_json').navButtonAdd('#jqGridPager',
        {
            buttonicon: "ui-icon-pencil",
            title: "Edit",
            caption: "Edit",
            position: "last",
            //onClickButton: customButtonClicked
        });

最佳答案

首先尝试清除网格数据,然后将网格选项的数据属性重置为新的 json 数据。

  var grid = $("#grid_json");

   grid.jqGrid('clearGridData').jqGrid('setGridParam', {
    data: new_data
   }).trigger('reloadGrid', [{ page: 1 }]);

关于javascript - 当json值发生变化时,如何重新加载jquery jqGrid中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37936620/

相关文章:

python - 从 JSON 生成数据帧

javascript - Var 更改后不会更新

javascript - 如何访问 enyo 类型的子组件?

javascript - jQuery fadeOut 在循环时不起作用

json - Swift:如何从 JSON 数据读取 JSON 数据

javascript - JSON 按名称分组然后显示最新记录

javascript - 将变量传递到另一个页面并运行该变量

javascript - 文本区域验证中的错误消息的 ng-class 或 ng-style

javascript - 数组在 javascript 中未定义

javascript - Highcharts 单独类别