JSFiddle - React, Tailwind, and code Playground

by polshgiant

HTML

<!DOCTYPE html>
<html>
  <head>
    

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs5/jq-3.6.0/dt-1.11.3/fc-3.3.3/rg-1.1.3/datatables.min.css"/>
 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs5/jq-3.6.0/dt-1.11.3/fc-3.3.3/rg-1.1.3/datatables.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>

        <tbody>
          <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>$3,120</td>
          </tr>
          <tr>
            <td>Garrett Winters</td>
            <td>Director</td>
            <td>Edinburgh</td>
            <td>63</td>
            <td>2011/07/25</td>
            <td>$5,300</td>
          </tr>
          <tr>
            <td>Ashton Cox</td>
            <td>Technical Author</td>
            <td>San Francisco</td>
            <td>66</td>
            <td>2009/01/12</td>
            <td>$4,800</td>
          </tr>
          <tr>
            <td>Cedric Kelly</td>
            <td>Javascript Developer</td>
        ...

CSS

/* Ensure that the demo table scrolls */
    th, td { white-space: nowrap; }
    div.container {
        width: 600px;
        margin: 0 auto;
    }

JavaScript

$(document).ready( function () {
  let dtApi = $('#example').DataTable({
    //data: dataSet,
    lengthChange: false,
    paging: false,
    scrollX: true,
    scrollY: "60vh",
    columns: [
      { title: "Name" },
      { title: "Position" },
      { title: "Office" },
      { title: "Extn." },
      { title: "Start date" },
      { title: "Salary" }
    ],
    //rowGroup: { dataSrc: 2 }, 
    orderFixed: [[2, 'asc']],

    // Note that fixedColumn 'left' and 'right' settings seem to be broken
    // Easy place to see the broken behavior is on the example page https://datatables.net/extensions/fixedcolumns/examples/initialisation/two_columns.html
    // 'leftColumns' and 'rightColumns' settings work properly
    fixedColumns: { 
      leftColumns: 0,
      rightColumns: 2
    }, 


  });
  window.top.dtApi = dtApi;
  
} );