Home

Awesome

Tablesorter Plugin

The Tablesorter Plugin is for Grav CMS. It applies the jQuery plugin Tablesorter to tables in a page (v2.27.7).

For a demo, visit my blog.

Installation

Installing the Tablesorter plugin can be done in one of two ways. The GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.

GPM Installation (Preferred)

The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's terminal (also called the command line). From the root of your Grav install type:

bin/gpm install tablesorter

This will install the Tablesorter plugin into your /user/plugins directory within Grav. Its files can be found under /your/site/grav/user/plugins/tablesorter.

Manual Installation

To install this plugin, just download the zip version of this repository and unzip it under /your/site/grav/user/plugins. Then, rename the folder to tablesorter. You can find these files on GitHub or via GetGrav.org.

You should now have all the plugin files under

/your/site/grav/user/plugins/tablesorter

NOTE: This plugin is a modular component for Grav which requires Grav and the Error and Problems to operate.

Configuration

Below is the default configuration. To override, first copy plugins/tablesorter/tablesorter.yaml to config/plugins/tablesorter.yaml and only edit that file. These settings can also be overridden at the page level.

enabled: true
active: false
include_widgets: false
include_metadata: false
production: true 
custom_path: assets/tablesorter  #no leading or trailing slash
themes: blue
table_nums: 1

Usage

This plugin is a limited implementation of the full plugin. There is no capacity, for example, to inject metadata into the tables themselves, and widget capabilities have not been tested. What you can do is inject configuration variables into the initial function call. You can do this globally (a single set of arguments for all affected tables) or set them on a table-by-table basis.

To do this, add the following to your page header:

tablesorter:
  active: true
  args:
    ...

The full list of available options can be had on the Tablesorter documentation page. What the plugin does is JSON encode the args content and pass that on to the function.

For example, if you want to automatically sort the first column of all the affected tables in ascending order, you'd do the following:

tablesorter:
  active: true:
  args:
    sortList: [[0,0]]

If you had two different tables, and you wanted the first sorted ascending but the second descending, then you'd do the following:

tablesorter:
  active: true:
  table_nums: '1,2'
  args:
  	1:
      sortList: [[0,0]]
    2:
      sortList: [[0,1]]

Themes take a little finesse. As long as you're only using a single theme for all your tables, then you can rely on the default configuration or set the themes field in the page header. If you want to use multiple themes in a page, though, then you need to define those themes in the args field as well. Let's say you had two tables and you wanted to apply the blue theme to the first and the green theme to the second:

tablesorter:
  active: true:
  table_nums: '1,2'
  themes: green,blue 	#order is irrelevant
  args:
  	1:
      theme: blue
    2:
      theme: green

Customization

Currently the only customization supported is themes. When finding theme files to inject, the plugin first checks the custom_path. If it doesn't find the file there, it will pull from the plugin's dist folder. All you have to do is ensure you follow the naming convention: theme.{NAME}{.min?}.css.

The most common customization will be copying an existing theme over and just tweaking it a little.

Future Work

I'm not a PHP native, so I welcome any pull requests to clarify documentation, clean up the code, or to add new functionality.