# | Name | Birthday | Grocery item | Price | Version | Filesize |
---|---|---|---|---|---|---|
1 | Gonzo the Great | 12-2-70 | Radishes | $0.63 | 31.0.1650.57 | 124k |
2 | Ernie | 10/11/69 | Fish | $12.09 | 11.0.1 | 134.56 GB |
3 | Bert | 10/11/1969 | Broccoli | $0.79 | 18.0.1284.49 | 134 B |
4 | Cookie Monster | 1/09/1966 | Oreo cookies | $2.78 | 3.0.0 | 4.13 TiB |
5 | Kermit | 12-05-1955 | Granola | $4.73 | 3.0.9 | 12 YB |
6 | Sam the Eagle | 04/07/75 | Corn dog | $5.50 | 3.1.2 | 19.4 K |
A small & simple sorting component for tables written in JavaScript
Download the ZIP of this repository or install via command line:
npm i tablesort
# Or if you're using Yarn
yarn add tablesort
<script src='tablesort.min.js'></script>
<!-- Include sort types you need -->
<script src='tablesort.number.js'></script>
<script src='tablesort.date.js'></script>
<script>
new Tablesort(document.getElementById('table-id'));
</script>
8+ ✔ | 3.6+ ✔ | 10+ ✔ | 11.50+ ✔ | 5.1+ ✔ |
// npm install tablesort
var tablesort = require('tablesort');
tablesort(el, options);
Add the styling from tablesort.css file to your CSS or roll with your own.
If you require a sort operation that does not exist in the sorts directory, you can add your own.
Tablesort.extend('name', function(item) {
// Regular expression to test against.
// `item` is a table value to evaluate.
return /foo/.test(item);
}, function(a, b) {
// Custom sort functionality goes here.
// e.g var n = (a > b) ? -1 : 1;
return n;
});
If you’ve made an extend function that others would benefit from pull requests are gladly accepted!
Dependencies: Node.js 16 or 18; npm 8.
Tablesort relies on Grunt as its build tool. Simply run
npm run build
to package code from any contributions you make to src/tablesort.js
before submitting pull requests.
Tests are run via:
npm ci && npm t
MIT