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

hasChanges works incorrectly

5 Answers 314 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Neeraj
Top achievements
Rank 1
Veteran
Neeraj asked on 17 May 2019, 09:12 AM
I have used hasChanges() to detect dirty flag in dataSource. But it behaves in strange way when we have 1 row inside Grid and if i we delete that still hasChanges() return false. 
              I have created DOJO demo https://dojo.telerik.com/alOHiyOV  
      What is official solution

5 Answers, 1 is accepted

Sort by
0
Neeraj
Top achievements
Rank 1
Veteran
answered on 17 May 2019, 11:24 AM
this demo is using my data. there is some error occuring. 
0
Neeraj
Top achievements
Rank 1
Veteran
answered on 17 May 2019, 11:24 AM
this demo is using my data. there is some error occuring.    https://dojo.telerik.com/UjUyaWeC
0
Tsvetomir
Telerik team
answered on 20 May 2019, 02:37 PM
Hi Neeraj,

I have investigated the provided Dojo sample along clarifications on the scenario.

Generally, the hasChanges() method simply checks for any dirty flags, any new items or any destroyed items. It is worth mentioning that by "destroyed" items, I refer to the items that are pending to be destroyed. When the batch() property of the data source has been set, all the edited, created and destroyed items are sent with one request. So, when it is enabled and you delete a record it is marked as destroyed, however, it is still accessible but it is not available in the data of the data source. 

That is why, the hasChanges() method is mainly used with the "InCell" edit mode. When you are using any of the other edit modes, the records are directly modified or destroyed. There is no time for them to be marked as "dirty". 

I have modified the Dojo sample to be working with batch editing. You may now observe the fact that if a record is deleted, it is marked as dirty (hasChanges() method returns true). Only after you press the "Save changes" button, then the record would be actually deleted:

https://dojo.telerik.com/UqOlEraP

I hope you find those clarifications helpful. Let me know in case further assistance is required.


Kind regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Neeraj
Top achievements
Rank 1
Veteran
answered on 22 May 2019, 05:10 AM
I have  a scenario where , there are multiple MVVM grids , with seperate button on screen to open them in kendo window . Each grid has seperate datasource. values are dependent on each other .
       I have used inCell editing and When i close kendowindow i make Ajax call and compute values server side and in success i create new kendo DataSource and assign this created dataSource to old DataSource variable in Observable object
0
Tsvetomir
Telerik team
answered on 23 May 2019, 10:46 AM
Hi Neeraj,

When the "InCell" edit mode is enabled, this would configure the Kendo UI Grid for batch editing. However, the data source of the grid is a completely separate widget from the grid and you would have to set its batch property to "true" as well. Also, the autoSync has to be disabled (in case it is present). 

The fact that you would perform a new ajax call to the server-side, it depends whether the grids are going to be destroyed when the request has been finished. For instance, if the widgets are not destroyed, even though you have set a new data source, it would not take place because the initialization/binding scripts will not be executed. So, in this case the better approach would be to make use of the setDataSource() method. 

As you have stated the scenario you are willing to achieve, do you encounter any issues with any of its states? If so, can you specify which ones? 


Kind regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Data Source
Asked by
Neeraj
Top achievements
Rank 1
Veteran
Answers by
Neeraj
Top achievements
Rank 1
Veteran
Tsvetomir
Telerik team
Share this question
or