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

RadGridView with group/summary rows only on bottom

15 Answers 505 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roberto
Top achievements
Rank 1
Roberto asked on 12 Jan 2011, 10:55 PM
Hi,

I have a GridView where I'm adding a grouping, and then summarizing some values for each group.  I'm trying to get the grouping / summary rows to ONLY show at the bottom of each group.  It seems that by default when adding a group that a group row always shows up at the top of each group.  Here is a snippet of my code:

GridGroupByExpression groupExprCol1 = new GridGroupByExpression("col_1 Group By  col_1");
grid1.GroupDescriptors.Add(groupExprCol1);
GridViewSummaryItem
sumItemValue = new GridViewSummaryItem("value", "{0,12:#,0;(#,0)}"
    GridAggregateFunction.Sum);
GridViewSummaryRowItem sumGroupCol1 = 
new GridViewSummaryRowItem();
sumGroupCol1.Add(sumItemValue);  
grid1.MasterTemplate.SummaryRowsBottom.Add(sumGroupCol1);

The end result that I'm trying to achieve would look similar to this:

Col 1 Col 2 Value
AA Yes 1
AA No 2
AA No 2
AA Yes 5
Total AA:   10
BB No 3
BB No 2
Total BB:   5
CC Yes 4
Total CC:   4

So basically I'm trying to avoid displaying a group header row at the top of each group, and just show a summary row at that bottom of each group.  Any help would be greatly appreciated.  Thanks.

15 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 12 Jan 2011, 11:28 PM
Hi Roberto,

In order to do this, you just need to set the group header height on the table elment. So, after your group descriptors and summary row definition....

// Group By
GroupDescriptor descriptor = new GroupDescriptor();
descriptor.GroupNames.Add("Name", ListSortDirection.Ascending);
this.radGridView1.GroupDescriptors.Add(descriptor);
// Summary Row
GridViewSummaryItem summaryItem = new GridViewSummaryItem();
summaryItem.Name = "Id";
summaryItem.FormatString = "SUM={0}";
summaryItem.Aggregate = GridAggregateFunction.Sum;
GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);
this.radGridView1.SummaryRowsBottom.Add(summaryRowItem);
// Get rid of the group header....
this.radGridView1.TableElement.GroupHeaderHeight = 0;

Hope that helps
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 13 Jan 2011, 09:54 PM
Hello Roberto,

Did this help?If so, please remember to mark as answer. If you need more assistance, please let me know
Richard
0
Roberto
Top achievements
Rank 1
answered on 11 Apr 2011, 06:54 AM
Hi Richard,

Your reply is very helpful, thank you.  Although there's one requirement I didn't specify in my original post: If I have multiple groups within my gridView, is it possible to hide the group header row for only one of the groups - i.e. the lowest level group?

Thanks in advance!
Roberto
0
Richard Slade
Top achievements
Rank 2
answered on 11 Apr 2011, 09:11 AM
Hello,

You can hide and manage formatting of these rows using ViewRowFormatting event. See this help topic for more information.
You can also perform group header formatting using the Group Summary Evalulate event

Hope that helps
Richard
0
Roberto
Top achievements
Rank 1
answered on 11 Apr 2011, 06:27 PM
Hi Richard,

I read through the links you provided, and tried using the ViewRowFormatting event but was unable to hide only the lower-level group header row.  I'm trying to achieve something similar to the table shown below; where only the "Col1" group header rows are displayed, but the "Col2" group header rows are NOT visible.  Another problem I have is that I can't get the bottom summary rows to show for both grouping levels.  They only show for the lower-level group (i.e. Col2 in my table below), but not for the higher-level group (i.e. Col 1).  For the bottom summary rows I'm using  the following:

this

 

.gridView.SummaryRowsBottom.Add(gridViewSummaryRowItem1);

Any help you might be able to provide would be greatly appreciated.  Thanks!

  Col1 Col2 Col3 Value
AA Group      
AA Red Yes   2
AA Red Yes   5
AA Red No   3
  Total Red:    10
AA Green No   4
AA Green No   6
AA Green Yes   2
  Total Green:    12
AA Blue Yes   7
AA Blue No   3
  Total Blue:    10
Total AA:  32
  BB Group      
BB Red Yes   6
BB Red Yes   9
  Total Red:    15
BB Green No   2
BB Green Yes   2
  Total Green:   4
BB Blue Yes   4
BB Blue No   3
  Total Blue:     7
Total BB:  26
  CC Group      
CC Red Yes   6
CC Red Yes   1
  Total Red:     7
CC Green No   2
CC Green Yes   6
  Total Green:     8
CC Blue Yes   5
CC Blue     9
CC Blue No   3
  Total Blue:    17
Total CC:  32
Grand Total  90


Roberto

