Using Custom Sort Type with Grouping

Am generating Jqgrid Dynamic Columns where initially in AJAX calls i will get the ColNames ,ColModel with intial sortname on which the Grid should be sorted and the other settings before firing the Grid.

In the Grid i have configured server side pagination where i will get Sorted records to the Grid and display it.

If user clicks on any of the columns the Data is sorted as per the Click event(Column asc ,desc) and returning the required data.

So far so Good. Now am trying to bring Grouping concept to the Existing code and am not sure on how to solve my sorting behaviour ?

First time am sending the data sorted by the Grouping field and looks fine and is folllowing the Grouping Wiki Rule

It is important to note that if you want the grouping to be correct, then the data should come from server to the grid sorted by that field

How can i acheieve this ? i saw couple of posts in SO jqGrid sorting a column while grouping consider grouping header

JQGrid Custom Sorting

Which all talks about adding Custom Sorttype to the ColModel. But my Colmodel is dynamic from MVC controller as stated eallier.

Is there any event at gridlevel like gridComplete i can override the sorting apart from Colmodel sorttype ?

Or is there a better appraoch you can suggest on ?

Thanks

=================== Update

For Example My grouping is based on Country(which is static and configured)

Suppose if user is sorting by Another Column Latitude my server side returning the Data sorted by Latitude and in Jqgrid it is Grouped by Country. So far Good.

But the Data is grouped in the way like the it is Grouped by Latitude and then by Country. Whereas i want the sorting to be only by Country

Example:

Country     City      Latitude

USA          MP        1.11
         WS        1.11

USA          SE        1.09
         WS        1.09

But as i am grouping by country am expecting like below 

USA          MP        1.11
         WS        1.11
         SE        1.09
         WS        1.09

So before sorting i should be doing something to get this o/p right ?

PS: Data is dummy to explain my issue. but hope you got my problem


If I understand correctly the problem you need just sort the data on the server first by Country (the grouping column) and then sort by Latitude as the second. You need just use something like ORDER BY Country, Latitude on the server side (or ORDER BY Country ASC, Latitude DESC depend on the sorting order).

链接地址: http://www.djcxy.com/p/25958.html

上一篇: jqGrid根据用户区域设置使用动态日期格式进行搜索

下一篇: 使用自定义排序类型进行分组