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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Update primary key in the Data Manager datasource

Thread ID:





129227 Mar 6,2017 08:39 AM UTC Mar 14,2017 04:25 PM UTC Angular 3
Tags: ejGrid
Rykunov Alex
Asked On March 6, 2017 08:39 AM UTC


I have a grid, that is manually updated, without using the default syncfusion CRUD methods. I use negative id's to mark "new" records in the grid. Hovewer, when the record is saved in the database, a unique GUID is attached to the record object. It is saved in database, but i need to update it in the grid (so i wont have to reload all the records from the server). Therefore, I want to change the Id of the record. I have the old record, I have the new record that came from the server, but the datamanager "update" method seems to require the primary key — the unique field, that i, besides the id, dont have. Is it possible to still somehow change the record?

Thavasianand Sankaranarayanan [Syncfusion]
Replied On March 7, 2017 04:03 PM UTC

Hi Rykunov, 

Thanks for contacting Syncfusion support. 

Query: The unique field, that I, besides the id, dont have. Is it possible to still somehow change the record? 
We have analyzed your query. We suspect that you want to generate an unique code for the grid record, which used to update the grid record in client side itself. 

If you have defined the IsIdentity column as Auto Generated in the DB. While inserting the new records to the DB, the system will auto-generate the value for the PrimaryKey column. So, while adding new record we need not enter value for the particular column it will be autogenerate the value and field will be in read-only. 

Refer the below code example. 

                // the datasource "window.gridData" is referred from jsondata.min.js 
               dataSource: window.gridData, 
               allowPaging: true, 
                columns: [ 
                        { field: "OrderID", isIdentity: true, isPrimaryKey: true, headerText: "Order ID", textAlign: ej.TextAlign.Right, width: 90 }, 
                        { field: "CustomerID", headerText: "Customer ID", width: 90 }, 
                        { field: "ShipCity", headerText: "Ship City", width: 90 }, 

Refer the help documentation. 

Thavasianand S. 

Rykunov Alex
Replied On March 10, 2017 07:29 AM UTC

Thank you, hovewer, that does not solve my problem. I want to generate the guid myself — on the server. 

For now I delete the old record and then insert a new one, but that is not a preferable way to solve the problem.

Thavasianand Sankaranarayanan [Syncfusion]
Replied On March 14, 2017 04:25 PM UTC

Hi Rykunov, 
We have analyzed your query. We have prepared a sample with the auto generated value in the server side for the column isIdentity column.  
Refer the below code example. 
<ej-grid #grid  [dataSource]="gridData" [allowScrolling]=true > 
             <e-column field="OrderID" [isPrimaryKey]="true" [isIdentity]="true" width="75" textAlign="right"></e-column> 
        <e-column field="EmployeeID" headerText="Employee ID" [validationRules] = "{ required: true, number: true }" width="75" textAlign="right"></e-column> 
        <e-column field="CustomerID" headerText="CustomerID" width="80"textAlign="right"></e-column> 
If you are using CRUD operations, we suggest to return the update records to client end. Since you are using the IsIdentity for the PrimaryKey column, the value in the client-side differs from the server-side and to notify the changes on the IsIdentity column you have to return them from server-end. Refer to the following code example. 

public ActionResult Update(Orders value) 
            var data = order.ToList(); 
            Orders result = data.Where(o => o.OrderID == value.OrderID).FirstOrDefault(); 
            if (result != null) 
                result.OrderID = value.OrderID; 
                result.CustomerID = value.CustomerID; 
                result.EmployeeID = value.EmployeeID; 
           return Json(value, JsonRequestBehavior.AllowGet); 
        public ActionResult Insert(Orders value) 
            int generate = order.ToList().Count(); 
            value.OrderID = ++generate; // set the auto generated value to the OrderID column 
            order.Insert(0, value); 
            return Json(value, JsonRequestBehavior.AllowGet); 
        public ActionResult Delete(int key) 
            var data = order.ToList(); 
            Orders result = data.Where(o => o.OrderID == key).FirstOrDefault(); 
            return Json(data, JsonRequestBehavior.AllowGet); 
We have prepared a sample and it can be downloadable from the below location. 

We have included angular2 sample also with in the project. 

Note:  First run angular2 sample separately for including packages and then run the project and change the path as (http://localhost:49349/angular2/ejGrid_Vpaging%20-%20Copy/ejGrid_Vpaging/) to run the sample in angular 2 
Thavasianand S. 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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