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

What replaced haschanges()

14 Answers 335 Views
Grid
This is a migrated thread and some comments may be shown as answers.
carlg
Top achievements
Rank 1
carlg asked on 28 Sep 2012, 05:50 PM
In the old MVC extensions, I tested if a grid had changes by using the following

grid.haschanges();


According to the transition guide here:
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/migration/widgets/grid


haschanges has been removed. 

So now with Kendo, how do I tell if the grid has changes?

14 Answers, 1 is accepted

Sort by
0
Iliana Nikolova
Telerik team
answered on 01 Oct 2012, 06:34 PM
Hi Carl,

Yes, you are right - haschanges() method is not available in Kendo UI Grid. In order to achieve the needed functionality you could use the 'dirty' property of the DataSource's model. Generally speaking all DataSource items have dirty flag which indicates whether the item has been modified by the user or not.  

Regards,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
carlg
Top achievements
Rank 1
answered on 01 Oct 2012, 06:49 PM
What about a delete since there is no record in the model for a deleted record?
0
Iliana Nikolova
Telerik team
answered on 02 Oct 2012, 04:40 PM
Hi Carl,

The destroyed items are stored in the  _destroyed property of the DataSource. Please note that this property is intended for internal usage only, however it can be used to check if there are deleted items or not. For example :
grid.dataSource._destroyed.length

Kind regards,

Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Muthu
Top achievements
Rank 1
answered on 04 Oct 2012, 04:38 AM
can you send me the example of using dirty property for the grid. i have to check in requeststart event. thanks
0
Sampath
Top achievements
Rank 1
answered on 18 Oct 2012, 09:51 AM
function doesDataSourceHaveChanges(ds)
{
    var dirty = false;

    $.each(ds._data, function ()
    {
        if (this.dirty == true)
        {
            dirty = true;
        }
    });

    if (ds._destroyed.length > 0)
    {
       dirty = true;
    }

    return dirty;
}
0
carlg
Top achievements
Rank 1
answered on 18 Oct 2012, 11:19 AM
I actually wrote that function and posted it on another website.

lol.


0
Muthu
Top achievements
Rank 1
answered on 19 Oct 2012, 03:22 AM
it works. i copied from other website that carlg posted. Thanks to all
0
Jerry
Top achievements
Rank 1
answered on 31 Oct 2012, 03:49 PM
I tried looking for the "this.dirty" flag on the dataSource._data objects but there is no dirty property.  Are there any dependencies in how the DataSource definition was created that would prevent this flag from appearing on these objects?
0
Muthu
Top achievements
Rank 1
answered on 05 Nov 2012, 05:00 AM
Try to follow this way
var grid = $('#Grid').data('kendoGrid');
if(doesDataSourceHaveChanges(grid.dataSource))
{
//
}
0
Nani
Top achievements
Rank 1
answered on 11 Apr 2017, 08:47 PM

HI,

I am using Kendo version 2013. I am also unable to find the dirty flag in the . I tried to check as Muthu suggested. but no luck. Does () support 2013 version?

I have a kendo grid. I want to set a flag if there are any changes in the cell level. Please help me out!!

Thanks

0
Stefan
Telerik team
answered on 17 Apr 2017, 07:13 AM
Hello Nani,

The Kendo UI Grid currently supports a hasChanges method, which can be used to check if there are any changes:

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

Also, please check how to set the dirty flag of a data item:

http://www.telerik.com/forums/manually-set-grid-row-as-dirty

Additionally, please have in mind that the posted approach here is custom and it is not officially supported.

Still, if an assistance is needed, with the implementation, please provide a fully runnable example and I will gladly assist.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Neeraj
Top achievements
Rank 1
Veteran
answered on 17 May 2019, 08:30 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. 
0
Neeraj
Top achievements
Rank 1
Veteran
answered on 17 May 2019, 08:58 AM
I have created demo https://dojo.telerik.com/alOHiyOV  
      What is official solution
0
Viktor Tachev
Telerik team
answered on 20 May 2019, 11:16 AM
Hello Neeraj,

I have examined the example and noticed that an object with the same signature as the dataItem was passed to the remove method. However, it was not reference to a dataItem in the DataSource and thus, the data is not altered. Check out this example as reference.

In order to remove the dataItem you need to get reference of it and then pass that to the remove method. Like in the example below.



Regards,
Viktor Tachev
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
Grid
Asked by
carlg
Top achievements
Rank 1
Answers by
Iliana Nikolova
Telerik team
carlg
Top achievements
Rank 1
Muthu
Top achievements
Rank 1
Sampath
Top achievements
Rank 1
Jerry
Top achievements
Rank 1
Nani
Top achievements
Rank 1
Stefan
Telerik team
Neeraj
Top achievements
Rank 1
Veteran
Viktor Tachev
Telerik team
Share this question
or