We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4749
    • 623 Posts
    Sorry, you’re probably all sick of me by now. grin

    I have Ditto using an orderBy parameter to sort by TV it’s working fabulously if there are no commas in the tv. For example I have a table of data that I want sorted by number initially. Well, the tv sorting works until there’s a comma in one of the tv’s like 1,200. 1200 works fine and I can live with that, but for the sake of knowing. Is there some way to get ditto to not trip up on the comma?

    [!Ditto? &parents=`10` &tpl=`Tpl` &tagData=`tvTags` &tagDelimiter=`,` &tagMode=`onlyTags` &tags=`[*menutitle*]` &display=`10` &orderBy=`tvSize DESC` &paginate=`1` &paginateAlwaysShowLinks=`1` !]


      The MODx has you...
      Utah Web Design
      • 18397
      • 3,250 Posts
      What version of Ditto are you running?
        • 4749
        • 623 Posts
        I’m using that latest version - not the svn. 2.1.0 I believe.
          The MODx has you...
          Utah Web Design
          • 18397
          • 3,250 Posts
          What happens to the sorting exactly when you add the comma? Also, if you could provide the debug data, that would aide in solving this issue.
            • 4749
            • 623 Posts
            Ditto is placing the values with commas at the bottom of a DESC list. Attached is the debug info.
              The MODx has you...
              Utah Web Design
              • 13577
              • 302 Posts
              Quote from: cbaone at May 23, 2008, 10:49 AM
              ...
              Well, the tv sorting works until there’s a comma in one of the tv’s like 1,200...
              Maybe I’m way off base here, but this seems like a simple matter of how the SQL statement is run. In the ORDER BY clause of an SQL statement, you can have multiple orderings, e.g.

              ... ORDER BY last_name ASC, first_name ASC, state

              So if you put in commas, then the query assumes that it has multiple sort by criteria (first/last name, and state in my example). Very often in snippet parameters, the parameter values are no more than query pieces as I would expect in this case. I guess Mark would be the authority on this one though.
                Standard Disclaimer
                I could be totally wrong.
                • 4749
                • 623 Posts
                jaredc,
                Thanks for the response. Like I said, everything is working as expected with Ditto, but when creating a page where the tv is specified, if the user puts in a comma for a value (e.g., Value in Dollars: 5,346) and all the other values don’t have a comma the value with the comma is displayed at the bottom of the results.

                Value in Dollars:
                Item 1 432
                Item 2 413
                Item 3 376
                Item 4 179
                Item 5 65
                Item 6 5,346

                So it’s sorting everything based on the tvs - sorting it correctly except for the values with commas. These aren’t ditto parameters or anything, but the tvs themselves.
                  The MODx has you...
                  Utah Web Design
                  • 7231
                  • 4,205 Posts
                  It seems that the comma is treated as a decimal rather than thousands. I wonder if this could be a localization issue since some countries use the commas and decimals reversed.

                  An option may be to ask that the users input numbers without commas and add them back in with a phx modifier for display.
                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don't know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 4749
                    • 623 Posts
                    I looked through the PHx documentation, but can’t find anything that explicitly states how to add a comma in later.

                    [+value: ....ahh, forget it I just wouldn’t know where to begin. How can I use PHx to add the comma in later?
                      The MODx has you...
                      Utah Web Design
                      • 7231
                      • 4,205 Posts
                      You can create a custom modifier and use the number_format() php function to add the commas.

                      Save this in a new snippet and name it phx:numFormat
                      <?php
                      $output = number_format($output);
                      return $output;
                      ?>


                      Add &phx=`1` to the Ditto call to activate the phx parser (not sure if this is needed if you have phx plugin installed).

                      Modify your placeholder call to:
                      [+name_of_tv:numFormat+]


                      By default this will add the commas at every thousand interval, so if the value is 12345678 it will output 12,345,678. You can tweak this to output other formats by adding more parameters, check the number_format() docs for more information.
                        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                        Something is happening here, but you don&#39;t know what it is.
                        Do you, Mr. Jones? - [bob dylan]