tags:

views:

1022

answers:

3

I used to know how to do this, but I can't seem to get sorting to work on a view where filters are exposed in a block. I want to be able to filter by, for example, type, price etc, but then also have sorting options to sort by these items.

How do I get sorting to work like this?

+1  A: 

AFAIK you can't expose sort criteria like you can with filters.

I looked a bit around a found this module. The idea is to create several views each with a different sort criteria and link them together with tabs. It's a bit hackish and might not work with exposed filters. The module is still in beta release, and I haven't tested it, so can't say if it's any good.

googletorp
I remember specifically having set an option in the past, that would show dropdowns at the top of the view. I want to know how to do that again. :-)
RD
+1  A: 

If you choose to use a table layout, you can sort by columns. That functionality is built into views.

Mike Crittenden
+2  A: 

I used that code to override sorting in non-table views

function views_tweak_views_query_alter(&$view, &$query) {
  if ($view->name == 'products'){
  if (arg(3) == 'pu') $query->orderby[0]='uc_products_sell_price ASC';
  if (arg(3) == 'pd') $query->orderby[0]='uc_products_sell_price DESC';
  if (arg(3) == 'nu') $query->orderby[0]='node_title ASC';
  if (arg(3) == 'nd') $query->orderby[0]='node_title DESC';

  } 
}

and placing into view template links with those urls

451F
Can you explain a bit more how you implemented this? Did you put this in template.php? Or where exactly? And when is this hook called? Every time a view is, erm, viewed?
RD
I put this in separate module. Hook alteres a view query to change sorting. Called every time. In view I add 4 links (sort name up, sort name down, sort price up and sort price down). In $query->orderby[0] stored field and direction for sorting.
451F