JQDataTablesPlugin

JQuery based progressive enhancement of tables

Overview

This plugin implements a widget to enhance normal HTML tables with extra navigation features such as sorting, filtering and paginating through datasets. The %DATATABLE macro is specifically tailored towards datasets created on the base of DataForms. It lets you easily compile an overview of data of that kind stored in a web as well as select specific records for further use in wiki apps.

JQDataTablesPlugin can be used in two distinct ways:

  • by means of the %DATATABLE macro
  • by means of HTML5 and JSON to enhance HTML tables directly

%DATATABLE takes a pointer to a DataForm definition and then creates a table based on the known formfields in that definition to create columns of a kind matching the formfield types. It then uses a connector fetch the data from the backend. There are several kinds of connectors available at the moment based on the additional functionality installed on your Foswiki:

  • search: this one uses the normal native search feature of Foswiki also used by the %SEARCH macro
  • dbcache: this one uses DBCachePlugin which is implementing a faster still native search, also available via its %DBQUERY macro
  • solr: this connector uses the SolrPlugin which uses a Solr fulltext search engine integrated into Foswiki.

A default connector can be defined as required. Note however, that even though %DATATGABLE tries to hide the differences of available connectors behind the scene, connectors will behave differently, i.e. when it comes to filtering. Also, performance is vastly different with the search connector being the slowest one. It is strongly recommended that you at least install DBCachePlugin for acceptable performance in every-day usage.

DATATABLE

Using a %DATATABLE you can query a set of topics and display their structured data in a dynamic table. Results are best when querying structured data attached to your topics as each formfield defined in the DataForm directly correlates to a column in the generated table. In this case you may specify the form definition in the form parameter and formfields in the columns parameter. The %DATATABLE will then use this information to properly display formfield values as well as sort columns along the technical representation. For example a date formfield will properly be displayed according to your locale's date format while sorting by date uses date values represented as epoch seconds.

Syntax: %DATATABLE{"<query>" parameter="..." parameter="..." ...}%

