Andrus
Andrus

Reputation: 27945

how to retrieve colmodel and data on single request and speed up jqgrid load

jqGrid is powered by remote json data in ASP .NET MVC2 application. On page load two requests are sent to server: one to retrieve whole html page with colmodel and second invoked by jqgrid to retrieve data.

colmodel is stored in database and depends on user rights and user configuration. Creating colmodel requires number of sql server calls which take a while.

Both request require building colmodel in server. For data retrieval colmodel is required to get correct number of columns to build select statement.

Currently this colmodel is built two times for every request. Also total number of recods is required to be returned which is slow on large data (causes whole result scan in PostgreSql server).

How to speed the things up ? How to build colmodel only once and send it and data in same request?

Upvotes: 0

Views: 556

Answers (1)

Oleg
Oleg

Reputation: 221997

I agree that extension of jqGrid to support the loading of some parts of colModel per one Ajax will be very helpful. For about a year I posted the feature request for example.

What you can do now:

  1. If I correct understand your requirements you need to show the user the subset of the columns depend on the user's permissions. One can implement the requirement in one Ajax request. What you can do is: first don't send the "hidden" data or send there as empty string. Seconds you can send the list of columns, which should be hidden, to the client. In the case you can implement the variable number of columns in jqGrid. You can send the information inside of userData part of JSON response for example. To have better performance with many hidden columns I would recommend you to call showCol or hideCol inside of beforeProcessing and hide/show the columns on the empty grid. It will speed up the performance of showCol or hideCol dramatically. If it's needed you can include additional call of clearGridData.
  2. You have to optimize the retrieval colModel. I don't understand why it should be slow. All depends from your implementation. In any way I am sure that one can make the retrieval really quickly.
  3. To improve the performance of request of data from the database you can consider don't fill records field of the JSON response and set total to page + 1. It enebles the "Next" button of the pager. You should set total equal to page only if you returns less rows as the rows (number of rows per page). In the most cases it will be good criteria to detect the last page. You can additionally hide some field on the pager lake the "Last" button and the sp_1_... span which shows the total number of pages. You can do this by the usage of pgtext : "Page {0}" option or the usage of pginput: false to have no pager input at all. The viewrecords should be false (its default value). After all the customization you will don't need to calculate the total number of records and in the way improve performance of the database request in case of large data.

Upvotes: 1

Related Questions