Insert new record doesn't refresh

I have a standard grid, and am trying to use the insert functionality. This works, but after inserting the record, it doesn't appear in the grid. I have to refresh the page to see the new record that's just been added.

<ej-grid id="datagrid" [allowSorting]="true" [allowPaging]="true" [dataSource]="gridData" [toolbarSettings]="toolbarItems" [editSettings]="editSettings">
<e-columns>
<e-column field="id" [visible]="false" [isPrimaryKey]="true"></e-column>
... etc ...
</e-columns>
</ej-grid>

export class MyComponent {
editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true};
toolbarItems = { showToolbar : true, toolbarItems : ["add", "edit", "delete", "update", "cancel"]};

constructor() {
this.datagrid = new ej.DataManager{
url: "/api/exampledata",
crossDomain: true,
adaptor: new ej.WebApiAdaptor(),
headers: [{
Authorization: "Bearer " + this.apiHelper.getToken()
            }]};
     }
}

(code above stripped down to show relevant bits)

Looking at Chrome dev tools - it's doing the POST request, then automatically doing a GET request to get all the results afterwards. These results do include the new record, but the grid doesn't get updated to include it.

Any ideas what I'm doing wrong?

Thanks for your help,
Dan



3 Replies

KM Kuralarasan Muthusamy Syncfusion Team April 5, 2018 12:37 PM UTC

Hi Dan, 

Thanks for contacting Syncfusion support. 

We suspect that you would like to auto-increment or update the value of the Primiary column in the server-end. So, you have set the visibility of the respective column as false. In this, case Grid requires the inserted data as a result from the server-end. To handle this scenario, Grid provides an option called isIdentity property of the Grid Columns. Also, you must return the inserted object to the client-end as shown in the following code example. 

Please refer the following code example: 

Grid.component.html: 

<ej-grid  id="Grid2" [allowSorting]="true" [dataSource]="gridData2"> 
 
                 ..... 
 
    <e-columns> 
 
                 .....            
 
        <e-column field="EmployeeID" [visible]="false" [isPrimaryKey]="true" [isIdentity]="true" headertext="Employee ID"></e-column> 
    </e-columns> 
</ej-grid> 


Controller: 
 
   public object Task<IHttpActionResult> Post([FromBody] Employee emp) 
        { 
 
            ..... 
             
            return emp; 
        } 
 


Please refer the following link to know about isIdentity: 


If you need further assistance please get back to us, 


Regards, 
Kuralarasan M. 



DC Dan Clarke April 12, 2018 08:36 AM UTC

Hi,

I've just tried this and it now works perfectly. Thank you for that.

I had seen the isIdentity setting - but had assumed it meant that SyncFusion would auto-increment it, which obviously wasn't what I wanted. It makes sense though now you say it though.

Thanks again,
Dan



KM Kuralarasan Muthusamy Syncfusion Team April 13, 2018 01:29 PM UTC

Hi Dan,  
 
We are happy to hear that your problem has been solved.  Please let us know if you need further assistance.   
  
Regards,  
Kuralarasan M.  



Loader.
Up arrow icon