Hướng dẫn Sorting Views với module DraggableViews trong Drupal 8

Hướng dẫn Sorting Views với module DraggableViews trong Drupal 8

Views are the most significant part of a Drupal website. Almost every Drupal site uses one or more views to list their content. The Views module is a Drupal 8 core module that manages these lists of content. You might run into situations where you need to sort these views. Currently, there are very few options to sort view items. You can only choose between simple date sorting, alphabetical sorting, and few more. Also, the sorting will be content specific and depends on the value of each content. To overcome these issues, we can use the simple table drag option provided by the DraggableViews module in Drupal 8. It is easy to configure and manage for the site administrator or editors. In this article we will be configuring the DraggableViews module for a Drupal 8 website. 

Installing the DraggableViews Module

Let’s get started by installing the module. You can download and install the Draggable views module from here or from the composer. Download and extract the file and then place inside your project directory. Alternatively, you can also use composer to download with this command

composer require drupal/draggableviews

Next, go to Extend and enable the module. You can also use drush to enable the DraggableViews module. Always ensure you have the latest version of Views installed before you start.

Configuring the DraggableViews module for drupal 8

Draggbleviews will provide drag and drop options for each row like how we drag and drop blocks or taxonomy terms. This is possible because of the tabledrag.js javascript that is used by these modules. Similarly, DraggableViews module uses the table formatted view display for using the core jquery feature from tabledrag.js which will allow you to drag and drop the HTML tables.

nguoi mau tuong vy

Steps to reproduce

  • Create a view
  • Create a Draggable view display
  • Add a menu link for easy navigation
  • Setup the permissions

1. Create a view:

First, let us create a view for listing content of any content type as required for your website. Add the necessary settings needed for the view. Make sure you remove the existing sort criteria and add the Draggable view sort from the selection. Please refer to the attached screenshot. 

DraggableViews module for drupal 8

2. Create a Draggable view display:

Create a view or add page display to the existing view by selecting the table format. Also follow the below instructions

Title: Title for the view. 

Format: Select the table format for the view display.

Fields: Under this section add the fields you need to show on the view page. At least three fields are required.

Content: Title: The fields which will be shown on the page. You can add any number of fields from the selected entity.

Draggableviews: Content: This is a mandatory field to make draggable views content to work. Click on the add button and search for Draggableviews (content) and add field.

Operational links : This is a mandatory field too to show the drag options for the user along with edit/delete.

Filter Criteria: Select the filters you want to include along with the selected content type.

Sort Criteria: Under this section remove the existing sort option and add the new sort by selecting the draggable views weight.

Path: Provide the valid path of your interest like /admin/content/sketches-order.

Pager: While configuring the pager, always display all items with no pager so that users can re-order all the items instead of each page item. See the attached screenshot for reference. 

Create a Draggable view display

3. Add a menu link for easy navigation:

Adding a menu link will provide the quick access for the Draggable view page. Please provide a valid path for views like “/admin/content/view-name” so that we can have a menu link under administration menus. To add a menu link to the navigation, edit the created view under Page Settings --> Menu. Select the menu tab and add the necessary settings here. See the attached screenshot for reference.

DraggableViews module for drupal 8

Setup the permissions: Draggable view module provides custom permissions for the user authentication to the draggable view. 

To update the permission please go to people --> permission. Next, search for draggable views. You will then see all permissions defined for roles. Select the trusted role and save the configuration. 

Draggable view display

Also, you will need to set the permission for the created view under Page settings ->   Access. Select the “Access Draggableviews” permission and save the view

DraggableViews module for drupal 8

And that's it! You will now have the page containing a drag and drop handle to reorder your content as in the image shown below.

DraggableViews module for drupal 8

Also, you can see the same order for all the created views of content type. Now reordering of your view items is much easier than before.

Tác giả Tommy

Bạn thấy bài viết này như thế nào?: 
Average: 6.2 (23 votes)
Ảnh của Tommy Tran

Tommy Tran owner www.expressmagazine.net

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy
  • Phone/Zalo: (+84) 944 225 212
  • WhatsApp: (+84) 944 225 212
  • Line Messenger: (+84) 944 225 212
  • Email: asaleotestf@gmail.com
  • Telegram Messenger: https:/t.me/tommytran0401

Bình luận (0)


Add Comment

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
16 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.




Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

Facebook theo dõi chúng ta như thế nào?

Facebook theo dõi chúng ta như thế nào?

Lần đầu tiên, Facebook đã tiết lộ chi tiết về quá trình theo dõi người dùng mạng xã hội này trên thời báo USA Today.

The Power of the Web

Sức mạnh của Website trong marketing online

Clayton Christensen's book, "The Innovator's Dilemma," rocked conventional business thinking when it came out in 1997. Christensen, a professor at Harvard Business School, showed that new technologies often failed because the companies offered new technologies to the existing customer base.

Hướng dẫn cấu hình domain ảo ở localhost

Hướng dẫn cấu hình domain ảo ở localhost

Giả sử bạn phát triển 1 dự án và tạo trên localhost, cách thông thường là mỗi dự án thì bạn tạo một thư mục riêng trong thư mụcwww hoặc bên trong 1 thư mục nào đó.