We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44234
    • 219 Posts
    Hi,

    I am using MigxLoopCollection to output a list of data that I want to sort numerically. Is there anyway of sorting naturally as my single numbers arn't prefixed with zero? http://php.net/manual/en/function.natsort.php

    This is my sortConfig:
    &sortConfig=`[{"sortby":"photo_number","sortdir":"ASC","sortmode":"numeric"}]`
    

    The output is ordered like this:
    1
    100-107
    108
    109-110
    111
    112-114
    115
    116-120
    13-18
    19-22
    2-4
    23-24
    25-26
    27-29
    30
    31-32
    

    Need it in this correct order:
    1
    2-4
    13-18
    19-22
    23-24
    25-26
    27-29
    30
    31-32
    100-107
    108
    109-110
    111
    112-114
    115
    116-120
    

    This question has been answered by Bruno17. See the first response.

      Find me on Twitter, GitHub or Google+
    • discuss.answer
      • 4172
      • 5,888 Posts
      try

      &sortConfig=`[{"sortby":"CAST(photo_number AS SIGNED)"}]`
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 44234
        • 219 Posts
        Quote from: Bruno17 at Jan 19, 2016, 12:46 PM
        try

        &sortConfig=`[{"sortby":"CAST(photo_number AS SIGNED)"}]`

        Thanks Bruno but no good, strange order now. Any other ideas?

        Oridginal Order:
        &sortConfig=`[{"sortby":"photo_number","sortdir":"ASC","sortmode":"numeric"}]`
        
        1-6
        10-14
        105-119
        120-121
        15-22
        23-32
        33-39
        40-43
        44-54
        55-73
        7-9
        74-78
        79-83
        84-88
        89-91
        92-97
        98-104
        

        New Order:
        &sortConfig=`[{"sortby":"CAST(photo_number AS SIGNED)"}]`
        
        23-32
        105-119
        10-14
        44-54
        15-22
        1-6
        92-97
        55-73
        74-78
        89-91
        7-9
        33-39
        20-121
        40-43
        79-83
        98-104
        84-88
        
          Find me on Twitter, GitHub or Google+
          • 4172
          • 5,888 Posts
          this is working for me.

          Tested also this one, to get the second part sorted, too:

          &sortConfig=`[{"sortby":"CAST(SUBSTRING_INDEX(name, '-', 1) AS SIGNED)"},{"sortby":"CAST(SUBSTRING_INDEX(name, '-', -1) AS SIGNED)"}]`


          this is working for me, too
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 44234
            • 219 Posts
            Managed to get both of your solutions working Bruno, thanks ever so much!
              Find me on Twitter, GitHub or Google+