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

DataSource Add removing current data

2 Answers 107 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Christy
Top achievements
Rank 1
Christy asked on 20 Oct 2016, 06:19 PM

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 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 21 Oct 2016, 12:25 PM
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.
 
0
Christy
Top achievements
Rank 1
answered on 21 Oct 2016, 02:14 PM
Thanks!  This worked great.  Site isn't letting me Mark as Answered.
Tags
Data Source
Asked by
Christy
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Christy
Top achievements
Rank 1
Share this question
or