Permalink
Browse files

Adding a displayField property in grouping in order to display it ins…

…tead of default group Value. Thanks to Matthew Hutton
  • Loading branch information...
1 parent ddeadc4 commit 4014e28295e16832e9f8ca7c4b472da5c690e5ae @tonytomov committed Jan 12, 2013
Showing with 13 additions and 5 deletions.
  1. +13 −5 js/grid.grouping.js
View
@@ -79,14 +79,22 @@ $.jgrid.extend({
grlen = grp.groupField.length,
fieldName,
v,
+ displayName,
+ displayValue,
changed = 0;
for(i=0;i<grlen;i++) {
fieldName = grp.groupField[i];
+ displayName = grp.displayField[i];
v = record[fieldName];
+ displayValue = displayName == null ? null : record[displayName];
+
+ if( displayValue == null ) {
+ displayValue = v;
+ }
if( v !== undefined ) {
if(irow === 0 ) {
// First record always starts a new group
- grp.groups.push({idx:i,dataIndex:fieldName,value:v, startRow: irow, cnt:1, summary : [] } );
+ grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
grp.lastvalues[i] = v;
grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
$.each(grp.counters[i].summary,function() {
@@ -100,7 +108,7 @@ $.jgrid.extend({
} else {
if( typeof v !== "object" && grp.lastvalues[i] !== v ) {
// This record is not in same group as previous one
- grp.groups.push({idx:i,dataIndex:fieldName,value:v, startRow: irow, cnt:1, summary : [] } );
+ grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
grp.lastvalues[i] = v;
changed = 1;
grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
@@ -115,7 +123,7 @@ $.jgrid.extend({
} else {
if (changed === 1) {
// This group has changed because an earlier group changed.
- grp.groups.push({idx:i,dataIndex:fieldName,value:v, startRow: irow, cnt:1, summary : [] } );
+ grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
grp.lastvalues[i] = v;
grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
$.each(grp.counters[i].summary,function() {
@@ -249,9 +257,9 @@ $.jgrid.extend({
hid = clid+"_"+i;
icon = "<span style='cursor:pointer;' class='ui-icon "+pmrtl+"' onclick=\"jQuery('#"+$.jgrid.jqID($t.p.id)+"').jqGrid('groupingToggle','"+hid+"');return false;\"></span>";
try {
- gv = $t.formatter(hid, n.value, cp[n.idx], n.value );
+ gv = $t.formatter(hid, n.displayValue, cp[n.idx], n.value );
} catch (egv) {
- gv = n.value;
+ gv = n.displayValue;
}
str += "<tr id=\""+hid+"\" role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+" "+clid+"\"><td style=\"padding-left:"+(n.idx * 12) + "px;"+"\" colspan=\""+colspans+"\">"+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+"</td></tr>";
var leaf = len-1 === n.idx;

0 comments on commit 4014e28

Please sign in to comment.