Open q2apro opened 5 years ago
Its sort by A-Z all correct. We a sort text not numbers
I know, but is there any "workaround" (hack) to sort A - Z and 1, 2, ... 10, ...?
Here is a workaround: add a "0" in front of a 1,2,3... ;)
more specific: A workaround without changing the numbers :P
Need find solution order by text+numeric
In PHP it is called natural sort: https://www.php.net/manual/en/function.natsort.php
Or using usort
: https://stackoverflow.com/q/12426825/1066234
Okay, I got it working for my case.
Open file manager\frames\nodes.functions.inc.php
Go to lines:
// Folder sorting gets special setup ;) Add menuindex and pagetitle
if ($_SESSION['tree_sortby'] == 'isfolder') {
$orderby .= ', menuindex ASC, pagetitle';
}
Afterwards insert this code:
// hack for natural sorting
if ($_SESSION['tree_sortby'] == 'alias') {
// $orderby is "sc.alias ASC"
$orderby = 'IF(CONCAT("",sc.alias*1)=sc.alias, LPAD(sc.alias,5,"0"), sc.alias) ASC';
}
The "order by" explained:
CONCAT("",sc.alias*1)=sc.alias
checks for numeric valueLPAD(sc.alias,5,"0")
adds several 0
in front (left padding), which creates 00001
, 00010
. 00200
etc.Result:
I am sorting by the doc alias, as described here: https://github.com/evolution-cms/evolution/issues/260 which works nicely:
However, as you can see, it sorts not natural: 1, 10, 11, 12, 13. ... 2, 20, ...
How to fix this?