You can sort in table views. But about 99% of the stuff I am working with for clients requires list views, but they still want users to be able to sort by things like author, date, etc.

It would be nice if, in addition to the standard paging, if you could easily have sort links appear for users in list views.

Is this here, and I'm just completely mad?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

This doesn't exist yet, but it will.

CoolDreamZ’s picture

I have a similar requirement (but don't need to expose the ability to the user). I would like the sort order of items in the list to be controlled via one of the fields in the view. Also, will this functionality be back-ported to 5.x ?

merlinofchaos’s picture

CoolDreamZ: While I'm not sure precisely what you mean, I don't think what you ask is possible.

CoolDreamZ’s picture

Thanks, in writing up a more detailed explanation I have discovered that there is another configuration setting for a View. At the bottom of the View Edit page there is a collapsible section titled Sort Criteria. I added the required criteria here and voila I now have a List View sorted as I wish! So my requirement is fulfilled (but not that of the original post).

merlinofchaos’s picture

That's also for VIews 1.0 and this issue is against Views 2 =)

merlinofchaos’s picture

Just a note; I've pushed this feature back to Views 2.1. Sorry.

merlinofchaos’s picture

Assigned: Unassigned » merlinofchaos
capellic’s picture

OK, darn! Thanks for all your work on this - it's a really great module.

I noted your suggested work around way back in 4.7 that we should create a clone view and then change the sort order. Then we can put links in a block, the view header or where ever we want.

hansamurai’s picture

I am also in support of exposing sorts, so hopefully it gets into 2.1! Thanks!

giorgio79’s picture

Yep, I was just looking for this as well :)

greg.harvey’s picture

+1 !!! =)

tuti’s picture

Also looking for this.. nice to hear that it's in the works!

arhak’s picture

subscribing

emattias’s picture

I just installed 2.1. Has the feature been pushed forward or have I missed where you expose the sorting?

dropchew’s picture

subsribe, not just in list, hope to see this in grid too.

pcambra’s picture

suscribe, very interesting feature

Barry Ramage’s picture

subscribing also.

japanitrat’s picture

sounds great

sbydrupal’s picture

Based on the messages, Exposed Sort Funtionality will be available ? Which version of Views is targeted now, or is it dropped out of picture. Thank Merlin!!! Looks like we depend on you and you are very busy.

associate’s picture

could do with this feature also.

sbydrupal’s picture

Until the Sort Views Functionality becomes available, I am trying to find a way sort search results (or taxonomy/term/tid) via Views and Tabs.

Created a view for search results (default drupal search) with taxonomy term as argument, and
return arg(2) as php code. It works fine and I can sort this view in the way I want.

However, this way, I can set only 1 view.

The path for this view includes % parameter (related to the argument) and as such Views Menu tabs can not be set.

This is the point I stopped. What is the next step ???

Tried to use Quick Tabs, no result so far.

Any suggestions ?

Thanks,

yhager’s picture

As a workaround, one could hack one of the views_alter hooks to change the sort order (e.g. based on an HTTP GET value) - but I haven't tried that yet.
Another possibility is to write a filter that does not filter, but only sorts (then you can expose it). I did that back in views1 and it kinda worked - not sure if this is still possible in views2.

sbydrupal’s picture

Thanks for the feedback. I was thinking to try exposed filters for this purpose. Will post if works somehow.

The other solution I found this morning is by using Quick Tabs along with Views. There is a patch that allows passing views arguments with %. Currently it worked with Taxonomy/term/tid and I will check to see for Sorting Search results with multiple tabs. Will post if works.

Harry Slaughter’s picture

+1 for sortable list (and grid) views!

seanenroute’s picture

just subscribing, would love to have this feature

gunzip’s picture

subscribe.

q0rban’s picture

subscribing, and also echoing the requests for Grid sorting as well.

blup’s picture

subscribing

merlinofchaos’s picture

The next person who posts to this issue had better post a patch, because it doesn't do anyone any good post 'Yea me too" to this issue. Yes, we know you want it.

dawehner’s picture

FileSize
7.19 KB
19.54 KB

subscribing, sry just kidding :)

i worked now a little on the patch, its not a even a first development version, just playing around

