Sorting HTML Table Vanilla JavaScript Library | Sortable.js

Sortable – Small JS vanilla table sorter makes any table with class = “sortable“, er, sortable. That is, the user can click the table header and change the sorting of table rows. The JavaScript Sortable.js library allows you to sort any static or dynamic HTML table. Blazing fast and easy to implement.

Just include JavaScript and it will work. No function calls are needed, everything is done with eventListener. (CSS isn’t much needed, but it makes it pretty and easy to use).

html table sort column header, jquery sort table ascending and descending, how to sort html table column using javascript, bootstrap table sort

Please note that the massive Advanced and Advanced versions have been deprecated. I just can’t justify their existence If you need advanced sorting, set up the tables with the data sort attribute instead. The same goes for the ES6 version, it seems pointless.

Factoids/Facts

  • 713 bytes are minimized.
  • Works with tables generated from JS / ajax. (Due to the event listener)
  • Lightning-fast. Huge tables will make it slow and it might even cause the browser to freeze, especially for cell phones, so you know …
  • Requires thead and tbody.
  • Via browser, ie9 +
  • EventListeners attached to rows will be removed
  • Event listeners are no longer removed! 😊
  • Not tested with React, Angular, Vue, etc. No method will work without messing with it. Literally no way.

How to make use of it:

1. Import the stylesheet sortable.min.css and JavaScript sortable.min.js into the HTML doc.

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

2. Add the CSS class sortable to your HTML table and the library will maintain the remaining.

<table class="sortable">
  <thead>
    <tr>
      <th>Month</th>
      <th>Savings</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>$80</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>Sum</td>
      <td>$180</td>
    </tr>
  </tfoot>
</table>

3. Ignore certain table columns utilizing the no-sort class.

<table class="sortable">
  <thead>
    <tr>
      <th>Month</th>
      <th class="no-sort">Savings</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>$80</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>Sum</td>
      <td>$180</td>
    </tr>
  </tfoot>
</table>

4. You can even sort any data (like dates, file size) utilizing the data-sort attribute:

<table class="sortable">
  <thead>
    <tr>
      <th>Month</th>
      <th class="no-sort">Savings</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>January</td>
      <td data-sort="100">$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td data-sort="80">$80</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>Sum</td>
      <td data-sort="180">$180</td>
    </tr>
  </tfoot>
</table>

Ultra-Fast HTML Table Sorting Library, sortable JS table sorter Plugin/Github, html sort table without javascript, jquery sort table on header click


See Demo And Download

Official Website(tofsjonas): Click Here

This superior jQuery/javascript plugin is developed by tofsjonas. For extra advanced usage, please go to the official website.

Related Posts

Confetti-Falling-Animation-Effect-party

Confetti Falling Animation Effect In JavaScript | party.js

Party.js is a JavaScript library to brighten user site experience with visual effects! Celebrate success with dom confetti! The library is written in TypeScript and compiled into…

jquery-cookie-consent

Simple jQuery Cookie Consent Plugin

jquery.cookie-consent is a simple jQuery plugin to request consent to use cookies. An easy-to-use and highly customizable cookie consent bar that informs your visitors of the use…

Timepicker-Plugin-for-jQuery

Timepicker JavaScript Plugin for jQuery Inspired by Google Calendar

jquery.timepicker is a lightweight jQuery timer plugin inspired by Google Calendar. It supports both mouse and keyboard navigation and weighs 5.5KB minified and compact. Features: Highly customizable…

angular-ngx-carousel-slider

A Lightweight, Touchable, and Responsive Angular Universal Carousel Library

ngxCarousel is a lightweight, tactile, and responsive library for creating an angular carousel. No dependencies, no more hammer. Must Read: Angular Responsive Image Slider With Lightbox Popup…

vue-fullpage-modal

First Mobile Full-screen Modal Popup Library For Vue

Vue full-page modal is a responsive, mobile-compatible, screen-friendly pop-up library for Vue.js. Must Read: Modal Component Is Written in Vanilla JS | ensemble Modal How to make…

random-number-picker

Generate a Random Number Picker In Vanilla JavaScript

Random Number Picker is a Vanilla JS-based number picker that allows you to generate a random number within a specified range. Must Read: Generating Lottery Numbers Using…