JSFiddle - React, Tailwind, and code Playground

by haba713

HTML

<script src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<table id="sample">
  <thead>
    <tr>
      <th>First name</th>
      <th>Surname</th>
      <th>Age</th>
      <th>Eye color</th>
      <th>Gender</th>
      <th>Company</th>
      <th>Email</th>
      <th>Phone</th>
    </tr>
  </thead>
</table>

JavaScript

var sample;

$(document).ready(function() {
  sample = $('#sample').DataTable({
    'ajax': 'https://api.myjson.com/bins/36fgj',
    'pageLength': 25,
    'columns': [{
      data: 'firstName'
    }, {
      data: 'surname'
    }, {
      data: 'age'
    }, {
      data: 'eyeColor'
    }, {
      data: 'gender'
    }, {
      data: 'company'
    }, {
      data: 'email'
    }, {
      data: 'phone'
    }],
    'dom': '<"top"flp>rt<"bottom"i><"clear">'
  });
  window.setInterval(function() {
    var currentPage = sample.page.info()['page'];
    sample.ajax.reload(function() {
      sample.page(currentPage).draw('page');
    });
  }, 5000);

});