DataSource Add removing current data

3 posts, 0 answers
  1. Christy
    Christy avatar
    38 posts
    Member since:
    May 2016

    Posted 20 Oct Link to this post

    I am trying to test out some ideas for adding data to a dataSource and then updating the local copy for a ListView.  There is an API call that runs in the background, and I DON'T want this to be editable within the ListView itself.  While trying out some ideas, I looked at the DoJo at the DataSource add method. I have changed the code as follows. I expect to have 2 records and to have Jane Doe appear first.  Why is this not the case?
    Thanks!

    <body>
      <p id="num"></p>
      <p id="first"></p>
      <p id="second"></p>
       
    <script>
    var dataSource= new kendo.data.DataSource({
      data: [
        { name: "Jane Doe", age: 30 }
      ]
    });
    dataSource.add({ name: "John Doe", age: 33 });
    dataSource.sync();
    var data = dataSource.data();
     
    $('#num').text(data.length);  // displays "1"
    $('#first').text(data[0].name); // displays "John Doe"
    $('#second').text(data[1].name);  // gives error
     
    </script>
    </body>
  2. Stefan
    Admin
    Stefan avatar
    268 posts

    Posted 21 Oct Link to this post

    Hello Christy,

    The reason for this behaviour is that the dataSource have to be read first. This is not needed when it is connected to a widget because the widget is calling the read method internally, except in the cases where the autoBind property is set to false:

    http://docs.telerik.com/kendo-ui/framework/datasource/basic-usage#create-datasource-for-local-data

    Please check the modified Dojo which is working as expected:

    http://dojo.telerik.com/AJEro

    Let me know if you need additional information on this matter.

    Regards,
    Stefan
    Telerik by Progress
     
    Build rich, delightful, *native* Angular 2 apps with Kendo UI for Angular 2. Try it out today! Kendo UI for Angular 2 (currently in beta) is a jQuery-free toolset, written in TypeScript, designed from the ground up to offer true, native Angular 2 components.
     
  3. Kendo UI is VS 2017 Ready
  4. Christy
    Christy avatar
    38 posts
    Member since:
    May 2016

    Posted 21 Oct in reply to Stefan Link to this post

    Thanks!  This worked great.  Site isn't letting me Mark as Answered.
Back to Top