- Home
- Forum
- ASP.NET MVC
- Refresh parent record after child record is saved
Refresh parent record after child record is saved
My scenario is that I have a hierarchical grid and want to refresh/update the parent record after any child record is saved.
Here is an example of my use case... a grid of orders, with the line items of each order shown in a child grid, something like the following:
| Order Number 4004 | 9 Items in Order | Order Total: $125 | |
| Line 1: 4 "A" widgets at $25/each | Line Total: $100 | ||
| Line 2: 5 "B" widgets at $5/each | Line Total: $25 |
If a line item is updated and saved, how can the parent record be refreshed to show the updated number of items in the order as well as the total order amount? For example, if line 1 is updated from 4 to 5 "A" widgets, the parent record should show as:
| Order Number 4004 | 10 Items in Order | Order Total: $150 | |
| Line 1: 5 "A" widgets at $25/each | Line Total: $125 | ||
| Line 2: 5 "B" widgets at $5/each | Line Total: $25 |
SIGN IN To post a reply.
4 Replies
SA
Saravanan Arunachalam
Syncfusion Team
March 2, 2017 12:37 PM UTC
Hi James,
Thanks for contacting Syncfusion’s support.
We have analyzed your requirement and achieved it by using “ActionComplete” event of child Grid control. In the ActionComplete event, we have update the corresponding parent record by using “updateRecord” method of Grid control while save edited record in child Grid. Please refer to the below code example.
|
@(Html.EJ().Grid<EmployeeView>("HierarchyGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
. . .
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("Items").Width(100).Add();
col.Field("Total").Width(120).Add();
})
.ChildGrid(child =>
{
. . .
.ClientSideEvents(e=> e.ActionComplete("onActionComplete"))
.Columns(col =>
{
col.Field("Line_No").HeaderText("Line No").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("Line_Item").HeaderText("Line Item").Width(100).Add();
col.Field("Line_Total").Width(120).Add();
});
})
)
<script type="text/javascript">
function onActionComplete(args) {
if (args.requestType == "save") {
var itemSum = ej.sum(this.model.currentViewData, "Line_Item"), totalSum = ej.sum(this.model.currentViewData, "Line_Total");
var parentGridObj = $("#HierarchyGrid").ejGrid("instance"), obj = {};
obj = { OrderID: this.model.currentViewData[0].OrderID, Items: itemSum, Total: totalSum };
parentGridObj.collapseAll();
parentGridObj.updateRecord("OrderID", obj);
}
}
</script>
|
And also we have created a sample that can be downloaded from the belo link.
Regards,
Saravanan A.
SA
Saravanan Arunachalam
Syncfusion Team
March 2, 2017 01:15 PM UTC
Hi James,
Please ignore the previous update.
Thanks for contacting Syncfusion’s support.
We have analyzed your requirement and achieved it by using “ActionComplete” event of child Grid control. In the ActionComplete event, we have update the corresponding parent record by using “updateRecord” method of Grid control while save edited record in child Grid. Please refer to the below code example.
|
@(Html.EJ().Grid<EmployeeView>("HierarchyGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
. . .
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("Items").Width(100).Add();
col.Field("Total").Width(120).Add();
})
.ChildGrid(child =>
{
. . .
.ClientSideEvents(e=> e.ActionComplete("onActionComplete"))
.Columns(col =>
{
col.Field("Line_No").HeaderText("Line No").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("Line_Item").HeaderText("Line Item").Width(100).Add();
col.Field("Line_Total").Width(120).Add();
});
})
)
<script type="text/javascript">
function onActionComplete(args) {
if (args.requestType == "save") {
var itemSum = ej.sum(this.model.currentViewData, "Line_Item"), totalSum = ej.sum(this.model.currentViewData, "Line_Total");
var parentGridObj = $("#HierarchyGrid").ejGrid("instance"), obj = {};
obj = { OrderID: this.model.currentViewData[0].OrderID, Items: itemSum, Total: totalSum };
parentGridObj.collapseAll();
parentGridObj.updateRecord("OrderID", obj);
}
}
</script>
|
And also we have created a sample that can be downloaded from the belo link.
Regards,
Saravanan A.
JE
jestc
March 2, 2017 01:47 PM UTC
This worked perfectly, thank you for the quick response.
SA
Saravanan Arunachalam
Syncfusion Team
March 3, 2017 04:56 AM UTC
Hi James,
Thanks for your update.
We are happy that the provided information helped you.
Regards,
Saravanan A.
SIGN IN To post a reply.
- 4 Replies
- 2 Participants
-
JE jestc
- Mar 1, 2017 07:38 PM UTC
- Mar 3, 2017 04:56 AM UTC