How to disable autoload in jqGrid?
Asked Answered
G

4

6

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

Thanks.

Gazpacho answered 17/7, 2010 at 12:2 Comment(0)
S
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.

Schoolman answered 20/7, 2010 at 17:23 Comment(0)
B
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');
         }
Burdick answered 9/7, 2012 at 7:52 Comment(0)
M
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)

Mcgruter answered 9/6, 2013 at 22:37 Comment(0)
L
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; }
}
Lashay answered 16/1, 2016 at 10:17 Comment(1)
This is not answer to question.Hellenize

© 2022 - 2024 — McMap. All rights reserved.