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

Using an array of kendo.data.Model objects in MVVM

1 Answer 90 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bilal
Top achievements
Rank 2
Bilal asked on 06 Feb 2015, 04:05 PM
Hi,
In my application I don't need to use all the fancy features of DataSource. So I thought to use an array of kendo.data.Model objects inside the ViewModel.

There is a property called "dirty" and another called "isNew()".

If I want to get all new objects added on client, then I can filter based on isNew = true. To get all those items that need to be updated on server, then I look at "dirty = true".

Is the above correct? Is there another way (could be better) to get list of items to be deleted, updated, created on server?

One more thing, I noticed that if I update a newly added item on client-side, its dirty becomes true and isNew is false. Is that the normal behavior?

Finally, is there a way to use DataSource as a local database on client side to track updated, created, and deleted records, however, having it based on "data" property, i.e. without any remote transport stuff? Then, I could use DataSource as a local storage to track all changes, then I can filter out rows to be deleted, created and updated on server. 

Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 10 Feb 2015, 10:23 AM
Hello,

Straight to your questions:
  1. The approach is correct. For the updated items, you should also check if they are not new. New items could also be changed and become dirty.
  2. isNew will return false if you set the id field value to be different then the default one.
  3. Yes, you can set the data option and use the dataSource as local storage. You might also consider using a dataSource with custom functions for the transport operations(examples are available in the documentation). This way the created, deleted and updated items will be passed to the corresponding function and you will not need to filter the items manually.


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
General Discussions
Asked by
Bilal
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Share this question
or