Make Tables Sortable Macro

Last modified by Admin on 2023/03/20 00:07

cogMakes all wiki tables on the page it is inserted sortable (and optionally filterable)
TypeXAR
CategoryMacro
Developed by

Clemens Robbenhaar

Active Installs26
Rating
2 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

Description

As explained in the Syntax Help wiki tables can be made sortable by adding some CSS classes via wiki markup notation like (% class="grid sortable filterable doOddEven" id="some-table-id" %) (and including the proper JavaScript resources via a velocity macro). See also the Table Sorter page.

This is however quite cumbersome for users only comfortable with the WYSIWYG editor.

Instead this extension defines a macro that, if inserted on a given page, does the necessary steps automatically for all tables on the page. The tables still should have a header as the first row, or the results will be quite odd.

Note: so far this extension has only been tested with Firefox & Chrome. Because it is completely JavaScript based, there might be browser incompatibilities. 

Usage

First you have some plain tables on the page, where the first row is the heading:

before-sortable.png

To make them sortable, edit the page in the editor, and insert the "Sorteable Tables" macro. (Sorry for the typo in the name.) You can edit if you want the tables on the page to be sortable, filterable, have a sticky header, or all of them:

macro-settings.png

Note that the change is not visible directly in the editor (actually a good thing, as it would infere with editing the table headers).

After saving you can see the tables on the page can be sorted by clicking on the headers:

after-sortable.png

or even be filtered, if you typed in "yes" in the "Filterable" settings:

after-sortable-filerable.png

Disabling Sort for some tables

XWiki 1.1+  If you add a CSS class which contains nosort in the name this disables the sort feature for the table.
Admittedly this means to go to the source editor and add a (% class="nosort" %) on a line above of the table, which defeats a bit the purpose of this macro, but this is how it possible if needed.

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Release Notes

v1.1

v1.0

v0.3

Added parameter to make the table header sticky.

v0.2

Bugfix: Tables were not filterable if a live-table was present on the same page.

v0.1

Initial Version

Dependencies

Dependencies for this extension (org.xwiki.contrib:macro-sortabletables 1.1):

Tags:
    

Get Connected