By just_fixed_it on
As far as I can tell I can't expose sort options using Views. What I mean is for a displayed view (a simple unformatted list) I want a drop down to order by popularity, alphabetical on title field, etc..
Any recommendations on how I should go about achieving what I want?
Comments
_
Views v3 adds exposed sorts. Works great.
Um ... not sure ...
Thanks very much for taking the time to reply.
I've done lots of searching around and the only exposed sort functionality I can find for Views v3 is when using a table format. Is this what you've been using? What I am after is exposed sorts for a simple list.
I've found a thread that offers a patch to add some sort functionality, but I'm a little unsure if this is the right way to go about it.
Any more help would be very welcome.
Thanks,
Aaron
_
Nope-- when you add sort criteria there's an 'expose' button just like with filters. That's the exposed sort to which I was referring.
Thanks for that ... I'll take
Thanks for that ... I'll take another look.
Aaaaahhhhhh
Right, after just simply not seeing what you were talking about, I eventually discovered a reason why I may not be seeing the same views screens as you ... errrr ... (embarrassing silence) ....
... I had previously rolled back to Views 2 because Views 3 was causing me stability problems. Sorry to be so careless in my earlier post. I had just forgotten about the roll back, and didn't take the time to check my module version until now. Stupid.
If you would be so kind ... which version of Views 3 are you running, and is it stable for you (there doesn't seem to be a 'full' release of Views 3).
Cheer,
Aaron
_
lol, no worries. I'm using the current d6 dev of views3 and it's been rock solid for me. I'm so used to the new exposed sort and aggregation features I don't think I could go back to v2 even if it weren't stable.
little late
Hi guys, im comming a little late for this conversation i know, however, from all my google research, as usuarl in every developers day, y finally get with it, but i have install the views3 and when i add the sort criteria, boom, there are no expose button anywhere, is there something i can possible doing wrong?, i just disable view, remove the directories, put the files and enable the views module again, and nothing. help please.
thanks in advance
--
Jason Acuna
_
I've got the current dev of views3, and when I add a field to the sort the expose button is in the upper right corner just like with the filters section.
I think you are looking for
I think you are looking for something like this - http://www.mercycorps.org/gift/category/all
I used a simple form in the View header:
I then used hook_views_query_alter() to change the sort order
It is not the ideal way to do this, but it works.
_
yep-- that's it, and views 3 now has this built-in to the sort options.
How do you use this code? Can
How do you use this code? Can you post your hook_views_query ?
Ok, first you need to have
Ok, first you need to have all of the sort options that you would like to use as sort options in your view with the default first.
Then you need to add this function:
You can get the field names, node_[first_sort_criteria], etc., by looking at the query that Views generates.
You do not need to return anything as the &$view and &$query are variable references.
That is all that there is to it.
Thanks, but it does not work
Thanks, but it does not work properly.
I have the following:
Views name: taxonomy_term
Filters: Node title asc
Filters: Node title desc
Views header code:
Module file:
the page just refreshes and nothing happens
You don't need the second
You don't need the second value of your ->orderby array.
You simply need to change the ASC to DESC. So it should look like:
You will only need the Title ASC sort criteria in the View if that is all that you want to do.
You could also simply change
You could also simply change the else case to
I had it written the other way, but the way that it was written, it wasn't changing the highest sort criteria.
I got a little lazy when I
I got a little lazy when I posted this.
The $query->orderby array should be
The way that I had it written originally wouldn't change the order of the sorting.
My bad. :/
Thanks for the help. My code
Thanks for the help. My code is now working for 50%. When i change the default sorting order in my module file it is working.
Only when i use the selectlist box, the page is only refreshing. There is no extra syntax after the url like: ?sort . Is there something wrong with my html code?
I would get rid of the second
I would get rid of the second option in the function code. So:
And make sure that you only have the node_title in the View Sort Order once. This way you are only going to use the function to change the ASC or the DESC, but the only criteria will be the node_title.
I appreciate your guidance so
I appreciate your guidance so far on this. I have the right functionality all except for my select list always goes back to the default, "Newest". However, the product page is still sorted by the option that I selected. Here is what I have:
Sort Order:
Node: Post date asc
Node: Title asc
Product: Sell price asc
Form:
Module:
Do you see any errors that would cause this?
Thanks!
Brian
Ah, right.... I added <?php
Ah, right....
I added
So that you can set the "selected" for the current sort order.
Works perfect... Thanks for
Works perfect... Thanks for your help!
Thanks
Thanks for your help.
It works perfect!!!
Drupal 7 ???
I'm using Drupal7 and Views3.
I tried everything that was suggested in this thread and the results that I get is that the form changes, but the order doesn't.
Can this work for Drupal7 ? or do we need to use another function
I want to sort by Date posted and a numeric field called "field_rentpcm". Here is what I have:
MODULE:
and in my views header I inserted a Global PHP form.
FORM:
An additional problem is that by default (before any choice is made) it will show the following error:
Can someone PLEASE help?
Another Approach for views with an attachment
This approach works in a great way. but unfortunately, not in my use case :( , I have a view of type "page" with a view of type "attachment" attached to it, using the approach stated here, one ends up editing the sorting of all queries and views on this page (the page view and the attachment)!
However, the approach found here works too, and enables you to generally manipulate specific displays :) (maybe only the page, or only one of the attachments attached to it)
http://stackoverflow.com/questions/2719850/how-to-change-the-sorting-of-...
it is based on hook_views_pre_view() you need to look at the answer not the question only:D
Not able to sort the columns using $query->orderby
I have
field name : 'field_emp_salary' ,
table name : 'field_data_field_emp_salary' and
//implement the hook_views_query_alter();
function hook_views_query_alter(&$view, &$query) {
if($view->name == "employee_basic_salary") {
$query->orderby[0] = array(
'field' => 'field_data_field_emp_salary.field_emp_salary_value',
'direction' => 'ASC',
);
}
}
Can anyone solve below error :
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_field_emp_salary.field_emp_salary_value' in 'order clause'
...waiting for reply
Thanks in advance.
Reply
Hello Guys,
I got the solution and it shows appropriate sorted columns
function hook_views_query_alter(&$view, &$query) {
if($view->name == "employee_basic_salary") {
$view->query->add_orderby('field_data_field_emp_salary','field_emp_salary_value',$order = 'DESC', $alias = '', $params = array());
}
}