0
Richard Slade
Top achievements
Rank 2
answered on 12 Apr 2011, 10:56 AM
Hi Roberto,

I may be wrong, but as far as I'm aware, to keep all your headers AND layout as per your chart, I dont think this is currently supported.
You can add the total to the end by setting:
this.radGridView1.MasterTemplate.ShowTotals = true;

and you could also hide a group header by cutting it the opposite way. I.e. Not showing all, and then re-showing the one that you want.
this.radGridView1.TableElement.GroupHeaderHeight = 0;

void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
    if (e.SummaryItem.Name == "Col1")
    {
        e.Group.HeaderRow.Height = 24;
    }
}

But when you have the grid grouped by two columns, then you are going to loose the headers for the first two columns as these have been grouped. Perhaps there is another way we can work around this.

Regards,
Richard
0
Alexander
Telerik team
answered on 14 Apr 2011, 09:04 AM
Hi guys,

Richard's solution for displaying summary rows at every group level and showing only particular group header rows is fine. I suppose that you have set the AutoExpandGroups property of RadGridView to 'true'. In the opposite case you will not be able to expand the groups with hidden header rows.

The following is the default grid behavior as Richard explained it:

'But when you have the grid grouped by two columns, then you are going to lose the headers for the first two columns as these have been grouped.' 

In order to keep the grouped column header visible, you can set the ShowGroupedColumns property of RadGridView to 'true'.

Should you have any other questions, do not hesitate to ask.

Best regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Roberto
Top achievements
Rank 1
answered on 14 Apr 2011, 03:01 PM
Thank you both for your help.  I'm still having an issue with the BOTTOM summary rows - they do not show for both grouping levels.  They only show for the lower-level group (i.e. Col2 in my table below), but not for the higher-level group (i.e. Col 1).  For the bottom summary rows I'm using  the following method:

this.gridView.MasterTemplate.SummaryRowsBottom.Add(gridViewSummaryRowItem1);

From what I have read in the documentation, this method should show the summary rows for all groups by default.  Is this the case?  Or is there something else I may need to do?

Any help you might be able to provide would be greatly appreciated.  Thanks!

Roberto

0
Alexander
Telerik team
answered on 19 Apr 2011, 01:22 PM
Hello Roberto,

You can show the summary rows for all grouping levels using the ShowParentGroupSummaries property:
this.radGridView1.MasterTemplate.ShowParentGroupSummaries = true;

I hope this helps.

Best regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 07 Mar 2017, 04:08 AM
Hi Richard,


    How could I change the color of Pinned row of Radgrid,where I have lot of summary rows and I pinned the last total value of my documents .

Where I used to Pinned Row with this code,
this.DgvTrialBalance.MasterView.SummaryRows[0].PinPosition = PinnedRowPosition.Bottom;

 

I want to change the color where I red marked in the below pic.
Expecting your help,
Thanks in advance!
Roberto
0
Dimitar
Telerik team
answered on 07 Mar 2017, 01:36 PM
Hi,

You should use the ViewCellFormatting event to style summary cells. For example:
private void RadGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement is GridSummaryCellElement)
    {
        e.CellElement.DrawFill = true;
        e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
        e.CellElement.BackColor = Color.Red;
 
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
    }
}
 
I hope this will be useful. 

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 14 Mar 2017, 07:24 AM

Hello Dimitar,

     Where I used that code before but there all the summery rows changing there color ,where i need to change color only the last summery row .

Thanks in advance
jamsheer

0
Dimitar
Telerik team
answered on 14 Mar 2017, 10:20 AM
Hi Jamsheer,

You can check the Name of the summary item in the currently formatted row:
private void RadGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement is GridSummaryCellElement)
    {
        var row = e.Row as GridViewSummaryRowInfo;
        if (row.SummaryRowItem.FirstOrDefault().Name == "Name1")
        {
            e.CellElement.DrawFill = true;
            e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
            e.CellElement.BackColor = Color.Red;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
    }
}

I hope this will be useful.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 15 Feb 2018, 10:13 AM

Hi,
     I have RadGridview with grouped columns. and their summery.

Where I want to hide summery of group and Show only Total summery of grid.

I want to show only  the red mark summery row, the black mark row to hide in the below pic .

How could i do .

Thanks in advance
jamsheer

0
Dimitar
Telerik team
answered on 16 Feb 2018, 10:57 AM
Hello Jamsheer,

There is no way to hide the summaries inside the group. We will consider such functionality if we receive more requests for it.

Thank you for your understanding.

Regards,
Dimitar
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
Roberto
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Roberto
Top achievements
Rank 1
Alexander
Telerik team
jamsheer
Top achievements
Rank 1
Veteran
Dimitar
Telerik team
Share this question
or