Toggle a class name to a column in DataTable
Toggle a class name to a column in DataTable
Francesco Di Sciascio
Posts: 8Questions: 3Answers: 0
Hi everyone,
I have a datatable initialized with a className in this way:
columnDefs: [{className: "editable", targets: [COLUMN_NUMBER]}]
Is there a way to add / remove the same className when something changes in my view?
I need to have the column 'editable' only in certain cases, and not editable in others.
Thanks for your help
This question has an accepted answers - jump to answer
Answers
Try
cells().nodes()
. You will probably want arow-selector
ofnull
and acell-selector
of the column. Something like this:Kevin
Kevin,
your solution seems not working correctly.
No class is added to cells of the COLUMN_NUMBER column
Kevin,
Maybe a .to$() is missing, but the fact is that, when an event occurs, I do not reinitialize the table, but I only do the following:
I need something that allows me to toggle the editability of the cells of COLUMN_NUMBER, because with a toggleClass or an addClass after the clear nothing changes
That code snippet works here:
http://live.datatables.net/joqagaxu/1/edit
Please provide a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
You are right, your sample works.
It's hard to put out a snippet for my project because of the complexity, but I suppose it could depend on how I retrieve the Datatable.
To solve it I've used the following:
and then I have called a new initialization of the table. I need to clear the table because it owns total given by other table selections (like an invoice).
Thanks for your help!