Enable button only if row is selected and a column has a defined value
Enable button only if row is selected and a column has a defined value
Hello,
i'm using datatables editor with the buttons 'new', 'edit' and 'delete'. The button 'new' is enabled all the time and the buttons 'edit' and 'delete' are only enabled if a row is selected. This all works fine.
My problem:
I have the column 'active' in my table. It contains the value 0 or 1, which represent the status 'not active' and 'active'. Now i want to extend the function of the 'delete'-button, that it will only be enable if a row is selected AND the value in the column 'active' is 0. If the 'active'-value is 1, the 'delete'-button can't be enabled.
How can i do this?
Thanks a lot for your help.
This question has an accepted answers - jump to answer
Answers
Here is an example.
These are my buttons. You need to give the remove button a name to refer to.
And here are the select and deselect event handlers.
Just adjust it to your situation e.g data.yourTable.active == 1 or something.
Why "deselect":
If you allow multi select and someone selects multiple records of which some must not be deletable you must also check the condition on deselect otherwise the user will be able also to delete forbidden records on the first deselect.
Works!
Thanks a lot