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

DataSource hasChanges() fails because data items are missing isNew()

2 Answers 599 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 13 May 2013, 08:19 PM
I've got some code which checks if a page has unsaved changes which is using the hasChanges() method of the Kendo dataSource to detect changes made within a grid:
var changed = self.data("kendoGrid").dataSource.hasChanges();

However, for the grid on one page this is failing because the isNew() method is missing from the data items within the dataSource.  If I inspect the dataSource.data() items all of the items are present, but whereas the items on my other pages include a "dirty" field and an "isNew()" method the ones for this page do not.  As far as I can tell there are no substantial differences between the pages.  The one that works does have a couple of aggregates and a change event handler included in the dataSource which the failing one doesn't but I don't see how that would affect this.

Here is the div for the grid from the page that fails:
                <div id="CentersGrid" data-bind="kendoGrid: 
    {
        data: ReportingCenters, 
        widget: centersGrid, 
        dataSource: {
            batch: true, 
            sort: { field: 'Number', dir: 'asc' } ,
        }, 
        scrollable: false,
        pageable: { pageSize: 15, input: true, numeric: false },
        editable: true, 
        sortable: true, 
        navigatable: true,
        columns: [ 
            { field: 'id', hidden: true } ,
            { field: 'Number', width: '20%' } , 
            { field: 'Description', width: '60%' } ,
            { command: [ {name: 'destroy'} ] }
        ],
        toolbar: ['create'],
        dataBound: function(e) { 
            $('#CentersGrid tbody tr .k-grid-delete').each(function() {
                var currentItem = $('#CentersGrid').data('kendoGrid').dataItem($(this).closest('tr'));
                if (currentItem.CanDelete == false) { $(this).remove(); }
            }) 
        }
    }">

The items that seem to be missing from each data item are: dirty, defaults, fields and isNew().

2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 14 May 2013, 06:07 AM
Hi Brian,

In order to use DataSource editing features you should configure a model

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian
Top achievements
Rank 1
answered on 14 May 2013, 02:59 PM
Thanks, that does fix it.  I'm not sure why it works without an explicit model for my other page but I'll chalk that up to the mysteries of Knockout-Kendo integration.
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Brian
Top achievements
Rank 1
Share this question
or