Custom ordering using drag and drop

1 reply [Last post]
Last seen: 6 years 29 weeks ago
Joined: 2011-06-11

I'm writing an alternative front page for a site using Drupal 7. Using the hook_node_(insert|load|update|etc.) functions I can manage an extra table to hold the 'weight' of the node (a simple integer which can be used to 'order by' with db_select so that I can control the display order).

So far, so good! But what I really want to do is add in the functionality that can be found for ordering items that the Block page uses ( an then save the weights to the extra node information table that I have created.

I know there are various modules available to do weight ordering but I really want to write this one myself as their are other factors I need to keep control of.

Is there a video on this in another section or can you point me in the right direction?



Drave Robber
Last seen: 9 years 6 weeks ago
Joined: 2012-08-07

This is a quite challenging task, and to my knowledge there is no video dedicated specifically to it.

The central pieces of the puzzle are: form elements of type 'weight', a custom theme function to present the form as a table, and drupal_add_tabledrag() function. Perhaps the best chance to get an idea of how these pieces come together is taking a look at the tabledrag_example.module from Examples for Developers project.

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:

Contact us

Below are the supported keyboard shortcuts for our video player.

Start / stop video
Go to next video
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
Jump to a percentage (2 is 20%, for example)
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
1 month
6 months
10% off
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.