We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11316
    • 81 Posts
    I am getting started on a project that requires the ability to sort results on a page.

    Example Page: (pull from ditto setup - show 16 results)

    Give the front end user the ability to have drop down (or multiple drop downs) that that sorts the results on the page:

    (ASC) (Latest) or other Template Variables)

    Thanks in advance!
      • 13730
      • 149 Posts
      I want to do the same thing.

      Did you find the solution for your problem?

      Thanks
        • 3749
        • 24,544 Posts
        You could create a form that posts to the current page and use a snippet to parse the $_POST array and return the appropriate Ditto tag. The page would reload with the selected sort order when the form was submitted.

        The only way that I can think of to do it without reloading the page would be to use JavaScript.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 13730
          • 149 Posts
          Thank you, I'll try your solution
            • 9102 ☆ A M B ☆
            • 318 Posts
            I would think a JS solution would perform better, as the page could still be completely cached and the resort would not require a reload as Bob said. You could write whatever sort parameters you want to use into classes using your Ditto/getResources template, read the results into an array and then sort the array by class. That might be a bit harder to implement though.

            Another possible approach might be to do a sort of hybrid solution, where the page initially loads cached with the default sort order, and then you use AJAX to retrieve the same results, sorted differently via a Ditto/getResources call, from another resource that you call uncached. That way the initial pageload would still be fast, and the resort would occur without appearing to reload the page, though it might be somewhat slower than the pure JS option.