6

How to disable autoload in jqGrid and load data manually when I need it?

Thanks.

andser
  • 555
  • 2
  • 6
  • 13

4 Answers4

12

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
2

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');
         }
akjoshi
  • 15,374
  • 13
  • 103
  • 121
Igor
  • 21
  • 2
0

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)

Grigory Kislin
  • 16,647
  • 10
  • 125
  • 197
0

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; }
}
Community
  • 1
  • 1