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

Order of new row problem after save and then cancelChanges

3 Answers 13 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Salim
Top achievements
Rank 1
Salim asked on 07 Dec 2016, 09:03 AM

Check the following scenario:

1. Go to the following example: http://dojo.telerik.com/uVInI

2. Add new row, enter its data, and click "Save"

3. Click "Cancel"

 

The new row which was the first one is now the last one. The "cancelChanges" should not affect the order of the new row

3 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 09 Dec 2016, 09:11 AM
Hello Salim,

Thank you very much for the provided runnable demo. 

This behaviour is expected if you follow the logic in the cancelChanges()  method you will see that the data is assigned back to the _pristineData:

https://github.com/telerik/kendo-ui-core/blob/master/src/kendo.data.js#L2841

In the depicted scenario, there are no changes and the _pristineData holds the items sorted with the newest item at the end of the data source data array. When a subsequent read is requested, the server responds with the dataItems ordered by their creation in descending order. 

There are several options to prevent this and in your scenario, the easiest one is to check for changes. If there are no changes, do not call the cancelChanges()  method:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-hasChanges

For your convenience, I have updated the demo at:

http://dojo.telerik.com/uVInI/2

Regards,
Alex Hajigeorgieva
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
0
Salim
Top achievements
Rank 1
answered on 09 Dec 2016, 09:15 AM
This is a wrong behavior since you are providing an option for the new row to be on top or at the bottom. So, the _pristineData should set the priority of the new based on the position of the new row
0
Alex Hajigeorgieva
Telerik team
answered on 12 Dec 2016, 04:17 PM
Hi Salim,

You seem to have a valid point regarding the expected behaviour when cancelling changes. However, please note that to ensure that the data is sorted, you should add a sort configuration or implement your own method of comparison:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-sort.compare

For your convenience, I have updated the demo to compare by ProductIDs:

http://dojo.telerik.com/UGOko/2

I hope this helps.

Regards,
Alex Hajigeorgieva
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
Tags
Grid
Asked by
Salim
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Salim
Top achievements
Rank 1
Share this question
or