beforeEdit
Fired when the user tries to edit or create a data item, before the editor is created. Can be used to preventing editing according to any custom logic.
The event handler function context (available via the this
keyword) will be set to the widget instance.
Event Data
e.model kendo.data.Model
The data item which is going to be edited. Use its isNew method to check if the data item is new (created) or not (edited).
e.sender kendo.ui.Grid
The widget instance which fired the event.
Example - subscribe to the "beforeEdit" event during initialization
<div id="grid"></div>
<script>
$("#grid").kendoGrid({
columns: [
{ field: "id" },
{ field: "name" },
{ field: "age" },
{ command: "edit" }
],
dataSource: {
data: [
{ id: 1, name: "Jane Doe", age: 30 },
{ id: 2, name: "John Doe", age: 33 }
],
schema: {
model: {
id: "id",
fields: {
"id": { type: "number" }
}
}
}
},
editable: "popup",
toolbar:["create"],
beforeEdit: function(e) {
if (!e.model.isNew()) {
e.preventDefault();
}
}
});
</script>
Example - subscribe to the "beforeEdit" after initialization
<div id="grid"></div>
<script>
function grid_beforeEdit(e) {
if (!e.model.isNew()) {
e.preventDefault();
}
}
$("#grid").kendoGrid({
columns: [
{ field: "id" },
{ field: "name" },
{ field: "age" },
{ command: "edit" }
],
dataSource: {
data: [
{ id: 1, name: "Jane Doe", age: 30 },
{ id: 2, name: "John Doe", age: 33 }
],
schema: {
model: {
id: "id",
fields: {
"id": { type: "number" }
}
}
}
},
editable: "popup",
toolbar:["create"],
beforeEdit: function(e) {
if (!e.model.isNew()) {
e.preventDefault();
}
}
});
var grid = $("#grid").data("kendoGrid");
grid.bind("beforeEdit", grid_beforeEdit);
</script>