Changes outside Grid not being reflected on Grid for existing records

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

    Posted 12 Feb 2015 Link to this post

    Hi,
    I have a Grid bound to a DataSource via MVVM.

    I select a row in the Grid, accordingly I use this:
    var grid = e.sender;
    var rowSelected = grid.dataItem(grid.select());
    this.set("currentAccount", rowSelected);
    Where "currentAccount" holds the currently selected row.

    Now, when I do changes on the form fields, they are not being automatically reflected on Grid. I need to call grid.refresh() for the changes to show on grid.

    However, when user presses a button "Add new record", I use this:
    var newRow = this.get("accRegDatasource").add( this._makeAccountModel( 0 ) ); // add new row to data source => reflected on grid
    this.set("currentAccount", newRow); // set new row added as the current account
    var row = input_map.grid().find(" tr[data-uid='" + newRow.uid + "']"); // find the row added into grid
    input_map.kendoGrid().select(row); // select the row added

    Above, I am adding a new empty row. Once I start editing the Form fields, automatically they are being reflected on the Grid without having to call grid.refresh.

    Any idea why this behavior?

    Thanks
  2. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 14 Feb 2015 in reply to Bilal Link to this post

    Here is a running sample: http://dojo.telerik.com/upiPE/26
  3. Kendo UI is VS 2017 Ready
  4. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 14 Feb 2015 in reply to Bilal Link to this post

    Even canceling changes on the selected row not working for existing records! Only for new records.

    Thanks
  5. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 14 Feb 2015 in reply to Bilal Link to this post

    In fact, clicking on Cancel changes is refreshing the grid to latest changes ! Weird behavior.
  6. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 16 Feb 2015 Link to this post

    Hello Bilal,

    The difference comes from the fact that inside dataSource data you should pass plain object literals and the dataSource itself will make it an observable object using the schema.model definition.

    here is an example:

    http://dojo.telerik.com/@pesho/uwiKo

    Kind Regards,
    Petur Subev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  7. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 16 Feb 2015 in reply to Petur Subev Link to this post

    Hello Petur,
    Thanks for the response. The problem was eliminated when I started loading data from server. I am loading them as JSON objects and hence proves your point! Thank you!

  8. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 16 Feb 2015 in reply to Petur Subev Link to this post

    Thanks Petur. When loading data from server this problem has vanished! Now I understand why. Thank you.

    However, another problem pops up. When I select a record, I can edit it in the form, then the values will be reflected on grid. When I hit cancel record changes, they are gone from the data source but not reflected on Grid. 

    I asked about it here: http://www.telerik.com/forums/datasource-cancelchanges-not-reflected-in-ui

    I knew that this is how the library works. Datasource won't fire its change event when cancelChanges is called with a model. So my other option is to just get a reference to grid and do a refresh inside the ViewModel? 

    Here is an example:
    http://dojo.telerik.com/aTiXE/4
  9. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 18 Feb 2015 Link to this post

    Hello Bilal

    I am not sure I understand the core of the issue you have. When cancelChanges is used the change event of the dataSource is not triggered, you can manually refresh the Grid by invoking the refresh method of the Grid:

    http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-refresh

    Kind Regards,
    Petur Subev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  10. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 18 Feb 2015 in reply to Petur Subev Link to this post

    Hello,
    I noticed a new discrepancy!

    cancelChanges(model) not always cancels the changes on model object!

    Here is the same version of the example above, with new features:
    http://dojo.telerik.com/omoGu/4

    For instance, click on the existing record. Change the "Project Description". Then hit "Cancel" on the right side. Sometimes changes are cancelled sometimes they are not!

    Is there something still missing?

    Thanks


  11. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 18 Feb 2015 in reply to Bilal Link to this post

    Hello again,

    I did a small experiment. If "desc" property is added into the Data Source "data", then cancelChanges(model) works fine.

    Seems, if a property was not originally  part of the model ( data returned by Data Source) then tracking for changes is not enabled for those new properties attached at runtime. Is this correct?

    One more thing related to cancelChanges(model).

    Try the following:
    - Select the record
    - Expand "User Info"
    - Click on "+" to add a new user

    You will notice that the Save Changes and Cancel Changes buttons are enabled! Perfect! A new record was added to a child collection on AccountModel, works perfect!

    Now, what if I remove that new user record. Shouldn't the Model notice that the model state is back to its original and mark the parent object as non-dirty? Is this done automatically? If not, how to do this specific case? (just adding record then removing it, making parent object back to original state - not dirty!)

    http://dojo.telerik.com/omoGu/7


    Thanks

  12. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 20 Feb 2015 Link to this post

    Hello again Bilal,

    Yes any new properties added to the model are not tracked and they are not actually bound even the markup for the binding has existed before that.

    Regarding the other questions - if any changes are reverted the dataSource does not track this and it will not set the dirty field to false. Updating is happening once on the first change and cannot be reverted. You can easily check the same in our batch editing demo here:

    http://demos.telerik.com/kendo-ui/grid/editing

    Notice that if you change the first record from "Chai" to something else and you then set it back to "Chai" you will see request performed no matter that there was not real change. 

    Also I would like to open separate thread for the distinct questions. Thank you for the understanding.

    Kind Regards,
    Petur Subev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready