I created a basic jQuery script to allow dragging and dropping table rows to reorder them. Everything is working great – the only thing that I can’t figure out is how to create a ‘ghost’ image of the row while it is being dragged.
I tried cloning the row
$(this).clone().addClass('dragClone');
With the following CSS
.dragClone{opacity:0.4;position:absolute;z-index:1500;}
But nothing showed up. Figuring that the TR may need to exist within a table, I cloned the entire table, emptied the rows and appended the selected TR as follows:
$('.dragTable').clone().addClass('dragClone');$('.dragClone').find('tbody').empty().append($('.origZone'));
(origZone is the class that’s given to the TR being dragged)
Still nothing is showing up.
I’ve never used clone before, so I have no idea if I am even close, or on the right track at all! The goal is to create a ghost image similar to the one used in the Redips_drag plugin (http://www.redips.net/javascript/drag-and-drop-table-row/)
I was able to solve this problem by doing the following:
Creating an empty div on the page:
Saved the containing table to a variable, cloned it, removed the tbody contents and hid the thead, appended the row, which was saved as a variable, appended it to the previously mentioned div
I’m not sure if this was the best way to accomplish it, but it works.
FYI – I had to use the following CSS to allow the hover affect to work on the underlying rows
Hope that this helps someone!