data source cancelling changes

1 Answer 141 Views
Data Source Grid
Nikita
Top achievements
Rank 2
Iron
Nikita asked on 25 Aug 2021, 04:54 PM
I have a grid bound to an AJAX dataSource configured to update records on the server. some of the data item properties are bound to editable fields in the grid via MVVM binding and the changes are synced using data source transport configuration. Other data item properties are also bound to the grid column templates but are updated explicitly via an implementation separate from the dataSource. For those properties I make sure the state of the dirty bit on the observable is unchanged when the property is update so the dataSource does not track it. However, calling cancelChanges() on the dataSource resets the state on these properties. Is there a way to cancel changes on some of the data item properties while keeping changes on other ones?

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 30 Aug 2021, 10:13 AM

Hello Nikita,

I recommend updating the data item properties using the pushUpdate() method. This way the specified data items will be updated without marking them as "dirty". The data source will not sync data items appended via pushUpdate:

Let me know if you have any questions.

Regards,
Nikolay
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Nikita
Top achievements
Rank 2
Iron
commented on 30 Aug 2021, 04:42 PM

Hello Nikolay, thank you for you response. This sounds like exactly what I need, however when I tried this I got an error message: "Uncaught ReferenceError: (property x) is not defined". The property named in the error message is not the one I was trying to update with pushUpdate, but it's one of the properties of the data model and it's bound to a grid column template using MVVM bindings. Do you have any suggestions for this?

Nikita
Top achievements
Rank 2
Iron
commented on 31 Aug 2021, 04:13 PM

I think I see what I did wrong there. After correcting it the error is not there anymore but another problem is that the grid cell bound to updated property is not refreshed. This is the code I'm using:

var dataSource = $('#gridElement').data('kendoGrid').dataSource;

var dataItem = dataSource.get(id);

dataItem.PropA = newValue;

dataSource.pushUpdate(dataItem);

Nikolay
Telerik team
commented on 02 Sep 2021, 12:45 PM

Hi Nikita,

You can check the approach in the following article to Refresh Particular Rows without Rendering the Entire Grid:

Regards,

Nikolay

Tags
Data Source Grid
Asked by
Nikita
Top achievements
Rank 2
Iron
Answers by
Nikolay
Telerik team
Share this question
or