Is it possible to custom sort views2? Can I give a sort function or sort SQL somewhere?

Comments

neokoenig’s picture

So in admin/build/views/edit/yourviewnamehere

Click the + to Sort Criteria, select your field, such as node:title, click add, set the direction and you should be good to go?

(that's from memory at least...)

--------------------------
OxAlto Design
http://www.oxalto.co.uk
--------------------------

--------------------------
OxAlto Design
http://www.oxalto.co.uk
--------------------------

aquila’s picture

That's too standard at this moment. I am looking for very special things. E.g. for numbers I would like to sort as "5 first, then 2, then 3, then 8, then everything else".

neokoenig’s picture

One work around would be to add a sortOrder field to node using CCK
Then it could work in a similar way to weight? Essentially all you'd be doing is assigning a number on importance and then sorting by that number ASC or DESC as needed.
--------------------------
OxAlto Design
http://www.oxalto.co.uk
--------------------------

--------------------------
OxAlto Design
http://www.oxalto.co.uk
--------------------------

aquila’s picture

I took this approach. It is not very clean, but it is userfriendly as I can allow some users to edit the node weight.
Thanks for your help!

Mark Theunissen’s picture

You could also try using the Nodequeue module to order nodes, then add that as a sort criteria in the view.

Hope that helps!

__________________________________________________________

Mark Theunissen

(work) Digital People
(personal) Code Baboon

Mark Theunissen’s picture

If you need it to be more automatic, try adding a Computed Field to the CCK type and run some PHP to generate the sort weight.

__________________________________________________________

Mark Theunissen

(work) Digital People
(personal) Code Baboon

aquila’s picture

What a good idea, I will certainly use this in the future!

avolve’s picture

Just wanting to see if anyone has come up with a user-friendly solution.

I am working on a page that will list committee members (i.e. chair, various co-ordinators) and and not sure on the most effective approach to achieving a sort order based on position as opposed to title, date, etc.

The ordering needs to be dynamic given that members will change over time.

avolve designs | ethical by design

aquila’s picture

Then nodequeue is exactly what you want, it is very userfriendly. My users understood it without any help!

truyenle’s picture

My case is a little bit different:

I user view 2 with a patch located at http://drupal.org/files/issues/views-group-aggregate.patch to make views to support group by and aggregation features.

So I can have some thing like
Group by: field A
Aggregate: Sum: Field B

The issue here is how can I sort by the the result of the Aggregate:Sum?

I did try sort by Content: Field B but it's not the result I want.

Thanks
Truyenle

narayanis’s picture

The cleanest way to achieve this is with a small custom hook. Check out this post for a good example: http://www.agileapproach.com/blog-entry/using-hookviewsqueryalter-change...

Here is a second example: http://www.nicklewis.org/hook-views-query-alter-how-programatically-alte...

fourmi4x’s picture

Thank you so much for these 2 links: exactly what I was looking for!

avolve’s picture

I created a nodequeue, ordered the nodes as I wanted them, and added it as a relationship to the view (I also removed any sort ordering from the view) — following the screencast at http://learnbythedrop.com/drop/160

On the nodequeue page the order is exactly how I want it. On the view it is unchanged, producing the same issue I was seeking to overcome.

I am unable to determine why views would sort alphabetically, based on a particular CCK field (even when another field was set as sort criteria), nor why views seems to overwrite the order produced in the nodequeue.

Anyone have thoughts on this?

avolve designs | ethical by design

peezy’s picture

In case someone else stumbles on this post, the answer is yes. There are several options. Please see http://drupal.org/node/398508 to see which best suits your needs.

1kenthomas’s picture