jqGrid
jqGrid copied to clipboard
Feature suggestion: support functions in groupingView.groupOrder
Hi Tony,
I'd like to suggest an enhanced feature for the groupingView.groupOrder property. Right now groupOrder is an array that only accepts the strings "asc" and "desc". This makes it difficult to provide custom sorting logic for groups. It would be great if groupOrder could also accept functions.
An example use might look like this:
groupingView: {
groupField: ["field1", "field2"],
groupOrder: ["asc", function(a, b){...}]
...
}
I've had a go at implementing this myself, the proposed changes are below:
grid.base.js:
-
The call to query.orderBy (line 2356) needs to pass the 5th parameter, which is the sort function. Change
query.orderBy(grindexes[gin],grpview.groupOrder[gin],grtypes[gin].stype, grtypes[gin].srcfmt);
toquery.orderBy(grindexes[gin],grpview.groupOrder[gin],grtypes[gin].stype, grtypes[gin].srcfmt, $.isFunction(grpview.groupOrder[gin]) ? grpview.groupOrder[gin] : null);
-
The assignment to dir in function orderBy (line 806) needs to set dir to null if sfunc exists. Change
dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase());
todir = dir == null ? "a" : ($.isFunction(dir) ? null : $.trim(dir.toString().toLowerCase()));
-
Function _getGroup needs to take a new parameter sfunc. It then just needs to pass this parameter on to the call to _getOrder (line 595). Change
this._getGroup=function(data,by,dir,type, dfmt){
tothis._getGroup=function(data,by,dir,type, dfmt, sfunc){
and$.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
to$.each(self._getOrder(data,by,dir,type, dfmt, sfunc),function(i,v){
-
All existing calls to _getGroup now need to pass the extra parameter. The call in _doSort (line 531) should pass sfunc. Change
var values=self._getGroup(d,by,dir,type,dfmt), results=[], i, j, sorted;
tovar values=self._getGroup(d,by,dir,type,dfmt, sfunc), results=[], i, j, sorted;
The only thing I'm usure about is the call to _getGroup in function groupBy (line 799).
I'm looking forward to hearing your thoughts.
Kind Regards, MLC
Hello,
Thanks for the suggestion. Will investigate this in the next days.
Regards, Tony