Parameter Description Default
<query>, query specify a search query to filter rows on the server-side; NOTE: the query language might vary depending on the connector being used, e.g. dbcache vs search vs solr  
connector connector to be used to fetch data dynamically from the backend; possible values are search (using Foswiki's native %SEARCH), dbcache (needs Foswiki:Extensions/DBCachePlugin), solr (needs Foswiki:Extensions/SolrPlugin), additional connectors may be implemented by plugins; NOTE: for general-purpose search dbcache is the best choice defined in $Foswiki::cfg{JQDataTablesPlugin}{DefaultConnector}
class additional css class to be added to the widget in addition to foswikiTable  
width width of table, e.g. 100% and the like  
web web to query for data current web
form data form definition  
paging, pager switch on/off paging data; NOTE: this parameter is deactivated when scrolling is specifed as well (see docu) off
pagelength, rows number of rows to be displayed when paging is enabled (see docu) 10
lengthmenu switches on a menu element to change the page length (see docu) [10, 25, 50, 100]
scrolling, scroller switch on/off dynamic scrolling; data will be fetched from the backend as you are scrolling up and down; NOTE: this parameter disables paging as these two features are mutual exclusive off
searching switch on/off the global search box (see docu) off
searchmode defines how to search, either using one search box covering all columns (global), or using one search box per column (multi) global
searchdelay delay before changes in a search box will cause new data to be fetched from the backend 400
sort specifies the column for initial ordering (see docu) first column
reverse specifies the initial ordering direction off
info switch on/off the info about the number of rows in the set (see docu) off
ordering switch on/off the ability to sort the table by clicking on a column header (see docu) on
scrollx switch on/off horizontal scrolling (see docu) off
scrolly specify vertical scrolling (see docu) off
scrollcollapse switch on/off collapsing of the table height on small data sets (see docu) off
columns comma-separated list of formfield names to be displayed; see the notes on special columns below all formfields of the DataForm specified by form
selecting switch on/off select extension  
selectproperty specifies the property of a row to be selected when selection is enabled topic
selectmode possible values are os, single, multi, this specifies the way a selection is made (see docu) multi
responsive switch on/off responsive extension  
fixedheader switch on/off fixed header extension  
<field-name>_title a column title for a given field-name, e.g. ProjectState_title="State" name of the formfield as specified in columns
<field-name>_width column width for a given field, e.g. ProjectID_width=5em  

Special column names

In general column names specified in the columns parameter of the %DATATABLE parameter directly relate to a formfield of an attached DataForm. Values are displayed and sorted according the the type of the formfield. There are however a few column names that have a special meaning or trigger an additional behavior on data in this column:

  • index: this is an auto-generated column enumerating the rows in a table
  • Date, Changed, Modified, Created, info.date, createdate: these fields are all date fields and treated accordingly
  • Topic: alias for topic
  • TopicTitle: displays the TopicTitle of a topic linking to it
  • By: alias for author of recent topic revision
  • Creator, createauthor, info.author: author if the initial topic revision
  • publishauthor: author that published the topic, defaults to createauthor in case there is no explicit Author field in the form
  • publishdate: date when the publishauthor created the initial revision, defaults to createdate in case there is no explicut PublishDate field in the form
  • Worflow: name of the workflow assigned to a topic
  • A column name starting with a / (slash) will be excluded from any special treatment, i.e. /Author will not be interpreted as the author of the recent topic revision, but as the Author formfield of a DataForm (see below example).

Example

Below example lists all topics in the System web that have the PackageForm attached to it:

%STARTSECTION{"example3"}%
%DATATABLE{
   web="%SYSTEMWEB%"
   form="%SYSTEMWEB%.PackageForm"
   paging="on"
   searching="on"
   info="on"
   pagelength="10"
   lengthmenu="5, 10, 20, 50, 100"
   columns="index, Topic, Description, Version, Release, /Author"
}%
%ENDSECTION{"example3"}%

index Topic Description Version Release /Author

HTML5

A data table can also be applied to an already existing table enhancing it with additional features such as paging, client-side sorting, searching etc. This is done by wrapping your tables into a .jqDataTablesContainer div element and specify additional parameters using HTML5 data attributes

%JQREQUIRE{"datatables"}%
<div class="jqDataTablesContainer" data-paginate="true" data-searching="true" data-info="true">
| *Header* | *Header* | *Header* | *Header* |
| Data | Data | Data | Data |
| Data | Data | Data | Data |
| Data | Data | Data | Data |
| Data | Data | Data | Data |
</div>

See http://datatables.net/reference/index for a full list of all options.

<div class="jqDataTablesContainer" data-paginate="true" data-searching="true" data-info="true">
| *Header* | *Header* | *Header* | *Header* |
| Data | Data | Data | Data |
| Data | Data | Data | Data |
| Data | Data | Data | Data |
| Data | Data | Data | Data |
</div>

Example

This example generates a table dynamically using a FormattedSearch:

%STARTSECTION{"example1"}%
<div class="jqDataTablesContainer" data-paginate="true" data-searching="true" data-info="true">
%SEARCH{
  "1"
  type="query"
  topic="*Plugin"
  header="| *Name* | *Date* | *Author* |"
  format="| $topic | $date | $wikiusername |"
  nonoise="on"
}%
</div>
%ENDSECTION{"example1"}%

Name Date Author
AttachContentPlugin 23 Sep 2005 - 09:09 ProjectContributor
AttachmentListPlugin 22 Jun 2009 - 20:57 AdminGroup
AutoCompletePlugin 13 Jan 2011 - 21:08 UnknownUser
AutoTemplatePlugin 13 Nov 2007 - 15:03 ProjectContributor
AutoViewTemplatePlugin 09 Apr 2016 - 02:21 ProjectContributor
BreadCrumbsPlugin 07 Mar 2018 - 10:27 ValentinBamann
CalDAVPlugin 26 Jan 2011 - 12:55 AdminUser
CalendarPlugin 14 Oct 2014 - 10:01 MatthiasGeorgi
ClassificationPlugin 05 Mar 2018 - 13:53 AdminUser
CommentPlugin 22 Jan 2018 - 14:46 ProjectContributor
CompareRevisionsAddonPlugin 18 Jan 2015 - 16:51 ProjectContributor
ConfigurePlugin 09 Dec 2017 - 03:47 ProjectContributor
DBCachePlugin 01 Mar 2018 - 12:27 AdminUser
DBConnectorPlugin 15 Dec 2008 - 10:50 EugenMayer
DiffPlugin 09 Jan 2018 - 12:41 ProjectContributor
DigestPlugin 17 Nov 2009 - 13:38 ProjectContributor
EditRowPlugin 01 Mar 2018 - 12:32 AdminUser
EditTablePlugin 20 Sep 2015 - 02:05 ProjectContributor
EmptyPlugin 23 Nov 2015 - 15:58 UnknownUser
ExtendedWebListPlugin 10 Dec 2008 - 01:53 UnknownUser
FilterPlugin 07 Mar 2018 - 10:23 ValentinBamann
FlexFormPlugin 30 Oct 2013 - 12:47 AdminUser
FlexWebListPlugin 30 Oct 2013 - 12:44 AdminUser
FootNotePlugin 01 Mar 2018 - 12:41 AdminUser
GluePlugin 05 Mar 2018 - 13:16 AdminUser
GraphvizPlugin 07 Oct 2015 - 12:30 ProjectContributor
GridLayoutPlugin 27 Jan 2017 - 14:20 ProjectContributor
HistoryPlugin 08 Sep 2015 - 16:18 ProjectContributor
HomePagePlugin 19 Mar 2015 - 00:51 ProjectContributor
IfDefinedPlugin 05 Mar 2018 - 13:16 AdminUser
ImageGalleryPlugin 10 Nov 2013 - 11:25 AdminUser
ImagePlugin 07 Mar 2018 - 10:27 ValentinBamann
InterwikiPlugin 07 Jul 2015 - 01:58 ProjectContributor
JQDataTablesPlugin 13 Jun 2016 - 09:07 ProjectContributor
JQGridPlugin 15 Jul 2015 - 16:06 ProjectContributor
JQueryPlugin 07 Nov 2015 - 02:00 ProjectContributor
ListyPlugin 01 Oct 2015 - 07:42 micha
MailerContribPlugin 05 May 2015 - 18:00 ProjectContributor
MediaPlugin 08 Mar 2009 - 00:30 ProjectContributor
MetaDataPlugin 29 Apr 2014 - 08:59 ProjectContributor
MimeIconPlugin 14 Oct 2014 - 10:01 MatthiasGeorgi
MoreFormfieldsPlugin 12 Jan 2018 - 11:24 ProjectContributor
MultiLingualPlugin 12 Jan 2018 - 11:57 ProjectContributor
NatEditPlugin 19 Nov 2013 - 11:36 AdminUser
NatSkinPlugin 19 Nov 2013 - 11:36 AdminUser
PreferencesPlugin 15 Jun 2015 - 00:26 ProjectContributor
PubLinkFixupPlugin 14 Sep 2015 - 00:51 ProjectContributor
PublishPlugin 14 Feb 2014 - 08:04 AdminUser
RedDotPlugin 12 Oct 2010 - 15:36 AdminUser
RedirectPlugin 08 Mar 2018 - 07:46 ValentinBaumann
RenderFormPlugin 14 Oct 2014 - 10:01 MatthiasGeorgi
RenderListPlugin 21 Jul 2015 - 17:42 ProjectContributor
RenderPlugin 30 Oct 2013 - 12:47 AdminUser
SetVariablePlugin 18 Nov 2009 - 12:24 UnknownUser
SlideShowPlugin 08 Sep 2015 - 13:20 ProjectContributor
SmiliesPlugin 17 Sep 2015 - 17:22 ProjectContributor
SpreadSheetPlugin 08 Nov 2015 - 04:46 ProjectContributor
SubscribePlugin 03 Dec 2008 - 14:09 UnknownUser
TWikiCompatibilityPlugin 15 Mar 2015 - 17:07 ProjectContributor
TablePlugin 09 Sep 2015 - 11:56 ProjectContributor
TagCloudPlugin 15 May 2014 - 11:51 ProjectContributor
TagMePlugin 14 Oct 2014 - 10:01 MatthiasGeorgi
TinyMCEPlugin 21 Jul 2015 - 17:42 ProjectContributor
TocPlugin 22 Dec 2009 - 10:07 UnknownUser
TopicCreatePlugin 05 Mar 2018 - 13:16 AdminUser
TopicDataHelperPlugin 12 Apr 2005 - 12:03 ProjectContributor
TopicInteractionPlugin 16 Feb 2018 - 09:28 ProjectContributor
TopicSpecificNavigationPlugin 15 Dec 2008 - 10:50 EugenMayer
TreeBrowserPlugin 05 Mar 2018 - 13:16 AdminUser
TreePlugin 05 Mar 2018 - 13:15 AdminUser
TwistyPlugin 21 Jul 2015 - 17:42 ProjectContributor
UpdatesPlugin 22 Jan 2018 - 14:46 ProjectContributor
UploadPlugin 12 Oct 2010 - 15:36 AdminUser
WebLinkPlugin 29 Nov 2010 - 14:45 ProjectContributor
WysiwygPlugin 21 Jul 2015 - 17:42 ProjectContributor

JQDataTablesPlugin comes with additional sorting features for specific types of data:

  • numeric
  • string
  • date (extended to be able to parse Foswiki's default date format)
  • currency
  • metrics (e.g. killo, mega, giga, tera, …)

Click on the table headers to sort the columns according to their data type.

%STARTSECTION{"example2"}%
<div class="jqDataTablesContainer">
| *#* | *String* | *Date* | *Number* | *Currency* | *Size* |
| 3 | ActionTrackerPlugin | 27 Jan 2010 - 17:07 | 1 | 1,00 | 10KB |
| 1 | AntiWikiSpamPlugin | 03 Jan 2013 - 09:07 | 10 | 10,00 | 3GB |
| 2 | RenderListPlugin | 13 May 2012 - 02:59 | 0.01 | 1,01 | 100MB |
| 5 | CommentPlugin | 10 Apr 2011 - 23:39 | 100 | 0,10 | 2024kB |
| 4 | FindElsewherePlugin | 23 Dec 2012 - 17:06 | 20 | 100,- | 0.1kB |
| 6 | JsonRpcContrib |  | 0 | -100,- | 1024TB |
</div>
%ENDSECTION{"example2"}%

# String Date Number CurrencySorted ascending Size
6 JsonRpcContrib   0 -100,- 1024TB
5 CommentPlugin 10 Apr 2011 - 23:39 100 0,10 2024kB
3 ActionTrackerPlugin 27 Jan 2010 - 17:07 1 1,00 10KB
2 RenderListPlugin 13 May 2012 - 02:59 0.01 1,01 100MB
1 AntiWikiSpamPlugin 03 Jan 2013 - 09:07 10 10,00 3GB
4 FindElsewherePlugin 23 Dec 2012 - 17:06 20 100,- 0.1kB

Installation

You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.

Open configure, and open the "Extensions" section. "Extensions Operation and Maintenance" Tab → "Install, Update or Remove extensions" Tab. Click the "Search for Extensions" button. Enter part of the extension name or description and press search. Select the desired extension(s) and click install. If an extension is already installed, it will not show up in the search results.

You can also install from the shell by running the extension installer as the web server user: (Be sure to run as the webserver user, not as root!)
cd /path/to/foswiki
perl tools/extension_installer <NameOfExtension> install

If you have any problems, or if the extension isn't available in configure, then you can still install manually from the command-line. See https://foswiki.org/Support/ManuallyInstallingExtensions for more help.

Dependencies

NameVersionDescription
Foswiki::Plugins::JQueryPlugin >= 4.10Required

Change History

25 Sep 2017: fixed html5 data attributes
30 Aug 2017: disabled Author auto-column; added publishdate and publishauthor auto-columns
23 Jan 2017: don't report back an url parameter in the error message
02 Sep 2016: added default english translation files
13 Jun 2016: fixed parsing of dates that are already epoch seconds; improved default settings of table layout
25 May 2016: updated to latest version of DataTables
22 Apr 2016: implemented server-side grid widget
18 Mar 2014: remove console.log() leftover; improve sorting date columns
09 Nov 2013: implemented sorting for currency, and metrics
08 Nov 2013: make it work under {NoConflict}; enable jquery-ui theming by default now; created a non-goofy default look and feel to play nicely with a skin's table design; only add DataTables support to specific tables, not all; make it configurable with declarative metadata; compress and minify plugin assets; remove files not required by the plugin; clean up controls and css classes added by TablePlugin's; added type detector for foswiki date columns
18 Jan 2013: Initial version
Topic revision: r1 - 13 Jun 2016, ProjectContributor
This site is powered by FoswikiCopyright © by the contributing authors. All material on this site is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback