Sorry, we don't support your browser.  Install a modern browser
This post is closed.

natural sort order option, for sorting string columns containing alphanumeric data#307

This is quite an important issue to address, not being able to sort things naturally… think something like product codes from different brands.

It’s the old problem where for example AB 80 gets sorted after AB 200 and AB 300, when it of course should be the first of these three.
Or anything with the common format where the number part of the string again has no leading zeros, so they just get sorted the wrong way: 10, 157, 18, 2, 9.

Handling these particular cases would be quite easy, but in many situations the data unfortunately has no standard pattern or fixed length.

However, at least MariaDB already has a general solution: https://mariadb.com/kb/en/natural_sort_key/

So, if it would be possible to choose in wpDataTables not to override MySQL sorting, then we could just implement our own sorting in the SELECT statement.
Even better if you could come up with a natural sort option in wpDataTables sorting engine.

For more information and several tricks to achieve the desired result:
https://en.wikipedia.org/wiki/Natural_sort_order
https://stackoverflow.com/questions/8557172/mysql-order-by-sorting-alphanumeric-correctly
https://stackoverflow.com/questions/48600059/using-mysql-sort-varchar-column-numerically-with-cast-as-unsigned-when-the-colum

3 years ago
Merged into Numeric sorting for string columns#126
a year ago