Allow/Disallow table row selection based on external variable
Allow/Disallow table row selection based on external variable
brendons
Posts: 39Questions: 14Answers: 1
Hi again. I am trying to prevent selection of rows in my table based on user role.
So far I've tried as below (plus others) but with no success:
if (userRole === 'admin') {
...
//table.select().enable(); //gives error: is not a function
//table.rows().select().enable(); //same error as above
//tried moving the select from the table definition to here but it doesn't work
table.select ({
style: 'os',
selector: 'td'
});
} else {
...
//table.select().disable(); //error: is not a function
}
Please advise how to achieve this.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Use
select.style()
to enable / disable click row selection. Useapi
as the value to disallow selection by click.Allan
Thanks Allan.
did the trick.
I would never have thought of 'api' as an option.
Back when I first designed that I did think about having an "off" option - but then I figured, why would you need that? You'd just not call the select methods. So "api" is more or less the same as off from the user's perspective, and if you don't want rows selected, don't select them.
I could alias "off" to that, but then it might get confusing if you did run a select method and a row was selected!
Either way, good to hear it is working for you.
Allan