I have a few tables created with sortable fields and clickable column headers. When I click on each header, it sorts the data ascending. I see there is an option to set a Default Sort direction, but this only seems to effect fields with the "Default sort" option checked.

As an example, here is one of my pages:

http://championshipatbest.com/fulham

If you click on the column headers, it will sort the data ascending. Most people visiting my site will want to see this data descending, so they have to click twice.

Is there any way to change the default order for any or all sortable fields?

CommentFileSizeAuthor
#11 drupal-table.png25.03 KBdeanloh

Comments

merlinofchaos’s picture

Currently this behavior is not changeable -- this is how the tablesort headers normally act for all of Drupal. Note that if you click it again it will sort the other way.

richardhkirkando’s picture

Thanks for the reply. Drupal question, not a views question then. I'll have to mess with my tablesort.inc a bit and see if I can find a workaround that doesn't break everything else.

merlinofchaos’s picture

Not exactly, Views 2 uses its own tablesort implementation, I just copied the model so that the UI would be the same.

dawehner’s picture

i will mark this as feature request.

why not use "default sort order" when clicking a table header and interpretate it with the "default sort order"

infojunkie’s picture

I need this feature too, so I found the relevant piece of code in theme/theme.inc, function template_preprocess_views_view_table. As with dereine's suggestion, I made the specified default sort order to be the default order for all columns. To do so, just change the line:

// @todo -- make this a setting
$initial = 'asc';

to

// @todo -- make this a setting
$initial = $options['order'];
papricus’s picture

Category: support » feature

1) For me that only works once. I can click once on the column label for ascending sorting, but with a second click it does not sort descendingly.
2) It allows only to set ALL other columns to be sorted ascendingly.

Again: It would be very nice in a future version to be able to set the first sorting order individually per field.

dagmar’s picture

Version: 6.x-2.1 » 6.x-3.x-dev
deanloh’s picture

The best is to display both up and down arrows in headers where sortable is checked. So if users want to see data in descending order, they click the down arrow, and vice versa.

Subscribing.

Jerome F’s picture

If I get you well, it would work like the list in the finder on mac or the list in the windows browser on PC. We could sort, either descending or ascending in each column. By name, by date, by any other custom value...

@richardhkirkando : on your table at championshipatbest, choosing a sorting criteria in the header works once and needs refresh to work again, do you know why ?

Subscribing.

Bilmar’s picture

I believe this feature would be beneficial where the administrator knows that when a user clicks on the top of a column to sort by, the user is looking for ascending or descending for the column.

To clarify with an example:
A view with three fields - 1) airline 2) location and 3) price
Default sort is set to sort by location A=>Z
When user click on price column to sort by price..we can assume user wants cheapest => expensive

-OR- adding one more field
A view with four fields - 1) airline 2) location and 3) price 4) years of service
Default sort is set to sort by years of service; highest => lowest number of years
When user click on price column to sort by price..we can still assume user wants lowest=>highest

Just used this example to illustrate, but this feature can benefit countless number of situations.

Another Example:
Currently, at Drupal.org if you search an issue from project page it sorts by 'score' - When I click to sort by 'Last Updated' column from this page it always sorts farthest=>closest by time..which I never understood as I think most users want to look at recent updates rather than 2 years ago. I always have to click it again to get most recent=>farthest by date
http://drupal.org/project/issues/cck?text=rules&status=All

Hope these examples are clear =) thanks

deanloh’s picture

StatusFileSize
new25.03 KB

To further elaborate my suggestion at #8, here's a screenshot. Not sure how tedious it is to implement , but I believe it will certainly improve usability as we are letting users to have the full control.

dsbrianwebster’s picture

This is one of my first contributed "solutions". I submit this knowing full well that this isn't a "real" fix. But I needed to launch a project and I didn't have the time to go searching and hacking views.

It uses jquery, so users without JS will still have to click twice to get desc as default, in my situation that was an okay sacrifice. Thought I'd share...

$(".views-table th:not(.active)").children("a[title^='sort']").attr('href', function() { return this.href.replace('asc', 'desc'); } );
agileware’s picture

This issue should interest people in here - #810482: Use tablesorter jquery plugin for sorting table views

dawehner’s picture

Status: Active » Closed (duplicate)
kndr’s picture

Quick workaround #12, which works for me. Thanks!

fotfotfot2000’s picture

Issue summary: View changes

Quick workaround #12, it is not working with other language than English.
I am using
$(".views-table th:not(.active)").children("a[title^='trier']").attr('href', function() { return this.href.replace('asc', 'desc'); } );
as 'trier' is french for 'sort'.