Conditionally Change Style of Column/Row/Field
Conditionally Change Style of Column/Row/Field
debug - https://debug.datatables.net/ififum
I am sure this has been asked, I just can't seem to find an answer. I have a Column called "Ansible Role." The returned valued from the database will either be "Completed", "In Progress", "Incomplete", or "NULL". I would like to style the value differently for each of them - say green for completed, yellow for In Progress, red for Incomplete, etc. How would I go about doing that?
What If I wanted to color the entire row for "Completed" green, etc. ? What if I wanted to color the entire row green, but not display the column?
I definitely want to do more than just color some words or rows, but I thought this was the simplest way to get to a starting point for other use cases.
thanks
Answers
There are two options I know of that may help:
Row Created Callback:
https://datatables.net/examples/advanced_init/row_callback.html
Row Callback:
https://datatables.net/reference/option/rowCallback
Kevin
Just to add to what Kevin has rightly said:
Use
columns.createdCell
orcreatedRow
if the data is static and won't change after the cell / row has changed.Alternatively, use
rowCallback
if the data might change since that is executed every time the row is drawn on screen.Allan