Reputation: 1597
I have a kendo grid with inline editing. I want to be able to make one of the cells in the row editable if another cell in the row is checked. If it's not checked then I want the cell to be read-only.
My columns look like this:
columns: [
{ field: "Title" }, // string
{ field: "Body" }, // string
{ field: "IsCalculated", template: "#= IsCalculated ? 'Yes' : 'No' #" }, // boolean
{ field: "Expression" } // string
]
If Calculated
is checked then I want Expression
to be editable, otherwise, I want it to be read-only.
I have looked at the configuration docs for the kendo grid and I have experimented with the columns.editable
function but as explained in the docs: "The JavaScript function executed when the cell/row is about to be opened for edit. The result returned will determine whether an editor for the column will be created."
I can use this function to determine whether the cell should be editable or read-only before it's opened but I want to be able to change it while the cell is open for editing and the Calculated
checkbox is checked or unchecked.
Upvotes: 0
Views: 2779
Reputation: 21465
Try preventing the edit
event with cancelRow()
:
edit: function(e) {
if (!e.model.IsCalculated &&
$(e.container).find('input').attr("name") == "Expression")
{
this.cancelRow();
}
}
UPDATE - Better condition:
if (!e.model.IsCalculated &&
$(e.container).find('input[name="Expression"]').length) // <---
Upvotes: 1