JSFiddle - React, Tailwind, and code Playground

by sespler2

HTML

<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>

    <link href="https://nightly.datatables.net/css/dataTables.dataTables.css" rel="stylesheet" type="text/css" />
    <script src="https://nightly.datatables.net/js/dataTables.js"></script>
    <link href="https://cdn.datatables.net/colreorder/2.1.0/css/colReorder.dataTables.min.css" rel="stylesheet" type="text/css" />
    <script src="https://cdn.datatables.net/colreorder/2.1.0/js/dataTables.colReorder.min.js"></script>
    <link href="https://cdn.datatables.net/responsive/3.0.4/css/responsive.dataTables.min.css" rel="stylesheet" type="text/css" />
    <script src="https://cdn.datatables.net/responsive/3.0.4/js/dataTables.responsive.min.js"></script>
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <table id="example" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
          </tr>
        </thead>

        <tfoot>
          <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
          </tr>
        </tfoot>

      </table>
    </div>
  </body>
</html>

JavaScript

var table = $('#example').DataTable({
  stateSave: true,
  colReorder: true,
  responsive: true,
  ajax: function(data, callback, settings) {
      // Simulate server-side response
      const mockData = {
        data: [
          ["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
          ["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
          ["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"]
        ]
      };
      // Simulate delay like a real AJAX call
      setTimeout(() => {
        callback(mockData);
      }, 1500);
    },
  
 
  initComplete: function () {
    console.log('init complete');
    this.api().on('columns-reordered', function (e, settings, details) {
        console.log('reordered');
        console.log(table.state()['colReorder']);
    });
	},
});