How to replace Pass or Fail value with Green Check Mark or Red X?
How to replace Pass or Fail value with Green Check Mark or Red X?
ColdFlow
Posts: 6Questions: 3Answers: 0
As the question has stated above, I am trying to write a code that will change all the outcomes of Pass to a Green Check Mark and all Fail outcomes to a Red X?
Below is my code:
columns: [
{ data: "datetime" },
{ data: "forklift" },
{ data: "driver" },
{ data: "shift"},
{ data: "inspection"},
{ data: "status",
render: function(data,type){
if (type === 'display'){
if(data[0] = 'pass'){
document.write("✔");
} else if (data[0] = 'fail'){
document.write("×");
}
return data;
}
return data;
}
},
{ data: "completed"},
],
Currently all it shows me is a blank page with nothing but ✔ at the top. How can I fix this where it will display inside my data table?
This question has accepted answers - jump to:
Answers
You probably don't want to use
document.write("✔");
as that I think is overwriting your page.Take a look at this example of data rendering with
columns.render
. Instead ofdocument.write("✔");
usereturn "✔";
.Also the data for the column is your
status
object. If its an array thendata[0]
will work if you are interested in only the first array element. Otherwise, in your if statements usedata
to to check the value ofstatus
.Kevin
Thanks that actually fixed my issue, now I just need to figure out how to change the color of them. @kthorngren
You can use
rowCallback
if the data can change orcreatedRow
if the data is static, like this example.Also the data for the column is your
status
object. If its an array thendata[0]
will work if you are interested in only the first array element. Otherwise, in your if statements usedata
to to check the value ofstatus
.Kevin
@kthorngren Okay, now this issue I am having is that if it is fail it still has a check mark beside it. Any thing I can do to fix that?
I noticed another problem:
In addition to my comment about
data[0]
you have=
. This is an assignment operator not a comparison. Use either==
or===
. See this doc for details.In order to help we will need to see an example of your data. Please provide a link to your page or build a simple test case showing the issues so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
@kthorngren I used
===
and that fixed the issue.