Does kendo.data.dataSource store the old value somewhere?
Asked Answered
S

2

5

Lets say that you have a kendo.data.DataSource. and you modify a row. and the row has become dirty. and now you want to compare if a specific column was changed before you save.

Does kendo.data.DataSource store the old value locally somewhere?

I suspect it does since it seems that you can call .cancelChanges() and .cancelRow() however i cant seem to find it.

I also suspect that you are not supposed to use it.

Sturdivant answered 12/11, 2014 at 16:51 Comment(2)
Are you connecting the datasource to a widget like the grid control? If so, there are events in the widget that let you listen for changes.Heid
yes i know however i was thinking i could avoid listening to change events if the old value is already stored somewhere.Sturdivant
A
8

You are correct that you are not suppose to use this, but it is located in the Data Source.

The currently displayed data/dirty data to be submitted is stored in dataSource._data The last saved value/non-dirty data is stored in dataSource._pristineData

The dirty flag is also stored in _data.


In general you don't want to be messing with any variable that begins with the _. You can alternatively save out the current data with the get/set function kendo provides. The dataSource.data() function. Update it with the same function dataSource.data(myNewData)
Amalgamate answered 12/11, 2014 at 17:4 Comment(1)
ah. i did notice the _pristineData before, however when i looked, it seemed to contain the same data.Sturdivant
A
0

Ideally Kendo will provide such feature. However, the next clean solution I found was by playing with the onfocus and onblure events as following: onfocus: you store original value onblure: you do the logic and put back original if needed.

Best of luck and I hope I helped someone :) If so then cheers my friend :)

Aphyllous answered 3/7, 2018 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.