Item vanishes after cancelling edit mode

3 posts, 0 answers
  1. Patrick
    Patrick avatar
    9 posts
    Member since:
    Jun 2014

    Posted 06 Jan 2015 Link to this post


    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);

    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,
  2. Patrick
    Patrick avatar
    9 posts
    Member since:
    Jun 2014

    Posted 06 Jan 2015 Link to this post

    There was something wrong after formatting the fiddle.

    The correct link is:
  3. Alexander Valchev
    Alexander Valchev avatar
    2873 posts

    Posted 08 Jan 2015 Link to this post

    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.

    Alexander Valchev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top