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. Image for the cookie policy date

I have problem with getting id row in grid AND refresh GRID without refresh browser


I have problem with getting id row AND refresh GRID without refresh browser

Ofter saving(Insert Data to sql database) it needs get id( key "IsPrimaryKey and IsIdentity ") of  inserted row   or  refresh data in grid after inserting without browser refresh   

@{Html.EJ().Grid<Object>("FlatGrid") .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.data).UpdateURL("/TestTablesControllerView/CellEditUpdate").InsertURL("/TestTablesControllerView/CellEditInsert")

.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
  .ToolbarSettings(toolbar =>
  toolbar.ShowToolbar().ToolbarItems(items =>
 .Columns(col =>
col.Field("Tkey").HeaderText("TKey").IsPrimaryKey(true).IsIdentity (true).Add();
 col.Field("Tid").HeaderText("Tid"   ).Add();



the set available code for get id after insert has technical problem :  "  value.Value.OrderID =order.LastOrDefault().OrderID + 1;"

I'm waiting for your prompt reply

thanks and regards.

1 Reply

VA Venkatesh Ayothi Raman Syncfusion Team April 7, 2017 12:51 PM UTC

Hi Hassan, 
Thanks for contacting Syncfusion support. 
Query #1: “Get the row ID while inserting the record” 
We went through your code example and found that you are using isIdentity property in Grid. If we enable the Isidentity property for Auto increment column then we must handle that Auto increment column.  
So, we are the responsibility to handle the Isidentity property. While performing CRUD operation in Grid with IsIdentity column, we need to return the modified value, because of we have handled IsPrimary key column value in server side. So, we suggest you to return the modified value while performing the CRUD operation in Grid like as follows, 
Code example
public ActionResult Insert([FromBody]OrdersView value) 
            value.OrderID = ++count; //Auto increment the value for isIdnetity property 
            return Json(value, JsonRequestBehavior.AllowGet); 

Another way
You may also set the isIdentity field value while saving the record in actionBegin event like as follows, 
Code example
                            .Datasource(ds => ds.URL(@Url.Action("DataSource")).UpdateURL("/Home/CellEditUpdate") 
                      .InsertURL("/Home/CellEditInsert").RemoveURL("/Home/CellEditDelete").Adaptor(AdaptorType. RemoteSaveAdaptor)) 
                           .Columns(col => 
                               col.Field("OrderID").IsPrimaryKey(true) .IsIdentity(true).TextAlign(TextAlign.Right).Width(90).Add(); 
                               . . . 
@ActionBegin event 
<script type="text/javascript"> 
var flag=false, count=100;  
    function actionBegin(args) {         
        if (args.requestType == "add") 
            flag = true; 
        //Set the isIdentity value while inserting the record 
        if (flag && args.requestType == "save") { 
            args.data.OrderID = count++;// here OrderID is the isIdentity field and set the value while inserting the record 
            flag = false; 

Query #2: “Refresh the Grid without refresh the browser” 
We can refresh the Grid by calling the refreshContent method in Grid. Here we can refresh the Grid using button click. Please refer to the below code example and Help document, 
Code example
<input type="button" value="Grid Refresh" id="refresh"/> 
                            .Datasource(ds => ds.URL(@Url.Action("DataSource")).UpdateURL("/Home/CellEditUpdate")                      .InsertURL("/Home/CellEditInsert").RemoveURL("/Home/CellEditDelete").Adaptor(AdaptorType. RemoteSaveAdaptor)) 
                           .Columns(col => 
                               . . .   
//Refresh the Grid using button click 
        click: function () { 
            var gridObj = $("#Grid").ejGrid("instance"); 
            gridObj.refreshContent(); //Refresh the Grid by calling the refreshContent method 

Venkatesh Ayothiraman. 

Live Chat Icon For mobile
Up arrow icon