Closed (duplicate)
Project:
Drupal core
Version:
8.0.x-dev
Component:
javascript
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
3 Sep 2011 at 10:37 UTC
Updated:
29 Jul 2014 at 19:56 UTC
I would like to react on drag table changes in my custom js code.
However tabledrag.js hides everything in a private "self" variable.
jQuery offers different solutions for this.
Imho the best one would be to trigger a custom event:
$(self.table).trigger('tableDragChanged', self);
This would allow to hook into the change event:
$("table").bind('tableDragChanged', function(self){
alert('Change Event')
});
Trigger is part of jQuery since jQuery 1.0
http://api.jquery.com/trigger/
| Comment | File | Size | Author |
|---|---|---|---|
| tabledrag_javascript_hook.patch | 510 bytes | jantimon |
Comments
Comment #1
ygerasimov commentedVery useful change. Big + on this.
I would change comment to simpler "Allows to hook into the change event."
As usecase we would be able to ajaxify draggable table as we would be able to submit form after dragging change has been done.
-25 days to next Drupal core point release.
Comment #2
nod_Hook into the change event won't make much sense to JS devs, it's an event and it allow module writers to react to, listen to or catch the change event.
I agree that's very useful and it doesn't look like there is anything we can use that's already in the code to easily do the same thing. While we're here why not add the same kind of events jQuery gives for his widgets: dragstart, drag, dragend.
Pushing a little, jQuery UI has a draggable utility that could be use to reduce the code from
tabledrag.js, just sayin' :-°Comment #3
nod_Just found #822062: Refactor tabledrag.js so it uses jquery.ui.draggable.js
Comment #4
jantimon commented@nod_ I totally agree.
As Drupal uses jQuery now we should try to reduce code duplications.
However the ticket you mentioned is for Drupal 8 and this issue is already a half year old.
So I guess in the long term we should go with #822062: Refactor tabledrag.js so it uses jquery.ui.draggable.js but for now this patch would help.
Comment #5
nod_6 months is not that old, and I don't think they'll go the easy way instead of the right one as long as there is no bug involved.
You should close this one as a duplicate of the other and help do that properly over there :)
Comment #6
jantimon commented"6 month is not that old" - that's exactly the reason why I don't like to contribute.
It's only time consuming and frustrating - I am using the patch above and if it is not applied
that's fine.
This one line of code would help module writers to create fancy ajax stuff but I guess the "#822062: Refactor tabledrag.js so it uses jquery.ui.draggable.js" issue
will be ready 2013/2014 anyway so we should just wait till then.
Comment #7
nod_That's the way it goes around here. If you won't help, then yes, it could take a while before it's done. A patch of mine took only a couple of weeks to get in because it was making performance improvement, it wasn't adding a feature.
It all depend on the kind of patch we're talking about. I'm pretty sure if the other issue had a working and clean patch it'll get in in no time.
Comment #8
barry_fisher commentedThanks @Merco for this patch. I've used it on a D7 install and works perfectly for my usage.
Comment #9
aaronschachter commentedsame here! thanks!
Comment #10
nod_Added a link here in #1524414: Rewrite tabledrag.js to use jQuery UI.
Comment #11
kpv commentedworks well with D7. thanks a lot