This is a migrated thread and some comments may be shown as answers.

multiple grand total in grid

1 Answer 30 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mehdi
Top achievements
Rank 1
Mehdi asked on 12 Jul 2018, 08:29 AM

Hi,
I have a groupped gridview with summary row that calculate subtotal of each groups
and one grand Total at end of Grid (after set :  gridview1.MasterTemplate.ShowTotals = true)

But In my senario I need one summery row for each groups and three grand Total  at end.
Is it possible?

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Jul 2018, 12:54 PM
Hello, Mehdi,    

By design, you will have a summary row for each group in the grid. If you enable the ShowTotal property, a grand total outside all groups will be shown. However, this grand total will be only one because you have added only one summary item. if you need to have several grand total, it is necessary to add several GridViewSummaryRowItems and GridViewSummaryItems. However, it would be necessary to hide the summary items in the groups. Here is demonstrated a sample code snippet which result is illustrated in the below screenshot. Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which achieves your requirement best: 
public Form1()
{
    InitializeComponent();
    this.radGridView1.ViewRowFormatting += radGridView1_ViewRowFormatting;
}
 
private void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
{
    GridSummaryRowElement summaryRowElement = e.RowElement as GridSummaryRowElement;
    if (summaryRowElement != null && e.RowElement.RowInfo.HierarchyLevel > 0 && e.RowElement.Parent.Children.IndexOf(e.RowElement) % 2 == 0)
    {
        e.RowElement.RowInfo.MaxHeight = 1;
    }
    else
    {
        e.RowElement.RowInfo.MaxHeight = int.MaxValue;
    }
}
 
private void Form1_Load(object sender, EventArgs e)
{
    this.productsTableAdapter.Fill(this.nwindDataSet.Products);
 
    this.radGridView1.BestFitColumns(BestFitColumnMode.AllCells);
 
    GridViewSummaryItem summaryItem = new GridViewSummaryItem();
    summaryItem.Name = "UnitPrice";
    summaryItem.Aggregate = GridAggregateFunction.Avg;
    GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
    summaryRowItem.Add(summaryItem);
    this.radGridView1.SummaryRowsTop.Add(summaryRowItem);
 
    summaryItem = new GridViewSummaryItem();
    summaryItem.Name = "UnitPrice";      
    summaryItem.Aggregate = GridAggregateFunction.Avg;
    summaryRowItem = new GridViewSummaryRowItem();
    summaryRowItem.Add(summaryItem);
    this.radGridView1.SummaryRowsTop.Add(summaryRowItem);
 
    this.radGridView1.MasterTemplate.ShowTotals = true;
}



I hope this information helps. If you have any additional questions, please let me know.  
 
Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Mehdi
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or