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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Summary by group

Thread ID:

Created:

Updated:

Platform:

Replies:

141731 Dec 31,2018 01:34 PM UTC Jan 2,2019 04:17 PM UTC WPF 1
loading
Tags: SfDataGrid
ivo ver eecke
Asked On December 31, 2018 01:34 PM UTC

Hi,

I'm having trouble with summaries on a Datagrid.
I have a datagrid with 2 levels of grouping and would like to have totals on each level.
looking something like:

Country     Category   Shop         Amount
Belgium                                       100
Belgium     Pets                           75
Belgium     Pets          Petstore    50
Belgium     Pets          Petland     25
Belgium     Toys                          25
Belgium     Toys        Toysrus     25

I've tried this using a CaptionSummaryRow, but this always seems to delete the grouping column value.

Any help would be welcome
Thanks

Shobika Palani [Syncfusion]
Replied On January 2, 2019 04:17 PM UTC

Hi Ivo, 

Thank you for contacting Syncfusion Support. 

We have analyzed your query to show summary on each level of groups. You can achieve this by customizing the GridCaptionSummaryCellRenderer as like the following code snippet 

public class CustomCaptionSummaryCellRenderer : GridCaptionSummaryCellRenderer 
    { 
        public override void OnInitializeEditElement(DataColumnBase dataColumn, GridCaptionSummaryCell uiElement, object dataContext) 
        { 
            base.OnInitializeEditElement(dataColumn, uiElement, dataContext); 
            if (dataContext is Group) 
            { 
                var groupRecord = dataContext as Group; 
                if (this.DataGrid.CaptionSummaryRow.ShowSummaryInRow) 
                { 
                    uiElement.Content = SummaryCreator.GetSummaryDisplayTextForRow(groupRecord.SummaryDetails, 
                        this.DataGrid.View); 
                } 
                else 
                { 
                    uiElement.Content = SummaryCreator.GetSummaryDisplayText(groupRecord.SummaryDetails, 
                        dataColumn.GridColumn.MappingName, this.DataGrid.View); 
                    if (dataColumn.GridColumn == this.DataGrid.Columns.FirstOrDefault(col => !col.IsHidden)) 
                    { 
                        uiElement.Content = groupRecord.Key.ToString() +" - " + uiElement.Content.ToString(); 
                    } 
                } 
            } 
        } 
 
        public override void OnUpdateEditBinding(DataColumnBase dataColumn, GridCaptionSummaryCell element, object dataContext) 
        { 
            base.OnUpdateEditBinding(dataColumn, element, dataContext); 
            if (element.DataContext is Group && this.DataGrid.View.GroupDescriptions.Count > 0) 
            { 
                var groupRecord = element.DataContext as Group; 
                //get the column which is grouped. 
                var groupedColumn = this.GetGroupedColumn(groupRecord); 
                if (this.DataGrid.CaptionSummaryRow.ShowSummaryInRow) 
                { 
                    element.Content = SummaryCreator.GetSummaryDisplayTextForRow(groupRecord.SummaryDetails, 
                        this.DataGrid.View, groupedColumn.HeaderText); 
                } 
                else 
                { 
                    element.Content = SummaryCreator.GetSummaryDisplayText(groupRecord.SummaryDetails, 
                        dataColumn.GridColumn.MappingName, this.DataGrid.View); 
 
                    if (dataColumn.GridColumn == this.DataGrid.Columns.FirstOrDefault(col => !col.IsHidden)) 
                    { 
                        element.Content = groupRecord.Key.ToString() +" - "+ element.Content.ToString(); 
                    } 
                } 
            } 
        } 
         
        // Method to get the Grouped Column. 
        private GridColumn GetGroupedColumn(Group group) 
        { 
            var groupDesc = this.DataGrid.View.GroupDescriptions[group.Level - 1] as PropertyGroupDescription; 
            foreach (var column in this.DataGrid.Columns) 
            { 
                if (column.MappingName == groupDesc.PropertyName) 
                { 
                    return column; 
                } 
            } 
            return null; 
        } 
    } 

Please find sample for the same from the following link 
Sample Link: 

Please let us know your concern. 

Regards, 
Shobika. 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

;