Grid Crud operation on localdata source (array) not working error TypeError: Cannot read property 'id' of undefined while click on add button
1 Answer, 1 is accepted
0
Dimiter Topalov
Telerik team
answered on 25 Dec 2017, 10:29 AM
Hi Rajesh,
The described error seems to be caused by the fact that an expected "id" property is not set on the newly added item. You can check out the following example that demonstrates Grid editing in a scenario with local data:
The save() method in the editing service receives information whether the item is new (or an existing item is being edited) and if the item is new, a "ProductID" field is created and set:
Other examples that involve remote data service also differentiate between adding and updating an item, and issue different requests such that eventually a new item with the expected fields is created and opened for editing in the Grid, e.g.:
The built-in Grid editing behavior boils down to creating a new item with the respective fields, and opening it for editing in the Grid when the Add button is pressed, so depending on the specific scenario the means for providing an ID to the new item may vary.