Make HTML Table Sortable With sort-table Library

Category: Javascript , Table | May 21, 2020
Author: stationer
Official Page: Go to website
Last Update: May 21, 2020
License: MIT


Make HTML Table Sortable With sort-table Library


sort-table is a small JavaScript library which applies the sorting functionality to your HTML table.

How to use it:

Import the stylesheet sort-table.min.css and JavaScript sort-table.min.js files into the document.

<script src="sort-table.js"></script>
<link rel="stylesheet" href="sort-table.css">

The basic table sorting functionality can be added simply by adding CSS class js-sort-table to all tables within the document.

<table class="js-sort-table" id="demo1">
  <caption>&lt;table class="js-sort-table"&gt;</caption>
      <th class="js-sort-number">Row</th>
      <th class="js-sort-date">Dates</th>

sort-table.js uses CSS classes to track the sort state. This allows for advanced styling by applying your own styles to the classes as shown below.

  • js-sort-asc: ascending sort
  • js-sort-desc: descending sort
  • js-sort-0: zero-based number of the sorted column
  • js-sort-string: sort by string
  • js-sort-date: sort by date
  • js-sort-number: sort by number
  • js-sort-last: sort by the last word
  • js-sort-input: sort by the input value



  • Avoid attaching handler for ‘none’ columns


  • Add support for ‘none’ sort type


  • Adjusted Sort Direction Decorative Styles

You Might Be Interested In:

6 thoughts on “Make HTML Table Sortable With sort-table Library

  1. Ecki Mühlhäuser

    thanks for the very cool, easy to implement script!
    I have one question:
    Is ist possible, that “js-sort-date” can read a date-format like “14-07-2019″?
    At the moment the”js-sort-date” doesnt interprete that as a date (and it doesnt sort the data).

    Thanks a lot.
    Kind regards, Ecki

    1. Kate

      I noticed the same thing. It only accepts the American format of MM-DD-YYYY not the international standard YYYY-MM-DD

  2. loomski

    I may be blind…but I can’t find the css file you mention anywhere. Would love to try it though.


Leave a Reply