one problem is that i cannot get a table in the style options, see the attachment

doublejosh’s picture

My work around is to manually case some sorts the PHP header of a view...

$view = views_get_view('uc_products');
//drupal_set_message('<pre>'.print_r($view->display['page_1']->display_options['sorts'],1).'</pre>');
if (arg(1)=='popular') {
 $view->display['page_1']->display_options['sorts']= array(
  'totalcount'=> array(
    'order' => 'DESC',
    'id' => 'totalcount',
    'table' => 'node_counter',
    'field' => 'totalcount',
    'override' => array('button' => 'Use default'),
    'relationship' => 'none',
   ));
 $view->save();
}
elseif (arg(1)=='new') {
 $view->display['page_1']->display_options['sorts']= array(
  'timestamp'=> array(
    'order' => 'ASC',
    'id' => 'timestamp',
    'table' => 'node_counter',
    'field' => 'timestamp',
    'override' => array('button' => 'Use default'),
    'relationship' => 'none',
   ));
 $view->save();
}
//drupal_set_message('<pre>'.print_r($view->display['page_1']->display_options['sorts'],1).'</pre>');

(Left in some commented debugs in case you need them to track down the sort array values you need to push in.)

RAFA3L’s picture

subscribing

danSamara’s picture

subscribing

KarenS’s picture

I've done some work on this and ran into the fact that even if you get this working Views won't display it because there are places in the Views code that expect all exposed forms to be filters. So I created #458140: Allow any handler to use exposed form to get that fixed.

Once that is in, we can build a sort form similar to the one used by the filter and it will have the option to select a sort and then choose to expose or not expose the form, just as filters do. I have some preliminary code to do that, but am waiting to be sure what is going to happen to the other issue.

KarenS’s picture

FileSize
7.01 KB

Here's the preliminary, broken patch for adding an exposed sort, based on the Views patch mentioned above. This is just to see how the patch would be implemented for the sort handler. Several things need to be worked out yet like how to handle multiple sort fields and all you can do so far is select a sort, it won't actually do anything with that information.

dixon_’s picture

subscribing

Xabi’s picture

Subscribing! This would be a great feature!

rjbrown99’s picture

Sign me up as a tester for this - especially now that the initial patch is in the 3.x branch.

Heilong’s picture

Subscribing.

Nchase’s picture

Subscribing

perke’s picture

Subscribing

SocialNicheGuru’s picture

subscribing

aclight’s picture

While working on the port of the project module for D6 and Views 2, I wrote an exposed filter handler that acts as an exposed search box. The code for that handler can be found in project_handler_filter_project_sort_method.inc. KarenS's patch in #35 kind of looks similar, but I didn't look in detail.

Caveat: The last time this code was tested was probably some time ago, maybe around Views 2.2 or so. It's possible that it no longer works with the current version of Views.

Kane’s picture

Subscribing

CKIDOW’s picture

subscribing

EgbertB’s picture

Subscribing

vincent.barbot’s picture

Subscribing

dawehner’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev
Issue tags: +views 3.x roadmap

adding a tag and pumping to 3.x

solipsist’s picture

The Views Display Tabs module sidesteps this missing feature by exposing the displays of a view as AJAX tabs. We developed it to address this particular feature. The original idea was to expose sorting but we figured exposing an entire display was way more generic and useful:
http://drupal.org/project/viewsdisplaytabs

maxiorel’s picture

any other news?

marcoka’s picture

need that feature, too ..subscribing

dagmar’s picture

Status: Active » Needs review
FileSize
7.25 KB
8.11 KB

I have created a patch based on #35

It is working for now. But probably need some work yet.

I'm not sure if we have to display an select for each exposed sort. It is a bit confusing. And users can not select the order of application for sorts.

Maybe implementing a new exposed form plugin we can get a list of sorts like this the attached image. See #535868: Exposed forms as plugins

dagmar’s picture

