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

Changes outside Grid not being reflected on Grid for existing records

10 Answers 286 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bilal
Top achievements
Rank 2
Bilal asked on 12 Feb 2015, 02:04 PM
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

10 Answers, 1 is accepted

Sort by
0
Bilal
Top achievements
Rank 2
answered on 14 Feb 2015, 09:12 AM
Here is a running sample: http://dojo.telerik.com/upiPE/26
0
Bilal
Top achievements
Rank 2
answered on 14 Feb 2015, 09:27 AM
Even canceling changes on the selected row not working for existing records! Only for new records.

Thanks
0
Bilal
Top achievements
Rank 2
answered on 14 Feb 2015, 11:54 AM
In fact, clicking on Cancel changes is refreshing the grid to latest changes ! Weird behavior.
0
Petur Subev
Telerik team
answered on 16 Feb 2015, 03:20 PM
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!
 
0
Bilal
Top achievements
Rank 2
answered on 16 Feb 2015, 06:56 PM
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!

0
Bilal
Top achievements
Rank 2
answered on 16 Feb 2015, 07:07 PM
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
0
Petur Subev
Telerik team
answered on 18 Feb 2015, 11:52 AM
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!
 
0
Bilal
Top achievements
Rank 2
answered on 18 Feb 2015, 02:51 PM
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


0
Bilal
Top achievements
Rank 2
answered on 18 Feb 2015, 03:25 PM
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

0
Petur Subev
Telerik team
answered on 20 Feb 2015, 11:52 AM
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!
 
Tags
Grid
Asked by
Bilal
Top achievements
Rank 2
Answers by
Bilal
Top achievements
Rank 2
Petur Subev
Telerik team
Share this question
or