evolution-cms / evolution

Welcome to the new evolution of MODX Evolution!
GNU General Public License v3.0
260 stars 95 forks source link

How to do sorting of menu tree A-Z and 1,2,...,10,11,... #968

Open q2apro opened 5 years ago

q2apro commented 5 years ago

I am sorting by the doc alias, as described here: https://github.com/evolution-cms/evolution/issues/260 which works nicely:

image

However, as you can see, it sorts not natural: 1, 10, 11, 12, 13. ... 2, 20, ...

How to fix this?

Dmi3yy commented 5 years ago

Its sort by A-Z all correct. We a sort text not numbers

q2apro commented 5 years ago

I know, but is there any "workaround" (hack) to sort A - Z and 1, 2, ... 10, ...?

pmfx commented 5 years ago

Here is a workaround: add a "0" in front of a 1,2,3... ;)

q2apro commented 5 years ago

more specific: A workaround without changing the numbers :P

Dmi3yy commented 5 years ago

Need find solution order by text+numeric

q2apro commented 4 years ago

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

q2apro commented 4 years ago

Okay, I got it working for my case.

  1. Open file manager\frames\nodes.functions.inc.php

  2. Go to lines:

     // Folder sorting gets special setup ;) Add menuindex and pagetitle
     if ($_SESSION['tree_sortby'] == 'isfolder') {
         $orderby .= ', menuindex ASC, pagetitle';
     }
  3. 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:

Result:

image