Skip to content

Commit

Permalink
Fix formatting summry values to be availble everywhere See #1034
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytomov committed Jun 12, 2023
1 parent 9e40f19 commit d8be545
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
31 changes: 21 additions & 10 deletions js/grid.grouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,13 @@ $.jgrid.extend({
tplfld = (cm[k].summaryTpl) ? cm[k].summaryTpl : "{0}";

vv = this.v;
if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
if(this.sd && this.vd) {
vv = (this.v/this.vd);
} else if(this.v && grlen > 0) {
vv = (this.v/grlen);
}
}
try {
this.groupCount = fdata.cnt;
this.groupIndex = fdata.dataIndex;
this.groupValue = fdata.value;
vv = $t.formatter('', vv, k, this);
//vv = $t.formatter('', vv, k, this);
} catch (ef) {
vv = this.v;
//vv = this.v;
}
tmpdata= "<td role=\"gridcell\" "+$t.formatCol(k,1,'')+">"+$.jgrid.template(tplfld, vv, fdata.cnt, fdata.dataIndex, fdata.displayValue, fdata.summary)+ "</td>";
return false;
Expand Down Expand Up @@ -381,10 +374,28 @@ $.jgrid.extend({
gv = n.displayValue;
}
var grpTextStr = '';
// format summary values if formatter
for( var kk =0;kk< n.summary.length; kk++) {
var nv = n.summary[kk];
var ci = $.jgrid.getElemByAttrVal($t.p.colModel, 'name', nv.nm, true);
if(ci>=0) {
if(typeof nv.st === 'string' && nv.st.toLowerCase() === 'avg') {
if(nv.sd && nv.vd) {
nv.v = (nv.v/nv.vd);
} else if(nv.v && n.cnt > 0) {
nv.v = (nv.v/n.cnt);
}
}
try {
nv.v = $t.formatter('',nv.v, ci, this);
} catch (e) {}
}
}

if($.jgrid.isFunction(grp.groupText[n.idx])) {
grpTextStr = grp.groupText[n.idx].call($t, gv, n.cnt, n.summary);
} else {
grpTextStr = $.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary);
grpTextStr = $.jgrid.template.call($t, grp.groupText[n.idx], gv, n.cnt, n.summary);
}
if( !(typeof grpTextStr ==='string' || typeof grpTextStr ==='number' ) ) {
grpTextStr = gv;
Expand Down
31 changes: 21 additions & 10 deletions js/jquery.jqGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -14673,20 +14673,13 @@ $.jgrid.extend({
tplfld = (cm[k].summaryTpl) ? cm[k].summaryTpl : "{0}";

vv = this.v;
if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
if(this.sd && this.vd) {
vv = (this.v/this.vd);
} else if(this.v && grlen > 0) {
vv = (this.v/grlen);
}
}
try {
this.groupCount = fdata.cnt;
this.groupIndex = fdata.dataIndex;
this.groupValue = fdata.value;
vv = $t.formatter('', vv, k, this);
//vv = $t.formatter('', vv, k, this);
} catch (ef) {
vv = this.v;
//vv = this.v;
}
tmpdata= "<td role=\"gridcell\" "+$t.formatCol(k,1,'')+">"+$.jgrid.template(tplfld, vv, fdata.cnt, fdata.dataIndex, fdata.displayValue, fdata.summary)+ "</td>";
return false;
Expand Down Expand Up @@ -14719,10 +14712,28 @@ $.jgrid.extend({
gv = n.displayValue;
}
var grpTextStr = '';
// format summary values if formatter
for( var kk =0;kk< n.summary.length; kk++) {
var nv = n.summary[kk];
var ci = $.jgrid.getElemByAttrVal($t.p.colModel, 'name', nv.nm, true);
if(ci>=0) {
if(typeof nv.st === 'string' && nv.st.toLowerCase() === 'avg') {
if(nv.sd && nv.vd) {
nv.v = (nv.v/nv.vd);
} else if(nv.v && n.cnt > 0) {
nv.v = (nv.v/n.cnt);
}
}
try {
nv.v = $t.formatter('',nv.v, ci, this);
} catch (e) {}
}
}

if($.jgrid.isFunction(grp.groupText[n.idx])) {
grpTextStr = grp.groupText[n.idx].call($t, gv, n.cnt, n.summary);
} else {
grpTextStr = $.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary);
grpTextStr = $.jgrid.template.call($t, grp.groupText[n.idx], gv, n.cnt, n.summary);
}
if( !(typeof grpTextStr ==='string' || typeof grpTextStr ==='number' ) ) {
grpTextStr = gv;
Expand Down
2 changes: 1 addition & 1 deletion js/jquery.jqGrid.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/jquery.jqGrid.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/minified/grid.grouping.js

Large diffs are not rendered by default.

0 comments on commit d8be545

Please sign in to comment.