Minimal Table Sorting Library – sorTable.js

Category: Javascript , Table | November 12, 2016
Author: beatdjam
Views Total: 1,430
Official Page: Go to website
Last Update: November 12, 2016
License: MIT

Preview:

Minimal Table Sorting Library – sorTable.js

Description:

sorTable.js is an extremely light JavaScript library used to sort table rows by alphabet and number without any dependencies.

How to use it:

Add the sorTable’s JS and CSS files to the html page.

<link rel="stylesheet" href="css/sorTable.css">
<script src="js/sorTable.js"></script>

Add the CSS class ‘sortable’ to your existing html table and done. Note that your html table must have ‘thead’ and ‘tbody’ elements.

<table class="sortable">
  <thead>
  <tr>
    <th>No</th>
    <th>Content1</th>
    <th>Content2</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <th>1</th>
    <td>Alpha</td>
    <td>Charlie</td>
  </tr>
  <tr>
    <th>2</th>
    <td>Bravo</td>
    <td>Duff</td>
  </tr>
  <tr>
    <th>3</th>
    <td>Charlie</td>
    <td>Apple</td>
  </tr>
  <tr>
    <th>4</th>
    <td>Delta</td>
    <td>Butter</td>
  </tr>
  </tbody>
</table>

That’s it. Click on the table header to sort the table rows.