<script type="text/javascript">
$(function () {
$("#Grid").ejGrid({
// the datasource "window.gridData" is referred from jsondata.min.js
dataSource: window.gridData,
allowPaging: true,
allowGrouping: true,
actionComplete: "onActionComplete",
groupSettings: { groupedColumns: ["ShipCountry"] },
columns: [
{ field: "OrderID", headerText: "Order ID", textAlign: ej.TextAlign.Right, width: 65 },
{ field: "CustomerID", headerText: "Customer ID", width: 90 },
{ field: "ShipCity", headerText: "Ship City", width: 90 },
{ field: "ShipCountry", headerText: "Ship Country", width: 90 },
{ field: "Verified", width: 70 }
]
});
});
function onActionComplete(args){
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[data-ej-mappingname="+grpCol[i]+"]").next();
for(var j=0;j<prevCaptions.length;j++){
curCaptions = $(prevCaptions[j]).closest("tr").next().find("td[data-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;
}
}
}
}
}
</script> |