I’m using a radgrid with boundcolumns, some of the columns are displayed as percentages. How would I display percentages in the group footer and the grand total footer? It's easy to sum, count fields in footers but I'm stumped with how to create calculated fields in footers.
The percentage would be calculated by sum of one column divided by the other. I looked at the example that uses the CustomAggregates event but if I used that then it would have to create a datatable for every percentage column for every group which would be significant overhead.
Let me know if you have any suggestions.
Thanks,
Bob
8 Answers, 1 is accepted
You can use the GridCalculatedColumn as shown in this demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/groupby/groupfooter/defaultcs.aspx
Marin
the Telerik team
GridCalculatedColumn does not provide a proper calculation for percentages of an aggregate footer row.
For example, I have 4 rows of percentages (0%, 50%, 100%, 100%) calculated from Row1 / TotalsColumn, and the footer row percentage shows up as 250% if I set the property Aggregate="Sum".
The Row1 values (0,1,1,3) total to 5, the TotalsColumn values (1,2,1,3) total to 7. This calculates to 71.43%.
Please provide an appropriate answer.
You can use custom aggregates to calculate the required value as shown in this help article:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/totals-in-grid-footers
Regards,
Marin
Telerik by Progress
Generally, you can use one of the built-in Aggregate options:
<
telerik:GridNumericColumn
...
DataFormatString
=
"{0:P}"
Aggregate
=
"Avg"
>
Alternatively, you can calculate your own preferred value similar to the approach demonstrated in the attached web site sample.
I hope this will prove helpful.
Regards,
Eyup
Progress Telerik
//bind the data to the grid
grdCommissionEstimate.DataBind();
//gets the footer row
GridFooterItem footerItem = (GridFooterItem)grdCommissionEstimate.MasterTableView.GetItems(GridItemType.Footer)[0];
//this looks up the text by the DataField value and pulls the footer total, then does the math
Decimal ThePercent = Math.Round((Convert.ToDecimal(footerItem["CommissionableAmount"].Text) / Convert.ToDecimal(footerItem["NetSalesValue"].Text)) * 100, 2);
//pushes the calculated value to the new footer column
footerItem["CommissionableAmountPercent"].Text = ThePercent.ToString();
Thank you for sharing your specific approach with your community.
Regards,
Eyup
Progress Telerik