3

Using code below, I can access classes of a row that's being dropped:

Drupal.tableDrag.prototype._dropRow = Drupal.tableDrag.prototype.dropRow;
Drupal.tableDrag.prototype.dropRow = function(event, self) {
  console.log('dropRow');
  console.log("feature-group: " + $(self.rowObject.element).hasClass('feature-group'));
  console.log("feature: " + $(self.rowObject.element).hasClass('feature'));
  if ( /* use classes here */ ) {
    /* return custom result here */
  }
  /* fallback to default here */
  return self._dropRow(event, self);
};

But now I don't want to test classes of a dragged row, but ones of a row that would be a parent. How do I do that?

To clarify: I need tabledrag parent, not DOM parent. All tabledrag rows are DOM siblings, and I need the row with ID field value equal to the would-be Parent ID field value (class="parent") of a dragged row.

Something in JavaScript sets the parent ID properly, during either drag or drop (can't tell), so I'm sure there is a way. I just don't know how to find it.

1
  • 3
    Interesting that this is accumulating downvotes, seems like a good Drupal JS question to me...@downvoters any chance you could comment on the specific objections?
    – Clive
    Jul 31, 2013 at 16:18

1 Answer 1

0

Get a reference to some parent DOM element ... the jquery parents() or parent function(s) comes to mind. Then use hasClass on those parents as needed.

some parent would be something like the following based on your example:

var parents = $(self.rowObject.element).parents(/* a selector to limit the type of parent, td, tr, whatever */);

EDIT:

dragged rows get a class of like .dragged-previous. The file tabledrag.js doesnt care about the current row, nor about IDs of anything during drag -- its just doing a DOM swap of rows and inserting the dragged row before another row; and assigning a Drupal weight to the hidden weight column. So cant you use like jquery prev() function to get the immediate previous element:

var parent = $('#menu-overview tr.drag-previous').prev();

I'm taking these values from a Main Menu tabledrag example of a vanilla D7 site: enter image description here

1
  • I meant tabledrag parent, not DOM parent. All tabledrag rows are siblings, and I want the row with ID equal to the would-be Parent ID of a dragged row.
    – Mołot
    Jul 26, 2013 at 6:24

Your Answer

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

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