Please wait...

Sorting tables in WordPress

Video versionA video overview of sorting tables in wpDataTables

wpDataTable sortable tables

Tables rendered by the wpDataTables plugin are sortable by default; it means that the content of the table can be ordered by the values of one of the columns. The ordering rules depend on the column type: e.g. string columns will be ordered by alphabetical rules, integer or float by arithmetic rules, and so on. See chapter 6 of this documentation for detailed info on different column types, and sorting rules. To enable sorting (or to disable, since it is enabled for all columns by default) you need to use the “Enable sorting” checkbox in the “Additional settings” section of the Step 1 in the table editing page.

Sorting one column

When the sorting is enabled, each column header will get “interactive”: it will work as a button, and when you click it, you will sort the table by this column in ascending (increasing order), which will be indicated by the highlighting of the column (means that it is used for sorting), and by the triangle showing to the right of the header turning black. When triangle is showing “up” it means that the table is sorted in ascending order – from “smaller” to “bigger” value:

When you click the same header again, the triangle will turn “down”, which means that the sorting is done in descending order from “bigger” to “smaller” value:

Sorting multiple columns

If you sort by one of the columns, then press “Shift” button on the keyboard, and, while holding it, click on another header, it will be used as a second sorting column (first the ordering will be done based on the first column, and then based on the second column):

The secondary sorting means that when the values of the first columns are the same for a number of rows, you can also use some other column values to get the order that you want. If the sorting is enabled, one of the columns will be used for ordering when you open the page (“default sorting column”). If you don’t provide it manually, the first column will be used for ordering; if you want to use a different one, you can define it in the step 2 of the table edit page: each column has an input “Default sorting column” with 2 radio buttons – “Ascending” and “Descending”. If you enable the radio button for one of the columns, this column will be used for ordering when front-end users first open the page.

Never miss new features!

Join 2000+ newsletter subscribers

Never miss notifications about new cool features, promotions, giveaways or freebies - subscribe to our newsletter! We send about one mail per month, and do our best to keep our announcements interesting.

We never spam or disclose your address to anyone.