Question#1. I am displaying Products table in grid control. Its a simple list of products. at the end of grid i want to display Count of products.
Question#2. when i use grid's group feature, then it should display Count of products for each group and also display Total count at the end of grid.
Is above possible. Any code sample or ideas.
Regards
9 Answers, 1 is accepted
Here are the answers to your questions:
1) To add an aggregate/count in the footer use this code:
GridViewSummaryItem summaryTotal =
new
GridViewSummaryItem(
"Country"
,
" Total: {0} "
, GridAggregateFunction.Count);
this
.radGridView1.MasterGridViewTemplate.SummaryRowsBottom.Add(
new
GridViewSummaryRowItem(
new
GridViewSummaryItem[] { summaryTotal }));
2) For each group use this code:
GridViewSummaryItem summary =
new
GridViewSummaryItem(
"Country"
,
" Count: {0} "
, GridAggregateFunction.Count);
this
.radGridView1.MasterGridViewTemplate.SummaryRowGroupHeaders.Add(
new
GridViewSummaryRowItem(
new
GridViewSummaryItem[]{summary}));
Sincerely yours,
Julian Benkovthe 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.
It worked. Thanks.
Now can I give some style to this footer summary row. like "Red" background and a different font and size.?
Regards
You can use ViewRowFormatting or ViewCellFormatting to change the appearance of a row or a cell:
void
radGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement.RowInfo
is
GridViewSummaryRowInfo && e.CellElement.ColumnIndex == 8)
{
e.CellElement.DrawFill =
true
;
e.CellElement.GradientStyle = GradientStyles.Solid;
e.CellElement.BackColor = Color.Red;
e.CellElement.Font =
new
Font(e.CellElement.Font, FontStyle.Bold);
}
}
Sincerely yours,
Julian Benkovthe 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.
Thanks. Is it that this can only be done via coding? or we can set formatting of Aggerate Row(s) at design time too?
Regards
In the current edition of RadGridView the only possible solution is to change the rendering of the summary rows. In the next edition of the control we plan to extend the API and improve the formatting, as well as the summary items and rows layouts. More information of RadGridView vNEXT you can find here.
Julian Benkov
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.
I used the posted code, but it doesn't show anything for the summary for the whole rows, when I group by any of the columns I found the count = 0 added to each group but not the right count, what do i missing here ...
Regards
Waleed
Please open a new support ticket and send us a sample project or some code snippets with your scenario which will help us to reproduce the issue locally. This will allow us to understand your case and provide you with further assistance.
Regards,Julian Benkov
the Telerik team
Best Regards.
Hamidnch2007@gmail.com
Thank you for writing.
In order to position the summary item centered, instead of below/above the corresponding column, you can use the ViewCellFormatting event and customize the GridSummaryCellElement.PositionOffset property. Thus, you can place the cell wherever is suitable for you.
As to the question related to merging cells, you can have a look at the RadGridView Merge Cells KB article.
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.