drupal_add_tabledrag() notes

23 Mar 2009
Posted by jcfiala

A couple of quite notes for those of you trying to use drupal_add_tabledrag() on your sites, that may prevent you suffering through the same pain as myself... but I'll hide it after the break for those of you who don't care and want to get on to the next bit.

  1. Your tabledrag form element columns need a header, or you will get arcane javascript errors like 'cell[0] is undefined' in if (cell[0].colSpan > 1) {. Yes, you're not going to display this column to the user, because the tabledrag js will hide it. But the tabledrag still expects it to be there.
  2. Although it looks like your rows should be automatically indented, that's not the case. Use theme('indentation', n) to indent your rows when they are loaded.
  3. It's not going to re-order your rows either - if b is the child of c, the tabledrag isn't going to put it under c if it doesn't fall there automatically.
  4. A great example of using table drag is hidden at theme_menu_overview_form. Check it when you're not sure if you're doing things right.

I hope that helps!