Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
template.js.plugins.grid.grouping.js Maven / Gradle / Ivy
/*jshint eqeqeq:false, eqnull:true */
/*global jQuery */
// Grouping module
(function($){
"use strict";
$.extend($.jgrid,{
template : function(format){ //jqgformat
var args = $.makeArray(arguments).slice(1), j, al = args.length;
if(format==null) { format = ""; }
return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){
if(!isNaN(parseInt(i,10))) {
return args[parseInt(i,10)];
}
for(j=0; j < al;j++) {
if($.isArray(args[j])) {
var nmarr = args[ j ],
k = nmarr.length;
while(k--) {
if(i===nmarr[k].nm) {
return nmarr[k].v;
}
}
}
}
});
}
});
$.jgrid.extend({
groupingSetup : function () {
return this.each(function (){
var $t = this, i, j, cml, cm = $t.p.colModel, grp = $t.p.groupingView;
if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) {
if(!grp.groupField.length) {
$t.p.grouping = false;
} else {
if (grp.visibiltyOnNextGrouping === undefined) {
grp.visibiltyOnNextGrouping = [];
}
grp.lastvalues=[];
if(!grp._locgr) {
grp.groups =[];
}
grp.counters =[];
for(i=0;i 0 ? nums[0] : undefined;
},
itemGroupingLevel,
showData,
collapsed = false,
frz = $t.p.frozenColumns ? $t.p.id+"_frozen" : false,
tar2 = frz ? $("#"+$.jgrid.jqID(hid), "#"+$.jgrid.jqID(frz) ) : false,
r2 = (tar2 && tar2.length) ? tar2[0].nextSibling : null;
if( tarspan.hasClass(minus) ) {
if(grp.showSummaryOnHide) {
if(r){
while(r) {
itemGroupingLevel = getGroupingLevelFromClass(r.className);
if (itemGroupingLevel !== undefined && itemGroupingLevel <= num) {
break;
}
$(r).hide();
r = r.nextSibling;
if(frz) {
$(r2).hide();
r2 = r2.nextSibling;
}
}
}
} else {
if(r){
while(r) {
itemGroupingLevel = getGroupingLevelFromClass(r.className);
if (itemGroupingLevel !== undefined && itemGroupingLevel <= num) {
break;
}
$(r).hide();
r = r.nextSibling;
if(frz) {
$(r2).hide();
r2 = r2.nextSibling;
}
}
}
}
tarspan.removeClass(minus).addClass(plus);
collapsed = true;
} else {
if(r){
showData = undefined;
while(r) {
itemGroupingLevel = getGroupingLevelFromClass(r.className);
if (showData === undefined) {
showData = itemGroupingLevel === undefined; // if the first row after the opening group is data row then show the data rows
}
if (itemGroupingLevel !== undefined) {
if (itemGroupingLevel <= num) {
break;// next item of the same lever are found
}
if (itemGroupingLevel === num + 1) {
$(r).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus);
if(frz) {
$(r2).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus);
}
}
} else if (showData) {
$(r).show();
if(frz) {
$(r2).show();
}
}
r = r.nextSibling;
if(frz) {
r2 = r2.nextSibling;
}
}
}
tarspan.removeClass(plus).addClass(minus);
}
$($t).triggerHandler("jqGridGroupingClickGroup", [hid , collapsed]);
if( $.isFunction($t.p.onClickGroup)) { $t.p.onClickGroup.call($t, hid , collapsed); }
});
return false;
},
groupingRender : function (grdata, colspans, page, rn ) {
return this.each(function(){
var $t = this,
grp = $t.p.groupingView,
str = "", icon = "", hid, clid, pmrtl = grp.groupCollapse ? grp.plusicon : grp.minusicon, gv, cp=[], len =grp.groupField.length;
pmrtl += " tree-wrap-"+$t.p.direction;
$.each($t.p.colModel, function (i,n){
var ii;
for(ii=0;ii= 0; i--) {
if(grp[i].idx === id-offset) {
ret = grp[i];
break;
}
}
}
}
return ret;
}
function buildSummaryTd(i, ik, grp, foffset) {
var fdata = findGroupIdx(i, ik, grp),
cm = $t.p.colModel,
vv, grlen = fdata.cnt, str="", k;
for(k=foffset; k ",
tplfld = "{0}";
$.each(fdata.summary,function(){
if(this.nm === cm[k].name) {
if(cm[k].summaryTpl) {
tplfld = cm[k].summaryTpl;
}
if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
if(this.sd && this.vd) {
this.v = (this.v/this.vd);
} else if(this.v && grlen > 0) {
this.v = (this.v/grlen);
}
}
try {
this.groupCount = fdata.cnt;
this.groupIndex = fdata.dataIndex;
this.groupValue = fdata.value;
vv = $t.formatter('', this.v, k, this);
} catch (ef) {
vv = this.v;
}
tmpdata= ""+$.jgrid.format(tplfld,vv)+ " ";
return false;
}
});
str += tmpdata;
}
return str;
}
var sumreverse = $.makeArray(grp.groupSummary), mul;
sumreverse.reverse();
mul = $t.p.multiselect ? " colspan=\"2\"" : "";
$.each(grp.groups,function(i,n){
if(grp._locgr) {
if( !(n.startRow +n.cnt > (page-1)*rn && n.startRow < page*rn)) {
return true;
}
}
toEnd++;
clid = $t.p.id+"ghead_"+n.idx;
hid = clid+"_"+i;
icon = " ";
try {
if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) {
n.displayValue = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp);
gv = n.displayValue;
} else {
gv = $t.formatter(hid, n.displayValue, cp[n.idx], n.value );
}
} catch (egv) {
gv = n.displayValue;
}
if(grp.groupSummaryPos[n.idx] === 'header') {
str += "0 ? " style=\"display:none;\" " : " ") + "role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+" "+clid+"\">"+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+" ";
str += buildSummaryTd(i, 0, grp.groups, grp.groupColumnShow[n.idx] === false ? (mul ==="" ? 2 : 3) : ((mul ==="") ? 1 : 2) );
str += " ";
} else {
str += "0 ? " style=\"display:none;\" " : " ") + "role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+" "+clid+"\">"+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+" ";
}
var leaf = len-1 === n.idx;
if( leaf ) {
var gg = grp.groups[i+1], kk, ik, offset = 0, sgr = n.startRow,
end = gg !== undefined ? gg.startRow : grp.groups[i].startRow + grp.groups[i].cnt;
if(grp._locgr) {
offset = (page-1)*rn;
if(offset > n.startRow) {
sgr = offset;
}
}
for(kk=sgr;kk";
str += buildSummaryTd(i, ik, grp.groups, 0);
str += "";
}
toEnd = jj;
}
}
});
$("#"+$.jgrid.jqID($t.p.id)+" tbody:first").append(str);
// free up memory
str = null;
});
},
groupingGroupBy : function (name, options ) {
return this.each(function(){
var $t = this;
if(typeof name === "string") {
name = [name];
}
var grp = $t.p.groupingView;
$t.p.grouping = true;
grp._locgr = false;
//Set default, in case visibilityOnNextGrouping is undefined
if (grp.visibiltyOnNextGrouping === undefined) {
grp.visibiltyOnNextGrouping = [];
}
var i;
// show previous hidden groups if they are hidden and weren't removed yet
for(i=0;i