<!DOCTYPE html>
<html>
  <head>
<meta name="description" content="Export with customisable file name" />
    <script src="https://code.jquery.com/jquery-1.11.3.min.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" cellspacing="0" width="100%">
  <thead>
    <tr>
      <th>Name</th>
      <th>Date</th>
      <th>Description</th>
      <th>Index</th>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <th>Name</th>
      <th>Date</th>
      <th>Description</th>
      <th>Index</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 data = [
    {
      name: 'Test 1',
      date: '06/15/2018',
      description: 'This is test 1',
      results: [
        {
          result: 'passed',
          note: 'note 1'
        }
      ]
    },
    {
      name: 'Test 2',
      date: '10/31/2018',
      description: 'This is test 2',
      results: [
        {
          result: 'failed 1',
          note: 'note 2a'
        },
        {
          result: 'failed 2',
          note: 'note 2b'
        }
      ]
    },
    {
      name: 'Test 3',
      date: '03/05/2018',
      description: 'This is test 3',
      results: [
        {
          result: 'passed with exception',
          note: 'note 3'
        }
      ]
    },
  ];
  var table = $('#example').DataTable({
    data: data,
    columns: [
      {
        data: 'name'
      },
      {
        data: 'date'
      },
      {
        data: 'description'
      },
      {
        data: null,
        visible: false,
        render: function (data, type, row, meta) {
          return meta.row;
        }
      }
    ],
    dom: 'Bfrtip',
    buttons: [{
      extend: 'excelHtml5',
      customize: function( xlsx ) {
        var table = $('#example').DataTable();
        
        // Get number of columns to remove last hidden index column.
        var thead = table.table().header();
        
        var titles = [];
        
        $(thead).find('th').each(function(){
          titles.push($(this).text());
        });
        
        console.log(titles);
      },
    }]
  });
});
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers