AJAX function conditional formatting cell (highlight)

Viewed 75

My goal is to highlight the "true" and false "cells.

Ideally, I would like to replace these values ​​with: _ red circle for "true" _ green circle for "false"

If it is not possible to make circles, filling in the background of the cell in color will suffice.

table1.csv :

xxx,xxx,xxx,xxx,10/13/2021,15/13/2021,FAUX
xxx,xxx,xxx,xxx,11/30/2020,2/1/2021,VRAI

My script which calls the csv file:

$('#load_en_cours').init(function(){
  $.ajax({
   url:"table1.csv",
   dataType:"text",
   success:function(data)
   {
    var employee_data = data.split(/\r?\n|\r/);
    var table_data = '<table class="table table-bordered border-dark"  data-search="true" style="background-color:#F5F5F5">';
    for(var count = 0; count<employee_data.length; count++)
    {
     var cell_data = employee_data[count].split(",");
     table_data += '<tr>';
     for(var cell_count=0; cell_count<cell_data.length; cell_count++)
     {
      if(count === 0)
      {
       table_data += '<th class="table-primary">'+cell_data[cell_count]+'</th>'; 
      // }
      // else
      // {
           
          // if(cell_data[cell_count] .includes("VRAI")){
                // var ret = cell_data[cell_count].replace('VRAI','');
                // if (ret == ""){
                    // table_data += '<td>'+ret+'</td>'
                // }else{
                  // table_data += '<td data-color="red"><span>'+ret+'</span></td>';
                // }
          // }else if(cell_data[cell_count] .includes("FAUX")){
                // var ret = cell_data[cell_count].replace('FAUX','');
                // if (ret == ""){
                  // table_data += '<td>'+ret+'</td>';
                // }else if(ret == " "){
                  // table_data += '<td>'+ret+'</td>';
                // }else{
                  // table_data += '<td data-color="green"><span>'+ret+'</span></td>';
                // }
      // 
      }
      else
      { 
       table_data += '<td>'+cell_data[cell_count]+'</td>';
      }
     }
     table_data += '</tr>';
    }
    table_data += '</table>';
    $('#table1_table').html(table_data);
   }
  });
 });
0 Answers
Related