Using an array of objects in MVVM

2 posts, 1 answers
  1. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 06 Feb 2015 Link to this post

    In my application I don't need to use all the fancy features of DataSource. So I thought to use an array of 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. 

  2. Answer
    Daniel avatar
    2230 posts

    Posted 10 Feb 2015 Link to this post


    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.

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