Custom Sort Drupal Content with the Draggable Views Module
by Kronda Adair, Developer & Client Experience Advocate
In the world of sorting, sometimes 'newest first' or 'oldest first' just doesn't cut it. During a recent Drupal project, we had a client who wanted to be able to control the order of their marquee images in random ways via a drag and drop interface.
Enter the Draggable Views module. In about thirty minutes, I was able to set up custom drag and drop functionality for several content types on their site. Let's dive in and I'll show you how it's done. If you prefer a video tutorial, skip to the end of this post.
Before You Begin
Make sure you have the lastest version of Views and also download the Draggable Views module.
The trick to getting the magic to happen is setting up two cooperative views. The first view shows your content in whatever way you have determined. The second view is created strictly to determine the order of that content.
Views Keeps Improving
In the time since I first used this module just a few weeks ago, the module has been upgraded to allow for using a different display on the same view, rather than two separate views, which makes matters even more tidy.
In my example, I started with my trusty page of kitten photos, created by this view:

From here you can just clone the original view and make a few changes:

Rename the display to differentiate it from the normal content view.

Change the Format setting to 'Table'. Remember to override the default view if your original setting is different.


Under Fields, add the draggable views field that will determine the sorting order.



Under Sort Criteria, remove the default sort option and replace it with Draggable views weight

Now go back to your original content view. Under Sort Criteria, add the Draggable Views weight just like you did in the sort display. This time, in the options you should see 'Display Sort As'. Choose the sorting view you created. Any other sorting views you create will populate the drop-down list here. (Don't forget to use the override setting so you don't affect the sorting view settings).

You should see a preview of your table view with the draggable weights on the far left.
You can reorder the rest of the fields to suit your needs. I like to put the photo first, since that is the easiest to recognize.

Happy sorting! Now go shuffle some kittens.
Comments
How this differs from nodequeue module
Posted by Jesus Manuel Olivas on . [Reply]
How about when adding a new node:
-Do you need to get back to the view and rearrange order.
-User/Editor need to have access to edit view.
Best Regards
Jesus Manuel Olivas
@jmolivas
By default no, you can't
Posted by Kronda Adair on . [Reply]
By default no, you can't custom order from a new node add form, but once you go back to the content view, you get an extra contextual link for ordering the view.
And yes, the editor would need access to views. That would be a good addition to make those separate permissions somehow.
Permissions
Posted by Roberto Ornelas on . [Reply]
Nice tutorial! Yesterday, i used DraggableViews on a project, and i'm big fan already :)
At least on the 7.x-2.x branch, users only need the "Access draggable views" permission to use DraggableViews.
That was fast, thanks for
Posted by Jesus Manuel Olivas on . [Reply]
That was fast, thanks for your answer
Jesus
draggableviews
Posted by fndtn357 on . [Reply]
Is this better (less memory usage - db calls) to use this method over Nodequeues?
@ fndtn357,
Posted by Kronda Adair on . [Reply]
@ fndtn357,
I have no idea. I asked our senior Drupal tech lead and he didn't know either. If you end up running any tests, let us know what you find!
Comparison of Node Ordering Modules
Posted by Jesus Manuel Olivas on . [Reply]
This may be of interest http://drupal.org/node/398508
link to node ordering options
Posted by fndtn357 on . [Reply]
thanks for the link
@Roberto,
Posted by Kronda Adair on . [Reply]
@Roberto,
I just tried taking off 'administer views' permission while leaving on the 'access draggable views' permission and it doesn't work. I'm on Views 7.x-3.x and Draggable Views 7.x-2.x.
I may experiment with trying a more lenient access permission in the particular view itself. Thanks for the comment.
I'm using DraggableViews 7.x
Posted by Roberto Ornelas on . [Reply]
I'm using DraggableViews 7.x-2.x-dev and Views 7.x-3.1
One advantage of DraggableViews over Nodequeue
Posted by Jesus Manuel Olivas on . [Reply]
Sorting a list of nodes assigned to a taxonomy.
Re: One advantage of Draggable Views over Nodequeue
Posted by fndtn357 on . [Reply]
Smartqueue taxonomy adds all taxonomy terms into views for you automatically.
Weight works too
Posted by Joonas Meriläinen on . [Reply]
A while back I tried out different ordering modules and then Weight was the only one which worked the way I wanted. It has also stable release available.
How to highlight the selected rows?
Posted by Salem Almarri on . [Reply]
Hi Kronda, your post and the screencast were awesome, thanks so much you made us better drupalers :) .
I have one BIG question,
I noticed at the beginning on the demo site,
there is a thick dotted horizontal line below the enabeled rows seperating it from the rest of rows which are dimmed.
how can I do that ?
JQuery
Posted by Dan Linn on . [Reply]
This was a small snippet of jQuery we added that adds the dotted line and fades the ones below :)
Any know how implement in
Posted by Ajedrez Tandil on . [Reply]
Any know how implement in custom module a views_handler_filter_draggable?
Tks!
drupal
Posted by venki on . [Reply]
HI,
Not able to reorder cck fields delta values in dragabble views .
Please help me,any help will be appreciated!
no delta support
Posted by Dylan Tack on . [Reply]
Support for field deltas is not provided by this module, though there's an open issue at http://drupal.org/node/877162.
Hi Dylan,
Posted by venki on . [Reply]
Hi Dylan,
Is there any alternate solution for this?
Add new comment