+++ handlers/views_handler_sort.inc	2 Sep 2009 15:53:08 -0000
@@ -10,52 +10,264 @@
+    if (!empty($sort) && $sort == 'asc' || $sort == 'desc') {

Oops, wrong operator precedence.

New patch.

mattiasj’s picture

Testing this out.

parrottvision’s picture

subscribing

dagmar’s picture

Title: Exposed Sorts » Ability to sort in list views
FileSize
8.8 KB

Ok, new patch.

Random Sorts shouldn't be Exposed.
Some improvements in usability.
Small bug fix.

People, please stop "subscribing" and test this patch.

For testing:

#Download the patch
wget http://drupal.org/files/issues/views-228510-exposed-sorts.patch 

#apply the patch
cd sites/all/modules/views
patch -p0 < views-228510-exposed-sorts.patch

This patch is valid for 2.x and 3.x views version.

We need also a solid method to check if an identifier is duplicated into a same views.
Since exposed sorts also use ids in url, a exposed sort for a node nid, and a expose filter for a node nid will have the same node_nid id.
By now , I'm using an "_sort" suffix to avoid collisions.

More information about this issue. See #363516: No validation to ensure exposed filter identifiers are unique

dagmar’s picture

Title: Ability to sort in list views » Exposed Sorts

Exposed sorts works for other style plugins that only lists. Changing title.

rizqi’s picture

#56 Hi Dagmar thank you for the patch, iam using views 2
i found this error when i want to add sort of "Node: Last comment time"

Fatal error: Call to undefined method views_handler_sort_date::show_expose_button() in /home/inkuiri/public_html/sites/all/modules/views/handlers/views_handler_sort.inc on line 27

dagmar’s picture

@rizqi: Thanks for try the patch. I make a mistake, this patch is not compatible with views 2 since #458140: Allow any handler to use exposed form was not commited to 2.x branch.

You have to apply both patches to get this working.

However, maybe views 3 is the right way to test this patch, then we can backport this later.

jrao’s picture

Title: Ability to sort in list views » Exposed Sorts

subscribing

vgarvardt’s picture

FileSize
20.24 KB

@dagmar: I applied this patch to views 2 with minor modifications. It works fine for exposed sort, but sort that is not exposed does not work at all. Also default sort is not applied when exposed filters form is not submitted.

Here is my backported patch for views 2

dagmar’s picture

Status: Needs review » Needs work

... but sort that is not exposed does not work at all

So, we have to fix that. Changing status.

@vgarvardt: Thanks for your review. I think that we should code this feature for views 3. When is ready, we can backport it into views 2.

d.plinsinga’s picture

Thanx, this helps my for a great part.

dagmar’s picture

Status: Needs work » Needs review
FileSize
13.85 KB

I have reviewed this patch again. There is a lot of changes. Please if you build a backport for views 2, use this patch.

Changes from #56:

  • Changed 'order' by 'sort' in date and random handlers.
  • Added Docs into Advanced Help. (please review, I don't speak english very well)
  • Removed 'unordered' string from Random sorts, it isn't necessary
  • Fixed #62

To test this patch, please, create a new view. hook_update_N() is not implemented yet and previous sorts will not be recognized.

I'm marking this as "needs review" if no problems are detected I will code the update script.

dafeder’s picture

Well, I created a new view, went to add a sort and when I hit "update" I got a JS alert dialog:

An error occurred at http://mydomain/admin/build/views/ajax/add-item/expose_sort_test/default....

I hit OK and am unable to update.

dagmar’s picture

@dafeder are you using views 3?

If yes, please deactivate javascript and copy the complete message error.

dafeder’s picture

Ack, my bad. Got my patches confused. Trying the views 2 version now.

dafeder’s picture

Patch from #61 adds the exposed sort to the form but it has no effect when changed and submitted. I'm a little confused though on whether I needed to apply http://drupal.org/node/458140 also.

I wonder if we should break this into two separate threads, one for Views 2 and one for Views 3?

dagmar’s picture

So, new patch. For easy testing I have created two version. For Views 2 and Views 3.

This patch has some nice improvements from #64.

  • Don't require update script, so you can expose existent sorts in your views.
  • Date and formulas sorts can be exposed.

If you are going to test this patch in views 2, probably you get something like:

Hunk #1 succeeded at 957 (offset 1 line).
patching file handlers/views_handler_filter.inc
patching file handlers/views_handler_sort.inc
patching file handlers/views_handler_sort_date.inc
patching file handlers/views_handler_sort_formula.inc
patching file handlers/views_handler_sort_random.inc
patching file help/sort.html
patching file includes/handlers.inc
patching file includes/view.inc
Hunk #1 succeeded at 571 (offset -7 lines).

This happens because the patch is build against 2.x version and stable version of views is 2.6. Anyway the patch apply without problems.

@merlinofchaos: I have a question about views_handler_sort_menu_hierarchy.inc. It can be exposed? Is really useful?

dagmar’s picture

By the way. Patch for 2.x includes #458140: Allow any handler to use exposed form so it isn't necessary apply both patches.

merlinofchaos’s picture

Ok, I just took a quick look at this.

One of the reasons that I never implemented this functionality as is has to do with the typical use-case. If you look around at websites that implement exposed sorting, it is usually a single select box. Often you'll find something that looks like this:

Order by
Name
Date
Color
Etc

Direction
Up
Down

You select one and a direction. Yes it is not as flexible as selecting several (but then, with this as it is you can't re-order them, so selecting several doesn't really do it).

I think this is the most important use-case to solve. So I'm a little hesitant about this version of the patch.

dafeder’s picture

Good point merlin. That is certainly the ideal scenario for me, and what is evolving here is much better than nothing but certainly not the most intuitive thing... for instance, if the list style (and/or others) had options similar to the table style's options, with fields that can be sortable having checkboxes. If one or more is checked, some widget is added to the top of the view allowing us to sort.

The ideal thing would be that, if we have exposed filters, it could be part of the same form, so that it would be submitted with all the changes to filters. A way around this might be to add a row of links similar to the headers of a table. But I'm not sure how intuitive that is on a view that doesn't have columns. Maybe just a second form, laid out in such a way it's obvious that it needs to be submitted separately from any filters, would be a good start though.

Trying to think if this could be accomplished with a contrib module ("sortable list" or something) or if views needs to be patched necessarily.

merlinofchaos’s picture

The style doesn't *have* to be involved in the tablesorting -- mostly it's the fields that do the real work and the style is just a middleman. We could move that out of the style and make it a global option.

dagmar’s picture

FileSize
27.14 KB

One of the reasons that I never implemented this functionality as is has to do with the typical use-case. If you look around at websites that implement exposed sorting, it is usually a single select box. Often you'll find something that looks like this:

To do this, we need to delegate the sort in other class different than handlers. This is because handlers can't know which element is defined to sort all the query.

Also, at this moment, there isn't a solid way to alter the query from some Exposed Form object.

I'm working in #535868: Exposed forms as plugins to allows exposed forms alter the views query.

So, what I did was merge both patches (with modifications) to allows exposed forms to generate the select box with all the exposed sorts and apply only one when is selected.

This patch is for views 3. And introduces 3 new plugins, so probably need a big revision before port it into views 2.

merlinofchaos’s picture

This probably won't be targeted for Views 2 in any case.

dagmar’s picture

Relloled since #535868: Exposed forms as plugins was commited. I'm attaching a screenshot of what this patch does.

Omar Alahmed’s picture

Thanks dagmar for this great patch. I executed views-2-exposed-sorts-228510-69.patch "#69", it worked perfectly, but i wanted the style that you attached in the screenshot views-228510-exposed-sorts.patch "#76".

I tried to execute the last patch views-228510-exposed-sorts.patch" "#76" but it seems that it's for views 3. Do you intend to do it for views 2? If you did many people will appreciate it especially me.

Thank you in advance.

merlinofchaos’s picture

Sorry, Views 2 will not receive this functionality.

Bilmar’s picture

tested patch @ #76 several days ago and it worked great =)
very excited to see this new feature!

Bilmar’s picture

received the below errors when patching:

patching file views.module
Hunk #1 FAILED at 984.
Hunk #2 FAILED at 1063.
2 out of 2 hunks FAILED -- saving rejects to file views.module.rej
patching file handlers/views_handler_sort.inc
can't find file to patch at input line 280
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: plugins/views_plugin_exposed_form.inc
|===================================================================
|RCS file: /cvs/drupal-contrib/contributions/modules/views/plugins/Attic/views_plugin_exposed_form.inc,v
|retrieving revision 1.1.2.1
|diff -u -p -r1.1.2.1 views_plugin_exposed_form.inc
|--- plugins/views_plugin_exposed_form.inc 11 Nov 2009 01:42:53 -0000 1.1.2.1
|+++ plugins/views_plugin_exposed_form.inc 11 Nov 2009 03:19:16 -0000
--------------------------

merlinofchaos’s picture

I don't think you have the latest views 3 dev, which is why the patch is not applying.

dagmar’s picture

So, here is a new patch. I am very pleased with this patch because it comes with:

  • A views_sort_handler.inc file very similar to views_filter_handler.inc
  • Options to modify the "Asc" and "Desc" string to strings like "Up" and "Down" for exposed sorts
  • The patch was refactored to work with the last patch #503452: Retool exports to drill down properly
  • It uses Exposed forms plugin to work. This plugin is altering the exposed form so, it can be easily overrided by a new exposed form plugin

This patch is dependent of this two patches marked as RTBC:
#645150: Call to undefined method views_plugin_display_page::get_exposed_form_plugin()
#645146: Filters cannot be exposed anymore after "Retool exports to drill down properly"

And again, this patch is for views 3. Please don't apply to views 2 because you will get something like #80.

In my opinion this patch is 95% ready, so please test it and give me your comments.

Bilmar’s picture

ahh - I got the folders mixed up when patching so I thought it may have been the several week gap that resulted in changes.

using the correct version: views 6.x-3.x-dev

I first applied the dependent two patches - both successful

1st #645146: Filters cannot be exposed anymore after "Retool exports to drill down properly"
patching file plugins/views_plugin_display.inc
Hunk #1 succeeded at 1963 (offset 7 lines).

2nd #645150: Call to undefined method views_plugin_display_page::get_exposed_form_plugin()
patching file handlers/views_handler_filter.inc
patching file includes/admin.inc

But then with views_exposed_sorts-228510.patch i get the following result. Is this expected?

patching file handlers/views_handler_sort.inc
patch: **** malformed patch at line 171: Index: plugins/views_plugin_exposed_form.inc

dagmar’s picture

Yes, sorry I deleted parts of the original patch because it was including the other patches. And probably I deleted more than I should.

Here is a reroll.

Bilmar’s picture

Hello dagmar,

Thanks for the reroll. Patching was successful, however on re-activately the Views module I got this fatal error:

Fatal error: Call to undefined method view::render_exposed_form() in /home/example/public_html/drupal/sites/all/modules/views/plugins/views_plugin_display.inc on line 2083

Found your patch that looked like it may be for similar issue http://drupal.org/node/639094#comment-2291180
But patching resulted in the below result:

(Stripping trailing CRs from patch.)
patching file plugins/views_plugin_display.inc
patch unexpectedly ends in middle of line
Hunk #1 succeeded at 2079 with fuzz 2 (offset 6 lines).

Hope this information helps. Thanks!

dagmar’s picture

Here we go again...

This patch is a rerroll and includes some small changes that take advantages of the exposed_form_alter() function introduced into exposed forms plugins.

To test this patch you only need the last version of views 3, no extra patches are needed.

dawehner’s picture

Some thoughts:
Would it be possible to Display the sort order before the other exposed filters?

+++ views.module	3 Dec 2009 21:28:03 -0000
@@ -994,7 +994,7 @@ function views_exposed_form(&$form_state
-    '#value' => t($form_state['submit_button']),
+    '#value' => t('Submit'),

Why do we force it to be submit?

I did exposed a lot of sorts and they worked like a charm. I guess the documentation should be updated. Thats a killer feature :)

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Update status, too.

dagmar’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
10.48 KB

Rerolled because #99370: Add a 'reset' button to exposed filters was committed.

Why do we force it to be submit?

This was the old mechanism of views. Now this feature is implement using exposed_form_alter() function.

dagmar’s picture

This patch check if 'reset' button is active and move it to a better position in the exposed form.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Works fine again.

vgarvardt’s picture

FileSize
25.04 KB

Here is updated patch from #69 that applies to Views 2.8

dagmar’s picture

@vgarvardt: Thanks for the patch. However, because this issue is marked as RTBC I have to make a note about this.

Exposed sorts were finally implemented using a new kind of plugin that will not be available in view 2. So when you are installing patch #92 your are in fact applying (at least) to views 2 all this patches:

#458140: Allow any handler to use exposed form
#535868: Exposed forms as plugins
#633482: pre_execute is never called on exposed forms plugins
#639094: Exposed Forms do not work?
#645150: Call to undefined method views_plugin_display_page::get_exposed_form_plugin()
#99370: Add a 'reset' button to exposed filters

As you can see, there is a high risk that this not work as you expected into views 2. So, the status of "Reviewed & tested by the community" is for patch #90. And this backport to views 2 is complete untested.

Bilmar’s picture

#90 worked great! Patched with no problems, easily exposed some sorts and I like how we are able to easily change the text for ascending/descending and labels.

I wasn't able to locate the string to translate the Asc/Desc to other languages though..will continue to try. Thanks!

dagmar’s picture

Issue tags: +alpha-2 blocker

tagging

xsean’s picture

subscribe

dawehner’s picture

I testet it for fun again, it is really cool.

ddorian’s picture

yes works here too +1

merlinofchaos’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

#90 committed to the 3.x-dev branch. needs to be ported to 7.x

I created to follow-up issues to this:

#666870: Exposed sorts do not properly default and #666874: Exposed sort order by field needs some work

cerup’s picture

Subscribing

joachim’s picture

Another followup: #670388: don't show exposed sort selector when only one sort is exposed.

And a meta-issue: there's an issue component 'exposed filters', so one for exposed sorts might be needed too.

dgastudio’s picture

subscribe

cerup’s picture

-removed-

merlinofchaos’s picture

cerup -- your question does not seem relevant to this issue. Please post your question as a separate support request.

ManyNancy’s picture

Is this going to go into 2.9 or should we upgrade to 3.x if we want this?

dawehner’s picture

I guess, this will not go into 2.9, because it needs also exposed form plugins and other stuff.
If you really want it you can try out 3.x or use some workarounds available out there(custom code)

merlinofchaos’s picture

I have feature frozen the 2.x line, so it will not be going into any Views 2 version.

dawehner’s picture

Issue tags: -views 3.x roadmap, -alpha-2 blocker

remove tag.

chx’s picture

Status: Patch (to be ported) » Needs review
FileSize
10.96 KB
dawehner’s picture

The same bug: http://drupal.org/node/698270#comment-2537800

I'm not sure how to solve it.

dawehner’s picture

Status: Needs review » Fixed

commited.

thx!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

prabhakarsun’s picture

I used this method mimic sorting for views 2:

1. Create A View for search.
2. Add different page displays for each sort criteria.
3. Add below code to the header of view, selecting PHP input.

<?php

$newurl = str_replace($_GET['q'], '', $_SERVER['REQUEST_URI']);

?>
Sort By: <a href="/find-by-distance<?php print $newurl; ?>">Distance</a> | <a href="/find-by-rating<?php print $newurl;  ?>">Ratings</a> | <a href="/find-by-popularity<?php print $newurl;  ?>">Popularity</a>

Ofcourse, links need to be changed.

Also it doesn't work where request uri returns full URL, like domain.com/someurl/, and needs clean URLs. Otherwise you may need to explode it to get $newurl

Hobbes-2’s picture

subscribe

xqi’s picture

subscribing

davepoon’s picture

subscribe

jeffsawyer’s picture

looking for more information on this feature... subscribing. Is this workaround a good way of handling it? http://stackoverflow.com/questions/2471361/drupal-sorting-a-view-program...

shopdogg’s picture

sub

171mayank’s picture

I think this may be more usefull:

function Hook_views_query_alter(&$view, &$query) {
// fyi, anonymous sessions need a record in the user table of 0 to work at all....
  if ($_SESSION['pref']['state_color'] == 'red') {
    // we'll have to do the less popular red query
    // which's key is [1] (weighted second in the views sort order interface)
    unset($query->orderby[0]);
  }
  else {
  // otherwise, don't do the hill billy logic at all....
    unset($query->orderby[1]);
  }
}
YK85’s picture

Is it possible to make exposed sort optional?

I have added one exposed sort to my view but would like to make it optional.
At the moment it is the only sort that is shown in the dropdown select list so therefore not optional.

Thanks!

stella’s picture

FileSize
50.41 KB

Here's a patch reroll of the version in comment 92 above for views 2.11, just in case anyone still needs it for D6

Daniel Wentsch’s picture

Subscribing.

sepla’s picture

subscribing..

mstef’s picture

@stella: thanks but patch contains a patch for itself and fails against 2.11 for views.module

mstef’s picture

seems that when in a table with ajax on, they don't work..ajax on and html list works fine

mstef’s picture

FileSize
6.54 KB

Great work on the patch, but I'm not a fan of the front-end ui.

I don't like how there are multiple select widgets, each with asc/desc options. I think there should be one select (with each sort as an option) and a toggle for asc/desc. See attached.

vistree’s picture

Version: 7.x-3.x-dev » 6.x-2.11

Hi, does the patch #121 works for 2.11 even there is this warning message for views.module??

greg.harvey’s picture

Version: 6.x-2.11 » 7.x-3.x-dev

Please don't change version.

merlinofchaos’s picture

Apparently #107 was not crystal clear.

Please do not hijack issue versions.
Please read the entire issue before you ask questions that are already answered in the issue.

merlinofchaos’s picture

Assigned: merlinofchaos » Unassigned
kndr’s picture

I've found workaround, which works quite good for me.

  • Assume, we have MY_VIEW and want to sort it by "creation date" and by "total count" (module statisticts)
  • Assume, url in page display for MY_VIEW is "my_view".
  • Assume, sort order will be given in querystring: "my_view?sort=created" and "/my_view?sort=totalcount"
  1. Add both sort criteria in MY_VIEW - by created and by totalcount
  2. Add argument GLOBAL:null
  3. Choose PHP validator for this argument
  4. Inside PHP validator - remove all unwanted objects when "sort" variable is set:
    switch ($_GET['sort']) {
      case 'created': 
        unset($handler->view->sort['totalcount']);
        break;
      case 'totalcount': 
        unset($handler->view->sort['created']);
        break;
      default: break;
    }
    return TRUE;
    

Notice1: Insert "dpm($handler)" in PHP validator to find name of sorting objects, which should be deleted.
Notice2: Sorting criteria in page display should be overwritten. It builds sorting objects, which we can delete.

Now, we can put links "my_view?sort=created" and "/my_view?sort=totalcount" into MY_VIEW header.

Please let me know if this solution has drawbacks .

Luciuz’s picture

cute

knigh7’s picture

sub

knigh7’s picture

I had a similar requirment, the way i did it was to turn the sortable items (authors ect) into taxonomy and then use arguments.

yurtboy’s picture

Hello,
Just wondering if this is being worked on for Views for Drupal 7?
If not it would be willing to give it a go but did not want to try at it knowing someone on the team is already at it?
Thanks

pcambra’s picture

yurtboy please see #111 this was committed in D7 almost 20 months ago.

yurtboy’s picture

thanks pcambra
now for the infamous question is there one for d6 ( -:

NIKS_Artreaktor’s picture

can anybody help?

How to display in form exposed sort filters AFTER exposed filters?

Thanks.

marcoka’s picture

definitly the wrong thread to ask that....
but take a look at views templates to do that...

NIKS_Artreaktor’s picture

yes, i understand, that in views...tpl I have array of widgets.
But how to revers sorting and display them in that way.

Robin van Emden’s picture

The 6.x 228510.patch (#92, #121) introduces a bug that breaks random sort by appending "ORDER BY _random UNSORTED" to the generated query.

Encountered the problem in Drupal Commons 2.3, which used to apply this patch by default. Latest Drupal Commons 2.x no longer applies it though, so problem went away for me:
http://drupal.org/node/1342452
http://drupal.org/node/1302984

Yet info might still be of use to others.

a.milkovsky’s picture

sub

tstackhouse’s picture

#141 is correct, I too have encountered this problem in Commons 2.3, adding one line to views_handler_sort_random.inc corrects it:

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
	$form['order']['#access'] = FALSE;
  }

becomes

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
	$form['order']['#access'] = FALSE;
	$form['order']['#default_value'] = 'ASC';
  }