views:

322

answers:

1

If I have this markup:

<table id="sometable">
   <tr>
    <td class="x"><span>111</span></td>
    <td>aaa</td>
   </tr>
   <tr>
    <td class="x"><span>222</span></td>
    <td>bbb</td>
   </tr>    
</table>

And this jQuery code:

$(".x span").draggable({ helper: 'clone', axis: 'y'});

When dragging the first column the cloned span is snapping to the second column rather than the first column. If I try to drag the table cell rather than the span inside it snaps outside of the table. If I remove axis:'y' is works as expected except I no longer have the Y axis restriction that I would like. Any ideas? Thanks.

A: 

You need to specify a containment & snap.

$(".x span").draggable({ 
    snap: '.x', 
    snapMode: 'inner', 
    containment: '#sometable', 
    helper: 'clone', 
    axis: 'y'
});
Jojo
In my code I am actually specifying the containment; in this case I would set it to '#sometable', '.x' wouldn't allow me to drag it outside of the cell. With or without the containment specified it does the same thing :(
pbz
Do you have a droppable set up as well?
Jojo
Not yet, but I'm planning on adding one as soon as I make the draggable work properly.
pbz
You're correct about the containment needing to be the table. You need that droppable though. That's what will allow you to drag between the .x td's. You may want to specify a snap and/or grid.`$(".x span").draggable({ snap: '.x', snapMode: 'inner', containment: '.x', helper: 'clone', axis: 'y'});`
Jojo
*cough* `containment: '#sometable'`
Jojo