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

Datasource fields that have been recalculated revert to 0 when poup edit is cancelled

2 Answers 56 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Lars Lykke
Top achievements
Rank 1
Lars Lykke asked on 08 Apr 2013, 01:10 PM
If a DataSource is created and some values are then recalculated, cancelling editor reverts to values before recalculation.

Example here:
http://jsfiddle.net/uBfQ3/17/

1. Observe discount values set
2. Observe disount values recalculated
3. Hit edit
4. Hit cancel
5. Observe values reverting to values before recalculation

What do I do to make values revert to calculated values and not 0?

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 09 Apr 2013, 07:19 AM
Hello Lars,

 
Here is the code that you need to modify in order to achieve your scenario:

$.each(dataSource.data(), function (i, row) {
 //row.Discount = row.Discount + 1;
 row.set("Discount", row.Discount + 1); //<-- model.set should be used so the Model is marked as dirty
                 
 //The line bellow will force the DataSource to accept the above change
 // and when changes are cancelled this value will be the default
 dataSource.sync();
});
//$('#grid').data("kendoGrid").refresh(); <-- this line is not necessary as the above DataSource.sync will refresh the Grid

Two things to notice:
 - Model.set should be used in order to marked the model as changed/dirty
 - DataSource.sync will accept the changes and will use those new values as current/default. Thus when the user cancel the changes in the edit form the values will be reverted to this last `accepted` value. Other side effect from the sync is that it will cause refresh to all data-bound widgets that are using it(the Grid in this case).

And here the link to update fiddle: http://jsfiddle.net/uBfQ3/18/

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Lars Lykke
Top achievements
Rank 1
answered on 09 Apr 2013, 09:19 AM
Thank you.
Tags
Data Source
Asked by
Lars Lykke
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Lars Lykke
Top achievements
Rank 1
Share this question
or