|
1 | | - : https://www.npmjs.com/package/table-sort-js |
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
2 | 6 |
|
3 | | -* Description: A JavaScript client-side HTML table sorting library with no dependencies required. |
| 7 | +## TABLE-SORT-JS. |
4 | 8 |
|
5 | | -* Demo: https://leewannacott.github.io/Portfolio/#/GitHub |
| 9 | +- Description: A JavaScript client-side HTML table sorting library with no dependencies required. |
6 | 10 |
|
7 | | -* Backend: `npm install table-sort-js` and require("../node_modules/table-sort-js/table-sort.js") |
| 11 | +- [Demo](https://leewannacott.github.io/Portfolio/#/GitHub) |
| 12 | +- [Documentation.](https://leewannacott.github.io/table-sort-js/docs/about.html) |
| 13 | + (work in progress) |
| 14 | +- [npm package.](https://www.npmjs.com/package/table-sort-js) |
| 15 | +## Install instructions. |
8 | 16 |
|
9 | | -* Frontend: `<script src="https://leewannacott.github.io/table-sort-js/table-sort.js"></script>` |
| 17 | +<b>Option 1.</b> Install from npm: ` npm install table-sort-js` |
10 | 18 |
|
11 | | -* Instructions: Add class "table-sort" to HTML table tags. Click on column headers to sort. |
| 19 | +```javascript |
| 20 | +import tableSort from "table-sort-js/table-sort.js"; |
| 21 | +``` |
| 22 | +Refer to the documentation for examples on using table-sort-js with frontend frameworks such as |
| 23 | +[ReactJS.](https://leewannacott.github.io/table-sort-js/docs/react.html) |
12 | 24 |
|
13 | | -Example: |
14 | | -```html |
15 | | -<script src="https://leewannacott.github.io/table-sort-js/table-sort.js"></script> |
16 | | -<table class="table-sort"> |
17 | | - <thead> |
18 | | - <tr> |
19 | | - <th>Last Name</th> |
20 | | - <th>First Name</th> |
21 | | - <th class="order-by-desc">Birth Date</th> |
22 | | - <th>Employee ID</th> |
23 | | - </tr> |
24 | | - </thead> |
25 | | - <tbody> |
26 | | - <tr> |
27 | | - <td>Smith</td> |
28 | | - <td>John</td> |
29 | | - <td>1977/12/4</td> |
30 | | - <td>1</td> |
31 | | - </tr> |
32 | | - <tr> |
33 | | - <td>Bach</td> |
34 | | - <td>Frank</td> |
35 | | - <td>1976/10/27</td> |
36 | | - <td>10</td> |
37 | | - </tr> |
38 | | - <tr> |
39 | | - <td>Doe</td> |
40 | | - <td>Jason</td> |
41 | | - <td>1978/4/6</td> |
42 | | - <td>100</td> |
43 | | - </tr> |
44 | | - <tr> |
45 | | - <td>Michael</td> |
46 | | - <td>Jackson</td> |
47 | | - <td>1958/8/29</td> |
48 | | - <td>54</td> |
49 | | - </tr> |
| 25 | +<b>Option 2.</b> [Download table-sort.js](https://leewannacott.github.io/table-sort-js/table-sort.js) (Select save as.) |
50 | 26 |
|
51 | | - <tr> |
52 | | - <td>Ben</td> |
53 | | - <td>Tenison</td> |
54 | | - <td>1994/7/21</td> |
55 | | - <td>134</td> |
56 | | - </tr> |
57 | | - </tbody> |
58 | | -</table> |
| 27 | +Then add the following script before your HTML table: |
| 28 | +```html |
| 29 | +<script src="table-sort.js"></script> |
59 | 30 | ``` |
60 | | -Notes: |
61 | | -* Makes use of natural sorting to sort numerical values correctly. Sorts numbers, Dates, alphanumeric, etc. |
| 31 | +Refer to the documenation for examples how to use table-sort-js with [HTML.](https://leewannacott.github.io/table-sort-js/docs/html5.html) |
| 32 | +#### To make tables sortable: |
| 33 | + |
| 34 | +- Add `class="table-sort"` to HTML <table> tags. |
| 35 | +- Click on table headers to sort columns. |
| 36 | + |
| 37 | +#### Classes: |
62 | 38 |
|
63 | | -* `class="order-by-desc"` on `<th>` to change default sort to descending order on first click. |
64 | | - |
65 | | -* If `<thead>` does not exist it will be created by using data from first row. `<tbody>` is optional. |
| 39 | +| <table> classes | Description | |
| 40 | +| -------------- | ------------------------------------------------ | |
| 41 | +| "table-sort" | Make the table sortable! (Words, numbers, dates) | |
| 42 | +| "table-arrows" | Display ascending or descending triangles. | |
| 43 | +| "remember-sort"| If clicking on different columns remembers sort of the original column. | |
66 | 44 |
|
67 | | -* Example of use: https://www.cssscript.com/minimal-table-sorter/ |
| 45 | +| <th> classes | Description | |
| 46 | +| --------------- | ----------------------------------------------------------- | |
| 47 | +| "order-by-desc" | Order by descending on first click. (default is aescending) | |
| 48 | +| "file-size" | Sort file sizes(B->TiB) uses the binary prefix. (e.g KiB) | |
| 49 | +| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g <td data-sort="42"> | |
68 | 50 |
|
69 | | -* Add `table-arrows` class to display ascending or descending triangle. |
| 51 | +#### Development: |
| 52 | +If you wish to contribute, install instructions can be found [here.](https://leewannacott.github.io/table-sort-js/docs/development.html) |
0 commit comments