Custom sorting with DraggableViews (Drupal)

September 17, 2014
Handle

When sorting on date or name isn’t granular enough, you can use DraggableViews which allows custom reordening. DraggableViews uses the handles we know from the back-end of Drupal, for example when we want to change the ordening of menu-items. 

In order to use DraggableViews, you need the Draggable Views module and the dependencies Chaos tools, Views and Entity API. 

Create a View for the end user

In this example we create a Page of Articles. The Page could also be a Block and the Fields could also be Content. 

DraggableViews Views Page

Create a Block next to the Page

Give it a clear name to separate it from the front-end content, for example ‘Draggable’ or ‘Ordering’. Follow these steps: 

  • Format: table (For: this block)
  • Add a Field: Draggableviews: Content (For: this block) and check ‘Ajax’ 
  • Add a Sort: Draggableviews: Weight (asc) (For: all displays) 

DraggableViews Views Block Draggable

Make the Block visible on the Page

Now, go to the Structure > Blocks interface and look for the ‘Draggable block’. Make sure it is under the main content block and choose to show the block only on the page of the View, in this case articles. 

Draggable Views Block ordening

Flush the caches to be sure it works. After reordering the articles, click Save and Refresh the page. 

DraggableViews on page

Add some access controls

In most cases: we want the Draggable Views block to be only visible for content editors and not for anonymous users. 

Go to the Draggable Views block settings (under Structure > Blocks) and check the Roles vertical tab. Show the block only to the roles of your choice. Test with this role and with an anonymous user. If this ain't working, set the permission at the Views level by choosing Access and limit the View to the roles of your choice. 

Comments

Thank you so much, some how it never occurred to me to place the sorting block, because when you create it as a view page, you can access the sort view from the gear ... the amount of time wasted in Drupal on stupid things you overlooked!

Thank you so much, this was really helpful..

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.