Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqGrid - how to set grid to NOT load any data initially?

Tags:

How can you create a grid but not load any data?

If I omit the url option then the loadError callback is triggered.

Currently we set url:NoData.json where NoData.json is a static file with no rows in it.

Issue is in our loadComplete callback we'd like to dipslay a message if the grid contains no data - except we don't want to display this message on the initial load. Currently we handles this as follows:

//jqGrid load complete handler function loadComp(grid) {     if (grid.getGridParam("url") != "NoData.json" && grid.getGridParam("records") == 0) {         setStatus("Your search did not return any results");     } } 

This just seems a little hacky.. would like to just have the grid not load any data initially.

Any ideas?

like image 320
Marcus Leon Avatar asked Oct 14 '10 15:10

Marcus Leon


People also ask

How do you hide jqGrid?

Just set opacity:0 for jqgrid element. it will work also.

What is rowNum in jqGrid?

jqGrid exposes a property rowNum where you can set the number of rows to display for each page.

What is Loadonce in jqGrid?

If you use loadonce:true jqGrid change the datatype parameters to 'local' after the first load of data from the grid. All next grid reloading (sorting, paging, filtering) works local. If you want refresh the grid data from the server one more time you should set datatype to its original value ('json' or 'xml').

How do I reset jqGrid?

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


2 Answers

You should just use datatype: 'local' initially. At the moment when you need to load the data you should change the datatype to json or xml:

$("#list").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid'); 
like image 99
Oleg Avatar answered Oct 06 '22 14:10

Oleg


I wanted to create a grid that loads no data when the page is loaded but loads data, when the user clicks refresh or uses the search. My solution is a little bit hacky to but is very easy and works nicely.

I am using the callback event loadBeforeSend to stop the ajax request for data when the page is loaded. My callback function removes itself so it will be executed only once.

loadBeforeSend: function (xhr, settings) {   this.p.loadBeforeSend = null; //remove event handler   return false; // dont send load data request } 
like image 37
TomWolk Avatar answered Oct 06 '22 15:10

TomWolk