Sortable Tables is a vanilla js plugin to turn any <table>
into a sortable one by just adding one class.
This package uses ECMAScript5. You can check browsers that support ES5.
There are 2 ways to install this package:
Install using:
npm install sortable-tables
or
yarn add sortable-tables
Include scripts either by:
import 'sortable-tables/dist/sortable-tables.min';
import 'sortable-tables/dist/sortable-tables.min.css';
require('sortable-tables/dist/sortable-tables.min');
require('sortable-tables/dist/sortable-tables.min.css');
dist/sortable-tables.min
and dist/sortable-tables.min.css
files and add them to your project<link rel="stylesheet" href="path/to/sortable-tables.min.css">
<script src="path/to/sortable-tables.min.js" type="text/javascript"></script>
sortable-tables.js
and sortable-tables.css
to your page -or their minified versions-.scrollbar-outer
to the <table>
you wanna make sortable.<thead>
to your table with one <tr>
and make sure all cell elements in it are <th>
<tbody>
to your table and make sure all cell elements in it are <td>
That’s it. View the example file for a demo.
$
or %
that would cause the alphabetical order to fail, add the class numeric-sort
to the <th>
element corresponding to that columnsortable-fa-icons
to <table>
to use FontAwesome sort icon instead of default unicode icons.Author: armaaar
Source Code: https://github.com/armaaar/sortable-tables
#javascript #html