Certain data types, such as currency values with currency symbols, numbers combined with text, or European dates, need special attention when they are sorted. The reason for that is that they differ from the data formats for which the DataTables JavaScript library has sorting algorithms built-in. To use such data types with TablePress, download, install and activate the DataTables Sorting plugins Extension like a regular WordPress plugin.
Currencies, numbers with text, and dates
Data types like formatted numbers (e.g. numbers with unit), currencies, European date formats (dd.mm(.yyyy)
or dd/mm(/yyyy)
) will then be recognized automatically, so that they are sorted correctly. Sometimes, it might be necessary to force the data type on a column. That’s possible by adding the following code to the “Custom Commands” text field in the “Features of the DataTables JavaScript library” section on the “Edit” screen of the table:
columnDefs: [ { type: "formatted-num", targets: [ 2, 3 ] } ]
Code language: JavaScript (javascript)
The 2, 3
in that code is a zero-based list of all columns that shall be sorted as values with commas as the decimal separator. Here, 2, 3
means that the third and fourth column are sorted like this, as the counting starts with 0
for the first column.
Using different thousand or decimal separators
In large parts of the world, mostly the English-speaking part, a number is written like “100,000.00”, where the comma is the thousand separator, and the period is the decimal separator. In many countries, for example in Europe, the format “100.000,00” is more common. Although a number in computing usually uses the English format, TablePress can use both formats, if it’s instructed to do so. That can be done via the translation file for the DataTables JavaScript library. If the used language matches the format, this will happen automatically. Otherwise, you can use the extra parameter datatables_locale=de_DE
(as an example for German) in the Shortcode. To set custom thousand and decimal separators, the Change DataTables Strings Extension can be used.
If an Extension is useful for you, please check out the available TablePress Premium features and consider getting a Premium license plan, which bring even more features for you and your site visitors. Thank you!