Skip to content

Commit

Permalink
Adding a displayField property in grouping in order to display it ins…
Browse files Browse the repository at this point in the history
…tead of default group Value. Thanks to Matthew Hutton
  • Loading branch information
tonytomov committed Jan 12, 2013
1 parent ddeadc4 commit 4014e28
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions js/grid.grouping.js
Expand Up @@ -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() {
Expand All @@ -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)};
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4014e28

Please sign in to comment.