<ej:Grid ID="OrdersGrid" runat="server" AllowGrouping="True" AllowPaging="True">
<ClientSideEvents ActionComplete="onActionComplete"/>
. . .
</ej:Grid>
function onActionComplete(args){
if(args.requestType == "grouping" || args.requestType == "paging"){
var grpCol = this.model.groupSettings.groupedColumns,len = grpCol.length,prevCaption,val=0;
if(len > 1){
for(var i=len-2;i>=0;i--){
prevCaptions = $("td[ej-mappingname="+grpCol[i]+"]").next();
for(var j=0;j<prevCaptions.length;j++){
curCaptions = $(prevCaptions[j]).closest("tr").next().find("td[ej-mappingname="+grpCol[i+1]+"]").next();
for(var k=0;k<curCaptions.length;k++)
val += parseInt($(curCaptions[k]).text().match(/\d+/)[0]);
$(prevCaptions[j]).text(function(i,txt) {return txt.replace(/\d+/,val); });
val = 0;
}
}
}
}
} |
$('#Grid').ejGrid({ . . . actionComplete: "onActionComplete", }); function onActionComplete(args) { //Check the required grid action if (args.requestType == "grouping" || args.requestType == "ungrouping" || args.requestType == "paging") { var grpCol = this.model.groupSettings.groupedColumns,len = grpCol.length,prevCaption,val=0; if(len > 1){ for(var i=len-2;i>=0;i--){ prevCaptions = $("td[ej-mappingname="+grpCol[i]+"]").next(); for (var j = 0; j < prevCaptions.length; j++) { curCaptions = $(prevCaptions[j]).closest("tr").next().find("td[ej-mappingname=" + grpCol[i + 1] + "]").next(); //Get the least sublevel captions element for(var k=0;k<curCaptions.length;k++) val += parseInt($(curCaptions[k]).text().match(/\d+/)[0]); //Get the number(count) from the string and add which is get from that sublevel captions $(prevCaptions[j]).text(function(i,txt) {return txt.replace(/\d+/,val); }); //That the added value is set to the immediate previous caption of sublevel val = 0; } } } } } |
<script id="template" type="text/x-jsrender"> {{:~func()}} </script> <script type="text/javascript"> var func = function () { var f = this.data.field, k = this.data.key, c = this.data.count, str = f + ":" + k; //Set the count for the least group caption format if(ej.isNullOrUndefined(this.data.items.GROUPGUID)){ str = c>1 ? str+" - "+c+" items" :str+" - "+c+" item"; } return str; } $.views.helpers({ func: func }); $(function () { $("#Grid").ejGrid({ . . . groupSettings: { captionFormat: "#template"}, }); }); </script> |