Sorry but I changed that already cursx is not used anymore.
I advice to use 'onDrag' callback. This way you get element's coordinates. You check this coordinates against you table position and each cell position. let's say: you have a table 500 px width, 500 height, 5 rows and 5 columns, positioned at 100px left and 50px top.Each cell has 100px as dimension. While you drag the element you get for instance x=313 and y=214. To find column int(x-table.left)/cell.width => parseInt(312 - 100)/100 = 3 to find row int(y-table.top)/cell.height => parseInt(214 - 50)/100 = 1 remember this last cell from row 1 and column 3 and when the dragging stops you know that the element was dropped on that last cell. Mark Gibson wrote: > 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/ > > _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/