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
close icon

Summing by unique categories

Hi ,

I need to be able to show a financial sum for unique values in a category in a regular gridcontrol next to the ggc with the source data (populated by a datatable).

For example, if I had a table like this:

Red    100
Red    500
Blue   200
Blue   120

I would need to display this in the gridcontrol:

Red  600
Blue  320

I would also need the grid control to automatically update the gridcontrol data to reflect any filters applied to the ggc.

Is there a built in method, or otherwise easy way to get this data from the ggc to the gridcontrol? If not, can I export only the filtered data from the ggc to a DataTable? If push comes to shove I could do a linq query on the exported tables, but that's probably less than ideal.

Thanks!


1 Reply

AR Arulpriya Ramalingam Syncfusion Team August 5, 2019 02:03 PM UTC

Hi Travis, 
 
Thanks for using Syncfusion support. 
 
The GridGroupingControl does not has the built-in methods to populate the group summaries to a external grid or datatable. However, this can be achieved by adding a SummaryRow for the specified column and in the below provided sample, we have achieved your requirement with “sport” and “wins” column. In order to, get the sum value of the group, the GetSummary() method can be used and to get the grouped item, the Category property of the GridGroup can be used. Moreover, the grid does not update the values on demand when the record values are changed. In order to overcome this use case, the SourceListRecordChanged, RecordFilters.Changed (Dynamic/Normal filter) and CategorizedRecords (Excel Filter) events can be used to update the grid data. Please make use of the below code and sample, 
 
Code example 
 
internal void LoadGridData() 
{ 
    gridcontrol1.RowCount = gridGroupingControl1.Table.TopLevelGroup.Groups.Count; 
    int i = 1; 
    foreach (GridGroup gridGroup in gridGroupingControl1.Table.TopLevelGroup.Groups) 
    { 
        double sum = (gridGroup.GetSummary(0) as DoubleAggregateSummary).Sum; 
        string category = gridGroup.Category.ToString(); 
        gridcontrol1[i, 1].CellValue = category; 
        gridcontrol1[i, 2].CellValue = sum; 
        i++; 
    } 
} 
 
 
Regards, 
Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon