Christian Gollhardt
Christian Gollhardt

Reputation: 17034

Kendo Grid hasChanges, how can I handle readonly grids?

I currently want to iterate about each Kendo Grid, and warn the user, if there are pending changes. For this I use the method hasChanges() (I use batch editing):

$(".k-grid").each(function () {
    if ($(this).data('kendoGrid').dataSource.hasChanges()) {
        //Warn user about pending changes
    }
}

This works fine.


However, I have some readonly Grids which should return always false. The Problem is, they always return true (which is impossible, because they can not be edited).

I investigated the differences, and the problem is, that my readonly grids have not the Model ID in the AjaxDataSourceBuilder<TModel> defined:

.Model(model => model.Id(entity => entity.SomeId)

They must be defined to get false from hasChanges() on a readonly grid.


My Question:

  1. Can I make hasChanges() work correctly without setting the Model ID each grid? It seems like a little overhead to me.

alternate

  1. Can I check at runtime via JS, if the grid is editable?

Upvotes: 1

Views: 496

Answers (1)

Jarno Lahtinen
Jarno Lahtinen

Reputation: 1703

Kendo Grid has method getOptions() and there is property editable.

var grid = $("#grid").data("kendoGrid");
var options = grid.getOptions();
console.log(options.editable); //outputs true or false

I think schema.model.id is necessary because it's key property for CRUD operations. So you need it for hasChanges() to work properly.

Upvotes: 1

Related Questions