I have set up a table to reorganize content based on custom weight field. Everything works well without pager.

But if I add a pager to the form, only the items displayed will be reorganized - causing conflicts with items in other pages. Why drupal_add_tabledrag doesn't consider only the weight values that are in the current page. This would avoid any item in current page to take the same value as an item in another page.

The Taxonomy Core module do it perfectly. For example in the form where you can reorganize terms, there is a pager (admin/structure/taxonomy/[vocabulary]):

enter image description here

In Taxonomy form, when there are several pages, the last item of a page will appear in in first in next page (so user can drag & drop either against next items or/and previous items)

How can I do the same in a custom form?

/**** EDIT ****/

Due to @Aneek Mukhopadhyay answer, I updated my post.

Actually the issue is not related with pager, but drupal_add_tabledrag(). The pager is working well.

The drag & drop feature too. The problem is that when reorganizing content in a page, some items will take a weight value already used by another item (in another page).

For example here is the first page of my form (before dragging any item):

enter image description here

And the second page:

enter image description here

If I move the item "Test 11" for example, new weight value for the item "Test 2" will be 2:

enter image description here

And the weight value 2 is already used by item Test 1 (in second page)

To achieve that I used drupal_add_tabledrag() this way:

drupal_add_tabledrag($table_id, 'order', 'sibling', 'example-item-weight');

I tried several options with drupal_add_tabledrag() but didn't find any other way to make it working without issues.

I also checked the taxonomy module but cannot figure out how they work with drupal_add_tabledrag().

  • did you look in the taxonomy module that came with your Drupal installation? In particular the admin form code ... ?
    – tenken
    Mar 12, 2015 at 4:29

1 Answer 1


This can be done. If taxonomy module does it then its doable isn't it? So to do that you have to mainly follow 2 functions.

  1. function taxonomy_overview_terms(..) in line # 249 @ /modules/taxonomy/taxonomy.admin.inc
  2. function theme_taxonomy_overview_terms(..) in line 548 @ /modules/taxonomy/taxonomy.admin.inc.

The first function is the form that generates the list of items present in the term listing page. (The screenshot you attached) The second function is the hook_theme implementation of the prior function and adds the table drag functionality to the page. If you look closely, the form has navigational steps added in it and then in the theme function they are made available for JavaScript to handle the back and forth navigation you mentioned. These are $form['#back_step'] & $form['#forward_step']. Those are converted to backStep & forwardStep and added to Drupal's JavaScript settings. So also you have to look at the taxonomy.js in where these are called and handled.

  • I have seen this two variables $form['#back_step'] & $form['#forward_step'], but don't think it's related with my issue. It's more a drupal_add_tabledrag() configuration issue I guess, than a paging issue.
    – 118218
    Mar 12, 2015 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.