We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31660
    • 22 Posts
    Hi.
    Noticed that getResources(1.2.2-pl) sortbyTV parametrs works strange with different-numbers-digits tv’s values. It’s just doing sort by symbols ignoring real count.

    Here my example, have 3 documents:
    Doc 1 have TV(price) = 999
    Doc 2 have TV(price) = 1001
    Doc 3 have TV(price) = 9989

    After sorting these by &sortbyTV=`price` and &sortdirTV=`DESC` the output is:
    Doc 1, TV(price) = 999
    Doc 3, TV(price) = 9989
    Doc 2, TV(price) = 1001

    Guess that problem not solved in http://modxcms.com/forums/index.php?topic=59365.0
    Maybe someone have any ideas?
    Thanks for attention.

    Respect to all modx community and regards to founders.

      • 22303 MODX Staff
      • 10,725 Posts
      Template Variables store there values as strings. If you need to numerically sort, you are going to have to pad the values so they sort properly as strings or wait for this feature (which has already been requested and discussed exhaustively) to be added to getResources.
        • 31660
        • 22 Posts
        Thanks Jason, will be trying to do something by myslf)
        Realy appreciate for your work. I think Modx R will be realy amazing) Such as you guys.
        Good luck, and hi from russia
          • 31660
          • 22 Posts
          Nothing helps.
          I’ve changed values to int, and tried "$Value + 0". Something like this:

            
          
          $Value = $myresource->getTVValue('MyTvWithNumericValue');
          $Value =  intval($Value);
          $Value = $Value + 0;
          $tv = $modx->getObject('modTemplateVar',array('name'=>'MyTvWithNumericValue'));
          $tv->setValue($DocId, $Value);
          $tv->save();  
          
          


          Even tried to add zeros to a string value, hopeless, really not good method

          Think there are two ways:
          1 To sort element after getting these into an object array (somehow)
          2 Change TV date type in modx (it’s obviously not correct)

          Realy hope that sorting problems will be solved. Revolution ditto have some issues with sort too.
            • 22303 MODX Staff
            • 10,725 Posts
            You’ll have to store the data (IOW in the database) as a sortable string, i.e. "0000123" vs. "123" since that is the only way to sort a numeric string properly. Trying to change the value to an integer in PHP has no effect.
              • 31660
              • 22 Posts
              Yep, gotcha)
              But if we changed TV data in db (add some zeros to all of them, like this "000"."23"), it will be output in the backend’s TV field 00023, wich be confused for user editor.

              I guess i have to sort elements after collecting ($Documents = $modx->getCollection(’modResource’,$query);) Can’t figured out how smiley
              xPDOQuery sortby doesn’t help in this case, i suppose.
                • 22303 MODX Staff
                • 10,725 Posts
                You have to sort it via the database; you can’t post sort in getResources because that would invalidate the limit/offset functionality. Other Snippets can be created to do post sorting like this for specific purposes where limit/offset is not needed.
                  • 7557
                  • 61 Posts
                  Quote from: Vitek at Mar 19, 2011, 01:33 AM

                  Yep, gotcha)
                  But if we changed TV data in db (add some zeros to all of them, like this "000"."23"), it will be output in the backend’s TV field 00023, wich be confused for user editor.

                  I guess i have to sort elements after collecting ($Documents = $modx->getCollection(’modResource’,$query);) Can’t figured out how smiley
                  xPDOQuery sortby doesn’t help in this case, i suppose.
                  Hi Vitek,
                  try this:
                  http://modxcms.com/forums/index.php/topic,59365.msg354427.html#msg354427
                    • 31660
                    • 22 Posts
                    Hi dj13,
                    It works) Thanks a lot, your help just in time, just in moment when i stopped trying)
                    Regards!