<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
    <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.html5.js"></script>
    <link href="https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css" rel="stylesheet" type="text/css" />
    <script src="https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.colVis.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
    </table>
    </div>
  </body>
</html>
 
body {
  font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
  margin: 0;
  padding: 0;
  color: #333;
  background-color: #fff;
}
 
$(document).ready(function() {
  var table = $('#example').DataTable({
      dom: 'Bfrtip',
    paging: true,
      "ajax": {
        "url": "ajax/objects_root_array.txt",
        "dataSrc": ""
      },
      "columns": [
        { "data": "name" },
        { "data": "position" },
        { "data": "office" },
        { "data": "extn" },
        { "data": "start_date" },
        { "data": "salary" }
      ],
      "createdRow": function(row, data, index) {
        if (data.office == "London") {
          $('td:eq(2)', row).css('background-color', 'Red');
        } else if (data.office == "New York") {
          $('td:eq(2)', row).css('background-color', 'Green');
        }
      },
    buttons: [{
      extend: 'excelHtml5',
      customize: function ( xlsx ) {
        var sheet = xlsx.xl.worksheets['sheet1.xml'];
        
        var count = 0;
        var skippedHeader = false;
        $('row c[r^="C"]', sheet).each( function () {
          if (skippedHeader) {
//             var colour = $('tbody tr:eq('+parseInt(count)+') td:eq(2)').css('background-color');
            var colour = $(table.cell(':eq('+count+')',2).node()).css('background-color');            
            
            if (colour === 'rgb(255, 0, 0)' || colour === 'red') {
              $(this).attr( 's', '35' );
            }
            else if (colour === 'rgb(0, 128, 0)' || colour === 'green') {
              $(this).attr( 's', '40' );
            }
            count++;
          }
          else {
            skippedHeader = true;
          }
        });
      }
    }]
  });
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers