The attached patch adds support for more sophisticated sorting scenarios. It allows each sorting instance to be attached to any draggable field. Previously when you added a sort to a view that includes a draggableviews field, that sort would be a "self" sort. After this patch, the same behavior is accomplished by choosing the same display from the list, but all displays are available.
This allows sorting by multiple draggable sorts in a single view. The example for which I wrote the fix was a view with a group by -- a list of entity A grouped by entity B. I needed to be able to sort both entity B as well as entity A.
This patch also fixes the draggable views code to use unique HTML IDs so those work. I believe this may also fix bugs that may arise on views with multiple sort/displays that would result from choosing the wrong (first) sort found instead of the intended sort.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | draggable_views_1514116_example-7.x-1.0.tar_.gz | 3.37 KB | fearlsgroove |
| #1 | draggableviews-multiple-sorts-1514116-1.patch | 9.49 KB | fearlsgroove |
Comments
Comment #1
fearlsgroove commentedComment #2
ygerasimov commented@fearlsgroove thank you for your contribution. I would immediately introduce usage of drupal_html_id() from your patch.
Regarding the groupped view, could you please provide example of the usecase when do you need this? I tried to avoid have possibility to set source display for views that do "sorting" (I mean to set "self" by default).
Comment #3
fearlsgroove commentedThe use case would be: say you've got content type foo and content type bar. Foo has a node reference to type bar. Create a view with the relationship foo > bar, add two title fields, one for the base content type foo, one with the relationship bar. Configure the view to group by title (bar).
Now say you want to sort both the parent bar and the category foo. Without this patch it's difficult -- you need to make a single ungrouped view then drag the entire list.
With this patch you can create two sort displays. The first display has a draggableviews field,and TWO draggable views sort. The first is the parent sort -- give it the relationship bar and assign the other draggable views display as the sort. The second is the "self" sort -- you'd select the one called identified with "this display." The result is a display grouped by the parent, sorted first by the parent, then by the children.
The second draggableviews display has no relationships, is filtered on bar and only sorts the items for bar.
I've attached a feature to demonstrate.
* Enable entityreference and features
* enable the feature
* Use devel generate to make 10 items of type bar, then make 50 items of type foo (in that order, to make sure the references to bar exist)
* visit /draggable-views-group-by-example -- note the multiple contextual links.
Comment #4
istryker commentedI have tested your feature and it works in the lastest dev.
I believe it was fix with this commit http://drupalcode.org/project/draggableviews.git/commit/a5e5103
The commit refers to #1900068: Replace 'self' reference with '$view->name:$view->current_display'
I was able to sort in one view, then the other. the page reflected both sort orders.
I am a little worried about #1899038: Need to add support for multiple draggable sort in one view display however this does not cause a problem. You are allow 1 draggableviews sort per sort order display. This gets a little confusing
In the feature the page display was first ordered by the bar sort order, then the foo sort order. The page display itself is not a sort order display.
Comment #6
istryker commented