I have a bootstrap-table which loads its data from a .json file. Everything works nicely but I am now trying to add a data-formatter="winLOSSFormatter"
to one column and can't make that work.
Basically I am looking for it to be a simple if else
statement that looks at the value and changes the color of the text for that field based on the value.
For example if the value includes the word "win," the text would be green.; the word "loss," the text would be red. Anything else the text would be standard black.
I believe this should be fairly simple to achieve with something along the lines of the script below but I can't seem to make it work.
Thanks!
function winLOSSFormatter(value) {
if (value.indexof ('Win') > -1) {
color = 'green';
} else if (value.indexof('Loss') > -1 {
'red';
} else {
color = 'black';
};
return '<div style="color: ' + color + '">' + value.substring(1) + '</div>';
}