Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
i'm facing a problem - i've got a view with exposed filter and exposed sorting
but i also have a custom sorting (draggableviews weight), which isn't and can't be made exposed.
what i need is to use draggableviews sort as default - before user applies exposed sort order. but whatever i've tried, only exposed sorting is respected.
i've tried setting $form_state['input']['sort_by']='weight' in the hook_form_alter but then the view throws an error with no results.
can someone please point me in the right direction. thanks.
ps: i also created an issue in the Views http://drupal.org/node/1813744
Comment | File | Size | Author |
---|---|---|---|
#2 | draggableviews-views_handler_filter-1813747-2.patch | 629 bytes | iStryker |
Comments
Comment #1
iStryker CreditAttribution: iStryker commentedSo you would need to add
'filter' => array(
'help' => t('filter out a weight(s)'),
'handler' => 'views_handler_filter_numeric',
)
to $data['draggableviews_structure']['weight'] in draggableviews.views.inc file
I do not see a use case for this so I'm closing it. Plus the values will be displayed incorrectly until #1901192: Row weight values range should be the same as what gets save to database is fixed.
If you are having trouble with expose filters. See Issue #1902536: How things work when you have one or more exposed filter
Cleaning up issue queue. Reopen if this is not the case.
Comment #2
iStryker CreditAttribution: iStryker commentedPatch attached. If anyone finds a use case for this and wants this committed, please comment.
Comment #3
Fernly CreditAttribution: Fernly commentedThis seems like a very common situation...
Products are displayed in a custom order by choice (draggableViews) when the customer enters the web shop. The customer needs to be able to reorder the products by title, price, ... .
At the moment, the other sort criteria which are exposed are overruling the DraggableViews weight right at the page load. The DraggableViews weight becomes unused here.
I also don't see how the 'filter' patch in #1 end #2 fixes this problem, as it is a sorting issue.
I'll be looking for a solution and when I found one I'll post it over here.
Comment #4
Fernly CreditAttribution: Fernly commentedI got it to work, but it's still not really a default option in the module. Also, I'm using one contextual filter "term id" in my example.
The trick is to make only the contextual filter count through the 'Prepare arguments with PHP code' option of the Draggableviews native weight sort:
PHP code to prepare arguments on the sorting display:
All existing arguments can be found in $arguments. I only return a new array containing the contextual filter which is a taxonomy term in my case.
PHP code to prepare arguments on the actual front-end display:
$_GET gives 1 when there are no parameters in the URL. As soon as the user uses exposed filters, the altered array will not be returned and the draggableviews sorting will not be applied. The draggableviews sorting is only applied when the matching arguments are presented.
The draggableviews sorting is not exposed, but will be used as default sorting until other exposed filters are used.
A real solid solution is still welcome...
Comment #6
markdcI vote to reopen this because I have a very practical use case for this feature.
I'm creating a task management application. I have a list of Tasks that users can sort by priority, due date, etc. Since they are also able to manually sort the Tasks with the help of this module, it would be expected that "Sort Manually" is an option in the Exposed Sort dropdown.
From a UX perspective, with no way to revert back to manual sorting, Draggable Views becomes unusable for this part of my project. I'll follow this issue and hope someone comes along with a fix. If I had time, I'd learn PHP and offer to help myself.
Otherwise thanks for this module. I can at least use it to sort simpler checklists within my Tasks.
Comment #7
mrchristophy CreditAttribution: mrchristophy commented+1 I want to do this right now