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 “Column Types and Features” chapter 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 “Allow sorting for the table” switch in the “Sorting and filtering” tab in the table configuration page.
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:
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.
In this example we used “Exam name” as first sorting column and “Student name” as second sorting column.
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 column settings. Each column has a “Default sorting column” switch. If you enable this switch for one of the columns, a selectbox will appear with options – “Ascending” and “Descending” where you can choose sorting direction. Column, with “Default sorting column” option enabled, will be used for ordering when front-end users first open the page.
From version 2.0 it is possible to toggle sorting per individual column. If you want to disable sorting per column you should disable “Allow sorting for this column” option on the column settings panel.
If you want to disable sorting for all columns but to have “Default sorting column” feature, then “Allow sorting for the table” option have to be enabled on the table settings and you have to disable “Allow sorting for this column” for every column separately.
- Creating editable tables and filling the table data manually
- Creating non-editable tables from Excel files
- Creating non-editable tables from Google Spreadsheets
- Responsive design
- Conditional formatting
- Individual column filters (multi-criteria filtering)
- Row grouping
- Using Placeholders – Adjusting MySQL queries dynamically based on shortcode attributes
- Pre-filtering tables through URL
- Calculating totals for columns, sum row
- Table Layout, Word Wrap
- Table data export tools
- Visual Composer integration