We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Custom Summary Calc using other Summary Values

I have a grid with grouped columns, and I can summarize groups just fine, but I need to sum the numbers, then compute percentages from those numbers and display those in the same summary row.  Obviously, I can't sum the percentages.  In my case, I'm showing hard drive storage stats...  I'll pick the easiest example:  I need % used, so I need the group's total used and group's total usable, both of which are right there on the summary row.  I've attached a picture in the zip file.

I've tried using ej.sum just to see if it would give me the sum of the group, but it doesn't - it gives me the sum of the whole data set.  So I can compute the total percentage used, but not the total for the group, which of course can change as the user manipulates the grouping.

My code so far:

$("#businessunitcommitmentreportgrid").ejGrid({
dataSource: data.commitment_detail,
allowPaging: true,
allowSorting: true,
allowReordering: true,
allowResizing: true,
allowFiltering: true,
allowGrouping: true,
enableHeaderHover: true,
showSummary: true,
summaryRows: [{
title: "Totals",
summaryColumns: [{
summaryType: ej.Grid.SummaryType.Sum,
displayColumn: "usable",
format: "{0:n2}",
dataMember: "usable"
}, {
summaryType: ej.Grid.SummaryType.Sum,
displayColumn: "used",
format: "{0:n2}",
dataMember: "used"
}, {
summaryType: ej.Grid.SummaryType.Sum,
displayColumn: "provisioned_free",
format: "{0:n2}",
dataMember: "provisioned_free"
}, {
summaryType: ej.Grid.SummaryType.Sum,
format: "{0:n2}",
displayColumn: "unprovisioned",
dataMember: "unprovisioned"
}, {
summaryType: ej.Grid.SummaryType.Sum,
format: "{0:n2}",
displayColumn: "over_provisioned",
dataMember: "over_provisioned"
}, {
summaryType: ej.Grid.SummaryType.Sum,
format: "{0:n2}",
displayColumn: "allocated",
dataMember: "allocated"
}, {
summaryType: ej.Grid.SummaryType.Sum,
format: "{0:n2}",
displayColumn: "snap",
dataMember: "snap"
}, {
summaryType: ej.Grid.SummaryType.Custom,
format: "{0:n2}",
displayColumn: "pct_used",
dataMember: "pct_used",
customSummaryValue: function(){
var gridObj = $("#businessunitcommitmentreportgrid").ejGrid("instance");
return ej.sum(gridObj.model.dataSource, "usable"); //This just gives you the whole total, not the group total.
}
}
],showTotalSummary: false
}],
groupSettings: {groupedColumns: ["data_center"]},

filterSettings: {filterType: "Excel"},
columns: [
{field: "data_center", headerText: "Data Center", width: 200},
{field: "array_name", headerText: "Array Name", width: 130},
{field: "category", headerText: "Category", width: 100},
{field: "application", headerText: "Application"},
{field: "usable", headerText: "Usable", format: "{0:n2}", textAlign: ej.TextAlign.Right},
{field: "used", headerText: "Used", format: "{0:n2}", textAlign: ej.TextAlign.Right},
{
field: "provisioned_free",
headerText: "Prov Free",
format: "{0:n2}",
textAlign: ej.TextAlign.Right
},
{
field: "unprovisioned",
headerText: "UnProvisioned",
format: "{0:n2}",
textAlign: ej.TextAlign.Right
},
{
field: "over_provisioned",
headerText: "Over Prov (GB)",
format: "{0:n2}",
textAlign: ej.TextAlign.Right
},
{field: "allocated", headerText: "Allocated", format: "{0:n2}", textAlign: ej.TextAlign.Right},
{field: "snap", headerText: "Snap (GB)", format: "{0:n2}", textAlign: ej.TextAlign.Right},
{field: "pct_used", headerText: "% Used", format: "{0:n2}", textAlign: ej.TextAlign.Right},
{
field: "pct_provisioned_free",
headerText: "% Prov Free",
format: "{0:n2}",
textAlign: ej.TextAlign.Right
},
{
field: "pct_unprovisioned",
headerText: "% UnProv",
format: "{0:n2}",
textAlign: ej.TextAlign.Right
},
{
field: "pct_over_provisioned",
headerText: "% OverProv",
format: "{0:n2}",
textAlign: ej.TextAlign.Right
}

], recordDoubleClick: function (args) {
deviceDrillDown(args.data.upload_id);
}
});

Attachment: rowquestion_32a2f955.zip

3 Replies

VA Venkatesh Ayothi Raman Syncfusion Team May 16, 2017 12:32 AM UTC

Hi Bruce, 

Thanks for contacting Syncfusion support. 

We went through your code example and screenshot that you have shared for us and found that you are initially grouped the columns and you have calculated the summary value for whole datasource instead of grouped data source. This is the cause of the issue. 
The grouped datasource can be accessed by using the currentVIewData API. Please refer to the following code example and Help documentation for your convenience, 
Code example
function CustomSummary() { 
        var gridObj = $("#Grid").ejGrid("instance"), groupedDataSource = gridObj.model.currentViewData; 
 
        //Here we can get the grouped data source 
        return ej.sum(groupedDataSource[0].items, "usable"); //This just gives you the group total. 
    } 
 
Note: For demonstration purpose, we have calculated the summary value for first grouped datasource. Using the above code example, you can compute the percentage. 
 
Regards, 
Venkatesh Ayothiraman. 



BV Bruce Van Horn May 23, 2017 05:36 PM UTC

That's what I needed.  I didn't know how to get to the grouped data source!  Oooh, Exciting!  (wanders off into the dark muttering happily.  this customer is clearly crazy).


VA Venkatesh Ayothi Raman Syncfusion Team May 24, 2017 05:28 AM UTC

Hi Bruce, 

Thanks for the feedback. 

We are very happy to hear that your requirement is achieved. 

Thanks, 
Venkatesh Ayothiraman. 


Loader.
Live Chat Icon For mobile
Up arrow icon