This article is about sorting and mostly similar to the jqGrid Paging article explained earlier.
The sorting from the client side need not be explained as it is quite easier to find and it works automatically with tableToGrid if a value for sortname is specified. Let us check how we can sort from server side which helps in reducing the amount of data transmitted.
Setup jqGrid in Project:
We will reuse the same project which we have done in the jqGrid Paging article. Also for setting up the basic jqGrid project, please refer to the jqGrid Display article. Visit the current jqgrid download page to download the jqgrid code. You can download everything or atleast Make sure you download the following.
- Table to Grid
The rest of the modules may be useful in later articles.
Server Side Sorting with Paging on Ajax Loaded data
This method avoids the loading of the entire data at once thus removing the bottleneck on load time. This is suitable for loading large number of rows and the pages will load the sorted data faster.
The code snippet at the html side remains the same except that the loadonce attribute will be made false.
The server side code will be supplied with the current sorting field and sorting order using the options of jqGrid and the Controller/action should return the correct data.
Click the sample project for jqGrid sorting for downloading the sample project for Visual Studio 2010.