Hi,
I would like to know if I can have a column in the master grid that it's a sum of child column?
For example, I have a master "invoices" grid with the "invoice lines" child grid. In the "invoices" grid I want a column with the total price of invoice, calculated from the sum of price column in "invoice lines" grid.
It's possible?
Regards
Jose
I would like to know if I can have a column in the master grid that it's a sum of child column?
For example, I have a master "invoices" grid with the "invoice lines" child grid. In the "invoices" grid I want a column with the total price of invoice, calculated from the sum of price column in "invoice lines" grid.
It's possible?
Regards
Jose
4 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 22 Mar 2011, 12:46 PM
Hello Jose,
You can access the nested table view (detail table) of the each item and traverse each detail table item to calculate the value(cell value) .Then assign it to corresponding column(cell) of parent item. The following documentation will help you to access the nested table view of each item.
Traversing detail tables/items in Telerik RadGrid
Also refer the following documentation for accessing cells and rows in grid item.
Accessing cells and rows
Thanks,
Princy.
You can access the nested table view (detail table) of the each item and traverse each detail table item to calculate the value(cell value) .Then assign it to corresponding column(cell) of parent item. The following documentation will help you to access the nested table view of each item.
Traversing detail tables/items in Telerik RadGrid
Also refer the following documentation for accessing cells and rows in grid item.
Accessing cells and rows
Thanks,
Princy.
0

Jose
Top achievements
Rank 2
answered on 22 Mar 2011, 04:49 PM
Hi Princy,
Thank you very much for your help.
I've tried with your suggestions but I'm unable to make it works.
This is the code that I'm trying in ItemDataBound event but it fails:
Any idea?
Regards
Jose
Thank you very much for your help.
I've tried with your suggestions but I'm unable to make it works.
This is the code that I'm trying in ItemDataBound event but it fails:
// Calculate Invoice Total column
if
(e.Item.OwnerTableView.Name ==
"Master"
)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
decimal
totalInvoice = 0;
GridTableView detailsTable = item.ChildItem.NestedTableViews[0];
foreach
(GridDataItem childItem
in
detailsTable.Items)
{
totalInvoice += System.Convert.ToDecimal(childItem[
"Price"
].Text);
}
item[
"TotalInvoice"
].Text = String.Format(
"{0:c}"
, totalInvoice);
}
}
Any idea?
Regards
Jose
0
Accepted

Princy
Top achievements
Rank 2
answered on 23 Mar 2011, 07:06 AM
Hello Jose,
Try the following code snippet in PreRender event and check if it works now.
C#:
Thanks,
Princy.
Try the following code snippet in PreRender event and check if it works now.
C#:
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
foreach
(GridDataItem item
in
RadGrid1.Items)
{
if
(item.Expanded)
{
GridTableView tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
decimal
totalInvoice = 0;
foreach
(GridDataItem childitem
in
tableView.Items)
{
totalInvoice += System.Convert.ToDecimal(childItem[
"Price"
].Text);
}
}
}
}
Thanks,
Princy.
0

Jose
Top achievements
Rank 2
answered on 24 Mar 2011, 12:12 PM
Thank you very much Princy.
I've added to the grid HierarchyLoadMode="ServerBind" because I need the totals in every row and not only expanded rows.
Also I've changed "if (item.expanded)" by "if (item.ChildItem != null)".
Thank you very much for your help.
Regards
Jose
I've added to the grid HierarchyLoadMode="ServerBind" because I need the totals in every row and not only expanded rows.
Also I've changed "if (item.expanded)" by "if (item.ChildItem != null)".
Thank you very much for your help.
Regards
Jose