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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add summary row for child grid

Thread ID:

Created:

Updated:

Platform:

Replies:

147726 Sep 21,2019 10:40 PM UTC Sep 24,2019 07:09 AM UTC WinForms 3
loading
Tags: SfDataGrid
Josip
Asked On September 21, 2019 10:40 PM UTC

Hello!

I have a master-detail view in SfDataGrid. I want to add summary for detail grid rows.

Here is how i'm doing it:


private void InitGrid()
        {              

            GridViewDefinition orderDetailsView = new GridViewDefinition();
            orderDetailsView.RelationalColumn = "RadionaStavke";          

            SfDataGrid childGrid = new SfDataGrid();
            childGrid.QueryRowStyle += ChildGrid_QueryRowStyle;
            childGrid.ForeColor = Color.Blue;
            childGrid.AutoGenerateColumns = false;
            childGrid.RowHeight = 21;
            NumberFormatInfo nfi = new NumberFormatInfo();
            nfi.NumberDecimalDigits = 2;
            nfi.NumberGroupSizes = new int[] { };
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "ID", HeaderText = "ID" });
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "SifraRD", HeaderText = "Šifra rd." });
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "OpisArtikla", HeaderText = "Opis/naziv" });
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "NazivGrupe", HeaderText = "Grupa" });
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "JedMjera", HeaderText = "Jed. mj." });                     
            childGrid.Columns.Add(new GridNumericColumn() { MappingName = "Kolicina", HeaderText = "Količina", NumberFormatInfo = nfi });
            childGrid.Columns.Add(new GridNumericColumn() { MappingName = "MPC", NumberFormatInfo = nfi });
            childGrid.Columns.Add(new GridNumericColumn() { MappingName = "VPC", NumberFormatInfo = nfi });
            childGrid.Columns.Add(new GridNumericColumn() { MappingName = "UkMPC", HeaderText = "Uk. MPC", NumberFormatInfo = nfi });
            childGrid.Columns.Add(new GridNumericColumn() { MappingName = "UkVPC", HeaderText = "Uk. VPC", NumberFormatInfo = nfi });
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "Napomena", HeaderText = "Napomena" });

            childGrid.GroupSummaryRows.Add(new GridSummaryRow()
            {
                ShowSummaryInRow = false,
                Name = "summary",               
                SummaryColumns = new System.Collections.ObjectModel.ObservableCollection<Syncfusion.Data.ISummaryColumn>()
                {
                    new GridSummaryColumn()
                    {                        
                        Name = "UkVPC",
                        SummaryType = Syncfusion.Data.SummaryType.DoubleAggregate,
                        Format="{Sum:c}",
                        MappingName="UkVPC"
                    },
                }
            });

            orderDetailsView.DataGrid = childGrid;
            this.gridRadiona.DetailsViewDefinitions.Add(orderDetailsView);

          
        }


Data are loaded, i can see everything in grid except this group summary row. What I'm doing wrong?

Susmitha Sundar [Syncfusion]
Replied On September 23, 2019 01:04 PM UTC

Hi Josip, 
 
Thank you for using Syncfusion controls. 
 
Based on the provided information, we suspect that you did not add the GroupColumnDescription for ChildGrid column. If you want to add the summary for DataGrid, you should add the GroupColumnDescription for any column in that DataGrid.  
 
Please refer the below code snippet, 
C#: 
firstLevelSourceDataGrid.GroupSummaryRows.Add(new GridSummaryRow() 
            { 
                ShowSummaryInRow = false, 
                Name = "summary", 
                SummaryColumns = new System.Collections.ObjectModel.ObservableCollection<Syncfusion.Data.ISummaryColumn>() 
                { 
                    new GridSummaryColumn() 
                    { 
                        Name = "UnitPrice", 
                        SummaryType = Syncfusion.Data.SummaryType.DoubleAggregate, 
                        Format="{Sum:c}", 
                        MappingName="UnitPrice" 
                    }, 
                } 
            }); 
 
            firstLevelSourceDataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = "UnitPrice" }); 
            viewDefinition.DataGrid = firstLevelSourceDataGrid; 
            this.sfDataGrid1.DetailsViewDefinitions.Add(viewDefinition); 
 
 
We hope it helps, please revert us back, if you need further assistance. 
 
Regards, 
Susmitha S 


Josip
Replied On September 23, 2019 08:16 PM UTC

Hi Josip, 
 
Thank you for using Syncfusion controls. 
 
Based on the provided information, we suspect that you did not add the GroupColumnDescription for ChildGrid column. If you want to add the summary for DataGrid, you should add the GroupColumnDescription for any column in that DataGrid.  
 
Please refer the below code snippet, 
C#: 
firstLevelSourceDataGrid.GroupSummaryRows.Add(new GridSummaryRow() 
            { 
                ShowSummaryInRow = false, 
                Name = "summary", 
                SummaryColumns = new System.Collections.ObjectModel.ObservableCollection<Syncfusion.Data.ISummaryColumn>() 
                { 
                    new GridSummaryColumn() 
                    { 
                        Name = "UnitPrice", 
                        SummaryType = Syncfusion.Data.SummaryType.DoubleAggregate, 
                        Format="{Sum:c}", 
                        MappingName="UnitPrice" 
                    }, 
                } 
            }); 
 
            firstLevelSourceDataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = "UnitPrice" }); 
            viewDefinition.DataGrid = firstLevelSourceDataGrid; 
            this.sfDataGrid1.DetailsViewDefinitions.Add(viewDefinition); 
 
 
We hope it helps, please revert us back, if you need further assistance. 
 
Regards, 
Susmitha S 


Thank you for the answer.

Actually it is not exactly that I wanted but I figured out how to add summary rows

            GridTableSummaryRow tableSummaryRow1 = new GridTableSummaryRow();
            tableSummaryRow1.Name = "TableSummary";
            tableSummaryRow1.ShowSummaryInRow = false;
            tableSummaryRow1.Position = VerticalPosition.Bottom;

            GridSummaryColumn summaryColumn1 = new GridSummaryColumn();
            summaryColumn1.Name = "UkMPC";
            summaryColumn1.SummaryType = SummaryType.DoubleAggregate;
            summaryColumn1.Format = "{Sum:c}";
            summaryColumn1.MappingName = "UkMPC";

            GridSummaryColumn summaryColumn2 = new GridSummaryColumn();
            summaryColumn2.Name = "UkVPC";
            summaryColumn2.SummaryType = SummaryType.DoubleAggregate;
            summaryColumn2.Format = "{Sum:c}";
            summaryColumn2.MappingName = "UkVPC";

            tableSummaryRow1.SummaryColumns.Add(summaryColumn1);
            tableSummaryRow1.SummaryColumns.Add(summaryColumn2);
            childGrid.TableSummaryRows.Add(tableSummaryRow1);

            orderDetailsView.DataGrid = childGrid;
            this.gridRadiona.DetailsViewDefinitions.Add(orderDetailsView);

Farjana Parveen Ayubb [Syncfusion]
Replied On September 24, 2019 07:09 AM UTC

Hi Josip, 
 
Thank you for your update. 
 
Please get back to us if you require further other assistance from us 
 
 
Regards, 
Farjana Parveen A 


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

Live Chat Icon For mobile
Live Chat Icon