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.4 (37 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

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

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

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.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

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

 
Thi lấy chứng chỉ: Acquia Certified Developer Exam Blueprint

Thi lấy chứng chỉ: Acquia Certified Developer Exam Blueprint

The Acquia Certified Developer exam is intended for Acquia customers, partners, and employees who perform a Developer role. This exam validates a candidate’s ability to:

Magic Quotes lỗi cài đặt với Drupal 8

Magic Quotes lỗi cài đặt với Drupal 8

We've had a few members start to test Drupal 8 and several ran into a problem during the installation.

Alexa

Những điều thú vị về Alexa

Alexa là một chỉ số xếp hạng trang web được nhiều webmater Việt Nam quan tâm, bài viết dưới đây Lướt NET không nói về vấn đề làm sao để tăng thứ hạng trên Alexa mà đưa ra vài điều thú vị về Alexa:

Công ty diệt chuột T&C

 

Diet con trung