Change colour of row based on column value
Change colour of row based on column value
Miko12359
Posts: 7Questions: 4Answers: 0
Hello,one of the columns in my table contains a due date, i would like to change the colour of the row to red if the due date has already been reached (due date is in the past), if it has not been reached then the colour should change to green.
I am using php to load the data from the tables if that helps.
Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Use one of the following to change the color based on the cell data:
createdRow
rowCallback
columns.createdCell
Kevin
Hi @Miko12359 ,
There are several threads in the forum discussing this, such as this one here.
Cheers,
Colin
so i have tried this, it only works if the current date is an exact match, for example the current date is 13-Nov-2018, so only that row is coloured which is fine, but if i try to change:
to
the it doesnt factor the month, it just checks to see if the day is less than current day (checks all rows to see if date is less that 13) it disregards the month, any way to fix this?
This isn't valid Javascript syntax. You either need to use
==
or===
.Without a test case showing your actual data its hard to say. Maybe you need to convert the
data[6]
value to a date object to matchformattedDate
, for example:var colDate = new Date(aData[6]);
.Please post a simple test case representing your data if you need further help.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin