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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how to return data from server while performing CRUD operation if IsIdentity column is defined

When enabling the IsIdentity property for Auto incremented column then we should return the values along with the response which is generated the value for IsIdentity column. Please refer to the following code example,

JS

var dataManager = ej.DataManager({ url: "/Home/DataSource", insertUrl: "/Home/Insert", updateUrl: "/Home/Update", DeleteUrl: "/Home/Delete", adaptor:"UrlAdaptor"});

      

        $("#Grid").ejGrid({

            dataSource: dataManager,

            allowPaging: true,

            editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true },

            toolbarSettings:{showToolbar:true,toolbarItems:["add","edit","cancel","update","delete"]},

            columns: [

                    { field: "OrderID", isPrimaryKey: true, isIdentity:true, type:"number", headerText: "Order ID" },

                    { field: "EmployeeID", type:"number", headerText: 'Employee ID' },

                    { field: "Freight", type:"number", headerText: 'Freight', format: "{0:C}" },

                    { field: "CustomerID",type:"string",headerText: 'Ship City' },

                    

            ],

            

 

        });

 

MVC

@(Html.EJ().Grid<EditableOrder>("Grid")

                           .Datasource(ds => ds.URL(@Url.Action("DataSource")).UpdateURL("/Home/Update").InsertURL("/Home/Insert").RemoveURL("/Home/Delete")

                    .Adaptor(AdaptorType.UrlAdaptor))

                    .AllowPaging()

                    .Columns(col =>

                     {

 

                        col.Field(p => p.OrderID).IsPrimaryKey(true).IsIdentity(true).HeaderText("Order ID").Add();

                        col.Field(p => p.EmployeeID).HeaderText("Employee ID").Add();

                        col.Field(p => p.Freight).HeaderText("Freight").Format("{0:C2}").Add();

                        col.Field(p => p.CustomerID).HeaderText("Customer ID").TextAlign(TextAlign.Left).Add();

                     })

            )

 

 

Server Side

  public ActionResult Insert(EditableOrder value)

        {

            OrderRepository.Add(value);

            var data = OrderRepository.GetAllRecords();

            return Json(value, JsonRequestBehavior.AllowGet);

        }

 

Note: Data source will be handled the Auto incremented column. Otherwise we need to set the value for IsIdentity column like as follows.

public ActionResult Insert(EditableOrder value)

        {

            

            var data = OrderRepository.GetAllRecords().Last();

            value.OrderID = ++data.OrderID;

            OrderRepository.Add(value);

            return Json(value, JsonRequestBehavior.AllowGet);

        }

 

Article ID: Published Date: Last Revised Date: Platform: Control:
7732 05/26/2017 05/26/2017 JavaScript ejGrid
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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