I am instantiating a custom command inside a grid.
If a certain condition is met, the command button (.k-grid-AddNewThing) is appended with the ("k-state-disabled") style class to disable the button.
This works great on load when wired up to the .DataBound event.
However, when the Edit button is clicked and subsequently the Cancel button is clicked, the ("k-state-disabled") style class is removed and reverted to the default.
I have tried to wire up the .Cancel event to re-apply the ("k-state-disabled") style class, but it seems that the .Cancel event is ansyncly firing the default action along with my custom function.
There are two paths that i figure.
1. Client Template w/Conditional: this would be favorable, since i can remove the javascript function completely.
2. Somehow implement a callback/promise in the default .Cancel event.
I don't know if any of these are possible though.
Any ideas?
Grid Helper Event Method
.Events(e => { e.DataBound(
"disableCustomCommand"
); e.Cancel(
"disableCustomCommand"
); })
JS function:
function
disableCustomCommand(e) {
var
grid =
this
;
grid.tbody.find(
"tr[role='row']"
).each(
function
() {
var
model = grid.dataItem(
this
);
if
(model.isVerified ==
true
) {
$(
this
).find(
".k-grid-AddNewThing"
).addClass(
"k-state-disabled"
).text(
"NewThing Exists"
);
}
});
}
//This works perfectly on the .DataBound event, but does not process properly when called by the .Cancel event and reverts to default style class, giving the impression that the .find() method did not find the element or the .addClass() method did not apply the style.