Sometimes you might need a table in your documentation that should be easily sortabale by one column or the other. Here's how you can achieve this in ClickHelp.
Preview
You can click on the column headings (first row cells) to sort columns in ascending or descending order.
| Strings | Numbers |
|---|---|
| Apple | 82156 |
| Coconut | 57 |
| Banana | 532 |
| Zimbabwe | 1124 |
How to implement
You will need sort-table.js - a script that makes sorting possible. You can get the latest version either from the original author's GitHub page (along with the demo file) or by downloading it directly from our server:
- Upload the script to your ClickHelp portal (via Scripts tab of the File Manager).
- Add the script to the necessary projects by adding the file in the "Project scripts" section of the Basic Settings.
- Add a table. You must have the <thead> section with <th> elements present, otherwise, the script won't work
- Add the js-sort-table class to your table for the script to work.
- Add the js-sort-Xclass to the <th> tags to correctly process cell values. Here is a list of supported classes and, therefore, sorting methods:
- js-sort-string — used for sorting pretty much any text in the alphabetical order
- js-sort-number — sort by number.
- js-sort-0 — zero-based number of the sorted column
- js-sort-date — sort by date
- js-sort-last — sort by the last word
- js-sort-asc — ascending sort
- js-sort-desc — descending sort
HTML Code
Here's how the table you saw in the "preview" section looks like "from the inside"
HTML |
<table class="js-sort-table CHTable" style="width: 400px;"> |