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.
8 Answers, 1 is accepted
You can use the GridCalculatedColumn as shown in this demo:
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:
Telerik by Progress
Generally, you can use one of the built-in Aggregate options:
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.
//bind the data to the grid
//gets the footer row
GridFooterItem footerItem = (GridFooterItem)grdCommissionEstimate.MasterTableView.GetItems(GridItemType.Footer);
//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();