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?
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | drupal-table.png | 25.03 KB | deanloh |
Comments
Comment #1
merlinofchaos commentedCurrently 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.
Comment #2
richardhkirkando commentedThanks 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.
Comment #3
merlinofchaos commentedNot exactly, Views 2 uses its own tablesort implementation, I just copied the model so that the UI would be the same.
Comment #4
dawehneri 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"
Comment #5
infojunkieI 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:to
Comment #6
papricus commented1) 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.
Comment #7
dagmarComment #8
deanloh commentedThe 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.
Comment #9
Jerome F commentedIf 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.
Comment #10
Bilmar commentedI 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
Comment #11
deanloh commentedTo 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.
Comment #12
dsbrianwebster commentedThis 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'); } );Comment #13
agileware commentedThis issue should interest people in here - #810482: Use tablesorter jquery plugin for sorting table views
Comment #14
dawehner#428196: todo: default sorting of views tables
Comment #15
kndrQuick workaround #12, which works for me. Thanks!
Comment #16
fotfotfot2000 commentedQuick 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'.