columns.render() - possible using if statements?
columns.render() - possible using if statements?
There are three different images I would like to display in my column.render() depending on data output. If I am using only two images I can get the code to work using: return (if true) ? display this : else display this. However, I am not able to get the code to work when working with more than two conditions using if statements. This is my faulty code:
"data": "ErrorCount",
"render": function (data, type, row) {
if (data === "01/01/9999 00:00:00") {
data = '<i class="far fa-dot-circle" style="color:yellow" /*aria-hidden="true"*/></i>';
} else if (data === 0) {
data = '<i class="far fa-dot-circle" style="color:green" /*aria-hidden="true"*/></i>';
} else {
data = '<i class="far fa-dot-circle" style="color:red" /*aria-hidden="true"*/></i>';
}
What is the correct way of doing this with more than two conditions? Thank you.
This question has an accepted answers - jump to answer
Answers
Thank you, seems really obvious now that you mention it
You are welcome. By the way, I changed the comparison operator from "===" to "==" because as far as I am aware Data Tables returns numbers as strings (if you use Editor on your server). With "==" it should work either way.
Thanks for the info. I will bear that in mind.
I use "switch" a lot for rendering Data Table columns. Switch compares in strict mode like "===". This example is about a boolean variable that is saved in a TINYINT field in my MySQL database. Editor returns it as a string. Hence I need to use this in my "switch" for rendering:
Without the ' it doesn't work ...