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.
Unfortunately, activation email could not send to your email. Please try again.

Custom Summary Calc using other Summary Values

Thread ID:

Created:

Updated:

Platform:

Replies:

130441 May 12,2017 03:15 PM May 24,2017 01:28 AM JavaScript 3
loading
Tags: ejGrid
Bruce Van Horn
Asked On May 12, 2017 03:15 PM

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

Venkatesh Ayothi Raman [Syncfusion]
Replied On May 15, 2017 08:32 PM

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. 


Bruce Van Horn
Replied On May 23, 2017 01:36 PM

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).

Venkatesh Ayothi Raman [Syncfusion]
Replied On May 24, 2017 01:28 AM

Hi Bruce, 

Thanks for the feedback. 

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

Thanks, 
Venkatesh Ayothiraman. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;