How to update the DataSource that's bound to a foreignkey column

Hi,

I've a grid with a foreign key column bound to an Autocomplete box and I need to trigger an update to that column data source once the data on the related table has been changed.

Kind Regards

1 Reply

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team May 21, 2018 11:50 AM UTC

Hi Yahia,  
 
Thanks for contacting Syncfusion Support. We could see you would like to update the dataSource to the Grid Column. This can be achieved by calling refreshContent method followed by assigning the new dataSource to the mode.columns[inx].dataSource as shown in the following code example. This has to be done in any external action.  
 
@(Html.EJ().Grid<object>("ForeignKey") 
        .Datasource((IEnumerable<object>)ViewBag.dataSource1) 
        .Columns(col => 
        { 
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width(90).Add(); 
            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add(); 
            //second index ForeignKey column 
            col.Field("EmployeeID").HeaderText("Employee Name") 
            .ForeignKeyField("EmployeeID") 
               .ForeignKeyValue("FirstName") 
               .DataSource((IEnumerable<object>)ViewBag.dataSource2) 
               .TextAlign(TextAlign.Left).Width(90).Add(); 
             
        }) 
) 
<script> 
    function externalCall() {  
        var gridObj = $("#ForeignKey").ejGrid("instance"); 
        gridObj.model.columns[2].dataSource = data;//new datasource 
        gridObj.refreshContent(true); 
    } 
</script> 
 
 
Regards,  
Seeni Sakthi Kumar S. 


Loader.
Up arrow icon