ASP.NETCore KendoGrid Correct way to disable delete for specific rows?
I have a use case where I need to disable the deletion of rows that still have children to maintain referential integrity of the database. Instead of having the user hit DELETE and catch the error, I need to prevent the user from attempting to perform an invalid action. I can attempt to hide the DELETE button in the onDataBound() or the onDataBinding() events but the results are poor and inconsistent. When it works, it only works when the page is first loaded. If the user performs an in-line edit on any row, the delete button unhides. Other interactions with the page also unhide the DELETE button. I have found several posts claiming that the "k-grid-delete" class can't be hidden.
Instead of hiding the button outright, ideally I'd like to be able to still have the button visible, but in a disabled state.
Is there a solution?
function onDataBound(e) {
var grid = $("#grid").data("kendoGrid");
var rows = grid.tbody.children();
rows.each(function (e) {
var dataItem = grid.dataItem(this);
if (dataItem.ChildrenCount > 0) {
var row = $("[data-uid=" + dataItem.uid + "]");
var deleteButton = row.find("k-grid-delete");
deleteButton.hide();
}
});
}