http://www.frisksomenfisk.no/?q=nyheter

I have made a view that allows the user to filter nodes based on category (taxonomy: term ID), genre (node type) and source (taxonomy: term ID). The sort is by posted date descending. However, I would also like to allow the user to be able to sort the content by different criteria both ascending and descending depending on the user's choice. Is this possible to achieve with one view? Or do I have to create one view for each of the different sorting methods (by date ascending, by date descending, by popularity ascending, by popularity descending etc.)?

Comments

WorldFallz’s picture

if you're using a table view each of the individual fields can also be designated as sortable and given a default order. I'm not sure about the other view styles.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

joiv’s picture

I am using ordinary node view. I guess I'll just have to make a lot of views then... :(

gforce301’s picture

It is possible. It requires getting pretty far into views though. You can dynamically change virtually any property of a view with argument handling code. It's really advanced stuff.

joiv’s picture

Do you have any idea of how to do it? I soon realized that I don't understand how the Argument-thing works. If anyone knows how to do it and is willing to help, I would really appreciate it. I could give you admin access to the page temporarily.

joiv’s picture

http://groups.drupal.org/node/4203

This code is supposed to allow sorting ascending and descending. I just don't know where to put it.

if ($args[0]== "desc") {
$view->sort[0]['vid'] = $view->vid;
$view->sort[0]['position'] = 0;
$view->sort[0]['field'] = 'node.nid';
$view->sort[0]['sortorder'] = 'DESC';
$view->sort[0]['options'] = '';
$view->sort[0]['tablename'] = '';
$view->sort[0]['id'] = 'node.nid';
}elseif ($args[0]== "asc") {
$view->sort[0]['vid'] = $view->vid;
$view->sort[0]['position'] = 0;
$view->sort[0]['field'] = 'node.nid';
$view->sort[0]['sortorder'] = 'ASC';
$view->sort[0]['options'] = '';
$view->sort[0]['tablename'] = '';
$view->sort[0]['id'] = 'node.nid';
}
return $args;

WorldFallz’s picture

It's suppposed to go into the argument handling code box (i'm not exactly sure where that is in the new views2 ui though, you'll have to poke around the arguments options) but this post is from 2007 so it must be for views1-- there's no guarantee it will work for views2.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

joiv’s picture

Ah, I see. The only place I could find for entering code in the arguments section was under validation.

Anyway, I have created one view for each sorting now...

photoman’s picture

that is in view 1, I can change filters sorts by argument handling code , but in view 2 , I can't do the same thing .

anyone know that?