This is a migrated thread and some comments may be shown as answers.

Cancelling edit deletes programmatically added model

2 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jesper
Top achievements
Rank 1
Jesper asked on 26 Jun 2012, 11:14 AM
If you add a model programmatically to your grid datasource - for example using the add()-method - set the corresponding row to edit mode and cancel the edit without changing anything, the model will be deleted.

This is the kind of behaviour you'd expect if you add an empty row to the grid and then cancel the edit without entering any information.

See this fiddle: http://jsfiddle.net/MM5Ke/3/

To reproduce, click the edit button, then the update button. The row will disappear. 
There's also an uncaught TypeError.

If this is to be intended behaviour, errors should be dealt with and the behaviour should be better documented.

2 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 22 Nov 2012, 04:35 PM
Having the same problem using MVC Wrappers. Seems odd that this is happening inside a wrapper as it wouldn't build if there was a typo or something missing!

My code looks the same as the KendoUI example, apart from the Model which has a few more items in it.
0
Alexander Valchev
Telerik team
answered on 27 Nov 2012, 04:13 PM
Hello guys,

The behaviour is caused by the fact that when you add a new item in this way its ID is not initially equal to the default one which is why the Grid cannot save it nor update its internal data.
The recommended approach is to add a new (empty) record, set the values (like in the editing process) and sync the changes. As an example:
var m = grid.dataSource.add();
m.set("bar", "baz");
m.set("foo", 1);
grid.dataSource.sync();

For convenience I prepared a simplified example using this approach in action.

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Jesper
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Alexander Valchev
Telerik team
Share this question
or