We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27330
    • 884 Posts
    is there a way I can sort a ditto list by custom TV vs. document placeholders?

    I have a [*product_price*] tv that I want to be able to sort by.

      • 25663 MODX Staff
      • 12,272 Posts
      I do in fact believe so. Please see http://ditto.modxcms.com for lots of interesting examples and always run the latest version.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 27330
        • 884 Posts
        are you thinking of this?
        http://ditto.modxcms.com/files/snippet-ditto-php.html#orderBy

        orderBy

        An array that holds all criteria to sort the result set by. Note that using a custom sort will disable all other sorting.

        $orderBy["parsed"][] = array("sortBy","sortDir");
        $orderBy["custom"][] = array("sortBy","callback_function");

        that’s the closets I could find, but I don’t get how do I actually use this piece of code.

          • 36592
          • 970 Posts
          &orderBy=`product_price DESC` ... something like this.
            • 27330
            • 884 Posts
            cool, I just need to add the tv prefix to the sortBy param and the sorting is done.

            does anyone knows how can I allow user to change the ditto call sort option themselves?
            I want to have something like
            Sort by:  Name  |  Price  |  reviews


            I’m think on some js that shows a different ditto call when the links are clicked but thinking maybe there is an easy way to do that without inventing the wheel?
              • 7231
              • 4,205 Posts
              JS will not work since it is post rendering. you could use a wrapper snippet to get the sort parameter but you could also use dittos ’request’ extender function for this.

                [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]
                • 10449
                • 956 Posts
                does anyone knows how can I allow user to change the ditto call sort option themselves?

                Generally speaking, there are various approaches:

                - each option is a link to another page, which has another ditto-call in it. (easy, but not very efficient if you have such stuff in many site-areas)
                - build a page-structure with Ajax-tabs. Each tab loads another page and displays just the tab-content-area (no entire page-reloads).
                - write a little snippet that waits for a certain $_GET parameter (PHP switch statement). Depending on that value, create the Ditto call dynamically. You could use the API function $modx->runSnippet() for that.
                  • 27330
                  • 884 Posts
                  thanks for the replies guys, appreciate it a lot.
                  I don’t like the idea of having to repeat the same info several times and show the correct page when a link is clicked and thinking I understood Ditto request extender I tried something like this but it didn’t work.


                  So I made a sortByOptions TV with these:name==pagetitle||Brand==tvproduct-brand||Price==tvproduct-price
                  and tried to added the TV to front end using the Quill snippet which allows the user to select the option from the drop down.

                    [[Quill? &mode=`control` &name=`sortByOptions`]]
                  [!Ditto? &id=`MenShirt` &sortBy=`[*sortByOptions*]` &depth=`0`&tpl=`ditto-products-view` &paginate=`1` &extenders=`request`!] 


                  but the call won’t refresh or update when a new selection is made.
                  So I guess I don’t quite get how to use of the request extender.

                  any help is appreciated.
                    • 27330
                    • 884 Posts
                    I guess my question is if the request extender is ’out of the box’ solution or do I still need a snippet to use it (sort of like Results Per Page snippet)?