jquery datatable background text color code example

Example 1: jquery datatable text color

$(document).ready( function () {
  var table = $('#example').DataTable({
    columnDefs: [{targets: [0, 1, 2, 3, 4, 5],
                    render: function ( data, type, row ) {
                      var color = 'green';
                      if (data == "example") {
                        color = 'green';
                      } 
                      if (data > 10) {
                        color = 'blue';
                      }
                      if (data < 60) {
                        color = 'red';
                      }
                      return '<span style="color:' + color + '">' + data + '</span>';
                    }
               }]
  });
} );

Example 2: jquery datatable background text color

$(document).ready( function () {
  var table = $('#example_table').DataTable({
    columns: [
      {
        data: "example_data",
        render: function (data) {
          if (data == true) {
            return '<h5><span class="badge badge-success">Example</span></h5>';
          } else {
            return '<h5><span class="badge badge-danger">Another Example</span></h5>';
          }
        },
      },
    ]
  });
} );

Tags:

Misc Example