JSFiddle - React, Tailwind, and code Playground

by Mausino

HTML

<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
<!DOCTYPE html>
<html>
  <head>
    <script src="http://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>
<link href="https://nightly.datatables.net/rowreorder/css/rowReorder.dataTables.css?_=d163871dd21df6b5a0b4985ca66fa6d4.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/rowreorder/js/dataTables.rowReorder.js?_=d163871dd21df6b5a0b4985ca66fa6d4"></script>

    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <label><input type=checkbox  id="showused">Show only used</label>
    <div class="container">
      <table id="example" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th>#</th>
            <th>Use</th>
            <th>Office</th>
            <th>Qty</th>
            <th>Start date</th>
            <th>Salary</th>
          </tr>
        </thead>

        <tfoot>
          <tr>
            <th>#</th>
            <th>Use</th>
            <th>Office</th>
            <th>Qty</th>
            <th>Start date</th>
            <th>Salary</th>
          </tr>
        </tfoot>

        <tbody>
          <tr>
            <td>1</td>
            <td><input type=checkbox id='row-1-used' onchange="if ($(this).is(':checked')) { $(this).closest('tr').addClass('used'); } else { $(this).closest('tr').removeClass('used'); } "></td>
            <td>Edinburgh</td>
            <td>1/1</td>
            <td>2011/04/25</td>
           ...

CSS

body {
  font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
  margin: 0;
  padding: 0;
  color: #333;
  background-color: white;
}
tr.used {
  background-color: Yellow !important;
}

JavaScript

// Datatable code

$(document).ready( function () {
  var table = $('#example').DataTable({
            "rowReorder"     : true,
            "scrollY"        : "500px",
            "scrollCollapse" : true,
            "lengthMenu"     : [[-1, 25, 100, 200], ["All", 25, 100, 200]],
            "columnDefs"     : [{ orderable: true, className: 'reorder', targets: 0 },
                                { orderable: false, targets: '_all' }]
  });
});

// Show Only Used checkbox code

$.fn.dataTable.ext.search.push(
    function( settings, searchData, index, rowData, counter ) {
      
      console.log(rowData[3])
      var data = rowData[3].split('/');
      
      var complete = false;
      if (data.length === 1 || data[0] == data[1]) {
        complete = true;
      }
      var ShowAll = !$('#showused').is(':checked');
      if (ShowAll || complete)
      {
          return true;
      }
      return false;
    }
);

$(document).ready(function() {
    var table = $('#example').DataTable();
    $('#showused').change( function() {
      console.log('clicked');
        table.draw();
    } );
} );