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

Set the keyField for CRUD Operations

I use the WebApiAdaptor for remote data source. I also want to use the CommandColumn Option to delete the entries.
The issue now is, that the keyField is undefined in the remove function. So I receive urls like `http://example.com/user/undefined` . How do I set the correct key? In my case the key has the name hash and is not displayed in the grid, but is available in the source. I tried to define the key element in the Datamanager section, but I guess it's the wrong part.
<ejs-grid ref='grid' :data-source="gridSource" :allow-paging="true"
>
<e-columns>
<e-column type='checkbox' width='50'>e-column>
<e-column field='firstname' header-text='Filename' width=90 :template="userTemplate">e-column>
<e-column field='account_created' header-text='Created at' width=90>e-column>
<e-column headerText='Manage Records' width='160' :commands='commands'>e-column>
e-columns>
ejs-grid>


data() {
return {

gridSource: new DataManager({
url: '/user',
adaptor: new WebApiAdaptor({

}),
key: 'hash'
}),
commands: [
{ type: 'Delete', buttonOption: { iconCss: 'e-icons e-delete', cssClass: 'e-flat' } },
],
}}

Thanks in advance

2 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team April 1, 2019 07:23 AM UTC

Hi Christopher, 

Greetings from Syncfusion support. 

We have checked your query and we suspect that you did not provide primaryKey to the Grid. PrimaryKey is important when you perform deletion in Grid. So, please enable the primaryKey column by set isPrimaryKey property as true.  

Note: PrimaryKey column must be have the unique values.  

Refer the help documentation. 
 
 
  
If it’s not satisfy your requirement, Could please provide below details that will be helpful for us to provide better solution as early as possible. 

  1. Please share your Grid code.
  2. Share the screenshot of developer tool console to check script error if any.

Regards, 
Thavasianand S. 



CH Chris April 1, 2019 02:21 PM UTC

Hello Thavasianand,

thanks for the hint. solved my issue.

Another question. Is it possible to hook in to the deletion process and show a toast with a message from the server if the deletion process was successfull or not?

Regards

Loader.
Live Chat Icon For mobile
Up arrow icon