Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress jqgrid from initially loading data?

Tags:

jquery

jqgrid

I have a page that has a couple of jqGrids on it, along with a few other fields. I want to make one AJAX call myself that pulls back a JSON object that has the data that should be used to fill the entire page.

So, I would like to make the call myself, populate the "other fields" and then pull a couple of collections off of the main JSON object that was returned and populate each of the jqGrids with those collections "manually".

I have this much working, but I can't get jqGrid to stop attempting to make an AJAX request itself. Shouldn't there be a way to tell jqGrid to NOT attempt an AJAX call when it is initialized?

I found a similar question asked here: How to suppress jqgrid from initially loading data?

But I don't have the option that solved it for the poster.

It seems pretty logical to me that some people may want to use this plugin without having the table attempt to get its own data upon initialization. Am I missing an option somewhere in the documentation (wiki - options)?

Thanks.

like image 371
Steve Avatar asked Feb 28 '23 02:02

Steve


1 Answers

There is an easy way to say jqGrid don't load the data itself. You should use using datatype: 'local' as a jqGrid option. This option say that you plan to fill the grid data yourself with a functions like addRowData or addJSONData (see an example on jqGrid tableToGrid "options" parameter). You can also fill the data in the grid inside of loadComplete callback, because jqGrid calls this function also in the case of datatype: 'local'.

Don't forget, that data which you give as parameter of addJSONData will be read (parsed) using jsonReader and jsonmap. It gives you a nice way don't much manipulate the data received from the server. Instead of that it's enough to give only correct data mapping in jsonmap for jqGrid. A relative complex example of data mapping you will find in Mapping JSON data in JQGrid.

If you think about optimization of data transfer, look at "Data Mapping" \ "Data optimization" part on the http://trirand.com/blog/jqgrid/jqgrid.html demo page. The idea is to replace data structure represented rows of table to array of strings. Then no column names (filed names of structure) will be send from server to client which compress data transfer. With this kind of optimization you can probably save much more time as with the other ways. Don't forget to switch on a data compression on the web server. This can also dramatically reduce the size of data transfer.

At the end I can recommend to look through my discussion question Should one replace the usage addJSONData of jqGrid to the usage of setGridParam(), and trigger('reloadGrid')? where I compare usage of addJSONData() function with the usage of trigger('reloadGrid'). Of cause if you want to update more as one table at once trigger('reloadGrid') will be a little slowly as if you makes only one ajax call, but the structure of your program will be much more easier with trigger('reloadGrid'). If you compare the total time in both cases it can be that the data transfer is not the bottleneck whic you have. So it could be, that the total time of page loading in both cases stay almost without changing. The best way would be to mess the time in both cases and decide how much you are ready to pay for a simple program design.

like image 157
Oleg Avatar answered Mar 16 '23 08:03

Oleg