-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we use drag and drop to do row ranking ? #636
Comments
Hi @Waynezhi! I think it might be difficult to add drag & drop functionality to the table rows because ideally the script would need to use delegated events and I don't know of any existing scripts that do that. If a script does exist, or if I have time to find & modify one, then after the drag & drop of child rows for a parent row, an "update" method would need to be used to retain the order. If parent rows were allowed to be drag and dropped, then what would be expected to happen if a column were sorted? |
I stand corrected. It looks like jQuery UI drag & drop does use delegated events. I'll try to work on a demo for you later today. |
Ok here is what I put together (demo): The only problem is that child rows can be moved from one parent to another... so it is possible to break the parent/child relationship and/or form new relationships (which may be a bad thing) $(function() {
var $table = $('.tablesorter');
// hide child rows & make draggable
$table.find('.tablesorter-childRow')
.find('td')
.droppable({
drop: function(event, ui) {
ui.draggable
.css({ left : 0, top : 0 })
.parent().after( $(this).parent() );
$table.trigger('update');
}
})
.draggable()
.hide();
$table
.tablesorter({
theme : 'blue',
// this is the default setting
cssChildRow: "tablesorter-childRow"
})
.tablesorterPager({
container: $("#pager"),
positionFixed: false
})
.delegate('.toggle', 'click' ,function(){
$(this)
.closest('tr')
.nextUntil('tr.tablesorter-hasChildRow')
.find('td').toggle();
return false;
});
}); |
Yeah, that demo is not pretty... it really breaks the table is a lot of cases. At least we know it's possible to drag & drop though LOL. |
Try this demo... it makes sure that we are only moving child row cells // hide child rows & make draggable
$table.find('.tablesorter-childRow')
.find('td')
.droppable({
drop: function(event, ui) {
ui.draggable
.css({ left : 0, top : 0 })
.closest('tr.tablesorter-hasChildRow').after( $(this).closest('tr.tablesorter-childRow') );
$table.trigger('update');
}
})
.draggable()
.hide(); |
thx @Mottie, look better |
in safari it now does not work at all, they just unclip and never snap, at lest before if i got over a row it'd push it down etc etc. Just reporting ;) |
Ok, I think I have most of the bugs worked out (demo). There are some limitations though:
$(function() {
var $table = $('.tablesorter');
// hide child rows & make draggable
$table.find('.tablesorter-childRow')
.find('td')
.droppable({
accept: '.draggingSiblings',
drop: function(event, ui) {
if ($(this).closest('tr').length){
$(this).closest('tr').before(
ui.draggable
.css({ left: 0, top: 0 })
.parent()
.removeClass('draggingRow')
);
$table
.find('.draggingSiblingsRow')
.removeClass('draggingSiblingsRow')
.find('.draggingSiblings')
.removeClass('draggingSiblings');
$table.trigger('update');
} else {
return false;
}
}
})
.draggable({
revert: "invalid",
start: function( event, ui ) {
$(this)
.parent()
.addClass('draggingRow')
.prevUntil('.tablesorter-hasChildRow')
.nextUntil('tr:not(.tablesorter-childRow)')
.addClass('draggingSiblingsRow')
.find('td')
.addClass('draggingSiblings');
}
})
.hide();
$table
.tablesorter({
theme : 'blue',
// this is the default setting
cssChildRow: "tablesorter-childRow"
})
.tablesorterPager({
container: $("#pager"),
positionFixed: false
})
.delegate('.toggle', 'click' ,function(){
$(this)
.closest('tr')
.nextUntil('tr.tablesorter-hasChildRow')
.find('td').toggle();
return false;
});
});
|
@Mottie its possible to have a demo of drag & drop parent lines ? only zebra widget, without other widgets, just want to save ordering after dropped. |
You could use jQuery UI sortable - see this Stackoverflow question & demo. |
thx a lot @Mottie |
i use pager, math, filter widgets, and edit / append new line
and if i can use sub-rows for a parent row (do the same thing like drag and drop, filtering, edit etc.) ?
thx
The text was updated successfully, but these errors were encountered: