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

Item vanishes after cancelling edit mode

2 Answers 140 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 06 Jan 2015, 11:07 AM
Hi,

We are using a MVVM ListView with the edditing feature, following your example in the demo section. We've also added an "Add record" button in order to insert new records. Everything works fine, we can add and update items. But if we try to cancel the editing the item vanishes from the list.

This is how the add method looks like:

01.addRecord: function (e)
02. {
03.         console.log("addRecord");
04.         var listView = $("#myTestList").data("kendoListView");
05.         listView.dataSource.insert(0, {
06.             "ProductID": Math.floor(Math.random()*100),
07.             "ProductName": "test",
08.             "UnitPrice": 2,
09.             "UnitsInStock": 39,
10.             "Discontinued": false
11.         });
12.   }

It was not possible to use the listView.add() method. When we tried this, Kendo always throws an exception "ProductName is not defined".

While debugging the kendo.web.js we've noticed that the "_pristineData" value is undefined / empty when iterating through the original items

1._eachPristineItem: function(callback)
2. {
3.    this._eachItem(this._pristineData, callback);
4.}

Based on your demo we've created a fiddle in order to reproduce it.

How can we add the new items to the _pristineData? Are we missing something?

Thanks in advance,
Patrick

2 Answers, 1 is accepted

Sort by
0
Patrick
Top achievements
Rank 1
answered on 06 Jan 2015, 11:14 AM
There was something wrong after formatting the fiddle.

The correct link is: http://jsfiddle.net/ynqbqkLz/4/
0
Alexander Valchev
Telerik team
answered on 08 Jan 2015, 08:46 AM
Hi Patrick,

Thank you for contacting us.

The _pristineData array is internal for the DataSource and you should not modify it manually.
In case remote transport is used, when new record is added its ID field should be left empty. After the record is added you should call dataSource.sync() method to synchronize the changes with the remote server, the remote server should generate unique record ID and return it back to the dataSource. Then the _pristineData will be automatically updated.

In case local transport is used, the developer should create a custom transport methods.

For more information please check this help topic:
Alto the examples inside the article use Kendo Grid, exactly the same is valid for Kendo ListView.

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