How to disable autoload in jqGrid?

早过忘川 提交于 2019-12-03 07:44:24
Oleg

If you set datatype to 'local' the data from the server will be not loaded. To force the loading of data you can change datatype to 'json' or 'xml' with respect of setGridParam method (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options and http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods#grid_related_methods) and then call trigger("reloadGrid") method.

See jqGrid is not loading data which has also the information what you asked.

Igor

Just don't set the default URL in the table. And install it just when you need to load data (for example by pressing a button) and then .trigger("reloadGrid").

Example for you:

jQuery("#grid").jqGrid(
         { 
            //Simply comment out the URL
            //url             :"salepointsprovider.php", 
            datatype:"json",
            colModel      :[
                {name:'SalePointId', index:'SalePointId'},
                {name:'Name', index:'Name'}
            ]
         }

 $('#ShowRecordsButton').click(function () {
           jQuery("#grid").jqGrid('setGridParam',
            {url:"salepointprovider.php?SalePointId=" + argSalePointId, page:1});
           jQuery("#grid").trigger('reloadGrid');
         }

My grid without url send requests to server:

.../?_search=false&nd=1370817124473&rows=20&page=1&sidx=&sord=asc

Set datatype: "local" solve problem. Reload grid by

`function reloadGrid(gridId, gridData){
    $(gridId).jqGrid('clearGridData');  // need for nonempty grig (see http://www.trirand.com/blog/?page_id=393/help/triggerreloadgrid-not-work/)
    $(gridId).jqGrid('setGridParam', {data: gridData}).trigger('reloadGrid');
}
`

No need to change datatype (at least for my json case it is recognized)

qwertydodo

In treegrid you couldn't use datatype = 'local'. So instead 'local', I set datatype = 'jsonstring', define empty fake data and jsonReader. jsonReader should be defined correctly according to your retrieved data. Thanks for Oleg's answer. And, when I need to load data, I simply change datatype to 'json'.

var fakeData ={
    rows: []
};
...
datatype: 'jsonstring',
datastr: fakeData,
...
jsonReader: {
    repeatitems: false,
    root: function (obj) { return obj.rows; },
    page: function (obj) { return 1; },
    total: function (obj) { return 1; },
    records: function (obj) { return obj.length; }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!