简体   繁体   中英

How to reload the data in jquery jqGrid whenever the json value is changes?

I have created a jquery grid and loaded the json data into it.. And i have some radiobuttons on pop up.. based on that selection the json value is changed. For the first time , the json is loaded into gqgrid. but when i select other radio button the json value is changed but that new json is not loaded into jqgrid. The old json is showing.

I have tried ,

    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
        });

Try this first clear the grid data then reset the data property of the grid options to your new json data.

  var grid = $("#grid_json");

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM