0

I am looking to sort nodes in a view, but only after the user has selected the sorting value.

So the nodes are currently listed in posting order, but I would like to provide the user to sort by price, but only once selected the price sorting?

Creating a standard sort by price, sets this from the initial page load and does not give the use a chance to see recently posted items.

How could this be achieved?

1 Answer 1

2

Two ideas:

(1) Expose the sort to the user to allow them to control sorting. You need to enable "Expose this sort to visitors, to allow them to change it" for the sort criterion in views. See below for more detail on how to get the two sorts grouped together.

(2) Present the data in a table and make the columns you want the user to be able to sort, "sortable". You'll find this option under Format: table > Settings.

With both approaches, you can set an initial sort, so the user will see content in the order you wish when the page first loads.

Edit: more detail for #1: by default, views will sort the output based the first sort criterion, and clutter the exposed form with sort order controls. To get the default sort you want, and to clean things up, you can try:

  1. Add both sort fields and expose to visitors (post date first)
  2. Under exposed form options: enable autosubmit and hide the submit button
  3. Under exposed form options: disable "Expose sort order"
  4. Adjust exposed sort labels if needed for clarity

(exposed form options are in the Advanced section of the view)

When the view loads, the user will see a single select list that contains both sort options, and no submit button. The view will be sorted according to the first option.

2
  • Perhaps there was not enough emphasis on an important point. The sorting by price should only take effect if the user was to use this option. When adding in a sort and exposing it you are forced to select either Asc or Dsc. This should be optional.
    – IamOnStage
    Nov 21, 2013 at 19:21
  • I added some more detail to idea #1. I'm not sure this will work exactly as you like, but the result would be a view ordered by post date by default, with a select list to change to order by price.
    – Dave Bruns
    Nov 21, 2013 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.