We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Refresh parent record after child record is saved

Thread ID:

Created:

Updated:

Platform:

Replies:

129162 Mar 1,2017 07:38 PM UTC Mar 3,2017 04:56 AM UTC ASP.NET MVC 4
loading
Tags: Grid
jestc
Asked On March 1, 2017 07:38 PM UTC

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 40049 Items in OrderOrder Total: $125
Line 1: 4 "A" widgets at $25/eachLine Total: $100

Line 2: 5 "B" widgets at $5/eachLine 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 400410 Items in OrderOrder Total: $150
Line 1: 5 "A" widgets at $25/eachLine Total: $125

Line 2: 5 "B" widgets at $5/eachLine Total: $25

Saravanan Arunachalam [Syncfusion]
Replied On 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. 


Saravanan Arunachalam [Syncfusion]
Replied On 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. 


jestc
Replied On March 2, 2017 01:47 PM UTC

This worked perfectly, thank you for the quick response.

Saravanan Arunachalam [Syncfusion]
Replied On 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;