So, I'm already going for it. I am trying to create a drag and drop table that has a parent-child relationship, but where the children cannot be moved from the parent group, and all parents are sorted among themselves. I modeled my form and theme outside the admin menu code, and I have this duplication of this functionality. The problem is that I can move children to another parent or allow him to become a parent. By way of illustration:
Category 1 | |--Item 1 |--Item 2 Category 2 | |--Item 3 |--Item 4 |--Item 5
I would like to be able to sort positions 1 and paragraph 2 with each other, as well as paragraphs 3, paragraph 4 and paragraph 5 with each other, but not move them between categories 1 and 2. I also need able to sort categories 1 and category 2 each with a friend, forcing the children with them. I made many combinations of the $action
, $group
, $subgroup
settings mixed with the $class
settings for the categories and elements that I lost. None of what I have tried so far has produced the desired result. Here are the relevant bits of my code, as of now:
In my form:
$form['#tree'] = true; foreach($categories as $cat) { if(!isset($form['categories'][$cat->cid])){ $form['categories'][$cat->cid] = array( 'weight' => array( '#type' => 'weight', '#delta' => 25, '#attributes' => array('class' => array('item-weight', 'item-weight-' . $cat->cid)), ), 'cid' => array( '#type' => 'hidden', '#value' => $cat->cid, '#attributes' => array('class' => array('cid')), ), ); foreach($cats[$cat->cid] as $item) { $form['categories'][$cat->cid]['items'][$item->id] = array( 'weight' => array( '#type' => 'weight', '#delta' => 25, '#default_value'=> $item->weight, '#attributes' => array('class' => array('item-weight', 'item-weight-' . $cat->cid)), ), 'cid' => array( '#type' => 'hidden', '#value' => $cat->cid, '#attributes' => array('class' => array('cid')), ), ); } } }
In my topic:
$children = element_children($form['categories']); $rows = array(); if(count($children) > 0) { foreach($children as $cid) { $row = array( drupal_render($form['categories'][$cid]['weight']) . drupal_render($form['categories'][$cid]['cid']), ); $rows[] = array( 'data' => $row, 'class' => array('draggable', 'tabledrag-root'), ); foreach(element_children($form['categories'][$cid]['items']) as $id) { $row = array( theme('indentation', array('size' => 1)) . drupal_render($form['categories'][$cid]['items'][$id]['name']), drupal_render($form['categories'][$cid]['items'][$id]['weight']) . drupal_render($form['categories'][$cid]['items'][$id]['cid']), ); $rows[] = array( 'data' => $row, 'class' => array('draggable', 'tabledrag-leaf'), ); } drupal_add_tabledrag('cat-table', 'order', 'sibling', 'item-weight', 'item-weight-' . $cid); } } drupal_add_tabledrag('cat-table', 'match', 'parent', 'cid', 'cid', 'cid', true, 1); $output = theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => 'cat-table'))); $output .= drupal_render_children($form); return $output;
I read the documentation for drupal_add_tabledrag()
, looked at the code, looked at the code example and searched around drupal.org and Google, but came up with nothing.
My only solution so far is to copy and modify the tabledrag.js file to simply eliminate these features, but when stopping the indentation problem with the elements (which means not allowing them to be the same with the categories), keeping them in that the same category was Not Fun.
I believe the most important question is: is it possible to use standard Drupal?