Mark Gibson wrote:
> Ideally I'd like to have a single Droppable on the whole table,
> and use the 'ondrop' callback, but having the position of the pointer
> (relative to the table element) passed to the callback function,
> is this possible?

Right, I've solved it. To recap the problem:

I have a palette of items, which need associating with columns in a
table. I wanted to drag the item into the table (using ghosting drag).
On dropping the item it would be removed from the palette and placed
in the TH cell of whichever column it was dropped in.

First I tried adding a Droppable to every TH and TD - this caused a
major delay at the beginning of the drag operation.

Now, I've got a Droppable on just the TABLE:

$("table").Droppable({
        accept:     'item',
        tolerance:  'pointer',
        ondrop:     function(item) {
                var dropx = item.dragCfg.cursx; // The cursor position at time 
of drop
                                
                var ths = $(this).find('th');   // Get all heading cells        
                                
                // Find the column in which the drop occurred
                for (var i=1; i < ths.length; i++) {
                        if (dropx < jQuery.iUtil.getPosition(ths[i]).x) break;
                }
                
                // Place the item in the column heading
                $(item).remove().appendTo(ths[i-1]);
        }
});

I have to ask though, if using of item.dragCfg.cursx is future proof?
Is there a better/safer way I should be doing this?

Otherwise, I hope this may help someone else.

Cheers
- Mark

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to