Summary

Sortable Tables adds on to the core Tables component, allowing the table to be sorted by the header row. Some custom sorting options are available.

Status

API status: general
Web resource key: com.atlassian.auiplugin:aui-table-sortable
AMD Module key: N/A
Experimental API: 5.1
General API: 5.8

Examples

Issue key Name Age Description
TEST-12 Cannot sort tables 2 Table sorting should be allowed
WIN-87 Issue Page doesn't load in IE 7 When loading issue page on IE it doesn't show
DRINK-7 Vending Machine is empty 1 Blocker

Code

Setup

To make a table sortable, you must add the aui and aui-table-sortable CSS classes to the table and also define the <thead> of the table.

Sortable Tables are determined at page load, so if a table is added to the DOM after page load then it must be declared as sortable in your own code.

Default sorting behaviour

Sortable tables attempt to automatically detect the best sorting method for a given column. The sorting method can be explicitly set by adding a CSS class to a column's th element. Most of the sorting methods are provided by the jQuery tablesorter plugin. Some custom sorting methods provided by AUI include:

  • aui-table-column-issue-key: Sorts JIRA issue keys so that they are in the correct ordering by project and then by issue id.
  • aui-table-column-unsortable: Disallows any sorting of this column.

Custom sorting behaviour

Through the jQuery tablesorter plugin API, it is possible to define your own sorting behaviour. The following is an example of how you might order a "Priority" column using a non-alphabetical sort order.

JavaScript API

Set table as sortable

To set a table as sortable, you must pass a jQuery object for the table into the AJS.tablessortable.setTableSortable function.

Assigning a table as sortable multiple times can result in undefined behavior. For example, if a sortable table is present on page load and then you assign it as sortable via the AJS.tablessortable.setTableSortable function, it is unlikely to work as expected.

Refresh sorting capability after data update

To refresh sorting cache after updating the table data you must trigger update event on given table.