14

I'm having some difficults with sortable option handle.

When I use:

$("table tr").sortable().disableSelection();

There is no problem.

If I add the handle option then the sortable stops working:

$("table tr").sortable({
    handle: "td:eq(0)"
}).disableSelection();

The links:

http://jsfiddle.net/22C2n/

http://jsfiddle.net/22C2n/1/

Can anyone help me please?

3 Answers 3

30

Wrap your <tr>'s in a <tbody> and change your code to:

$("table tbody").sortable({
    handle: 'td:first'
}).disableSelection();

You specify the container that contains the elements you want to be sortable not the actual elements...

1
  • Perfect!!!! Its start the sorting from table 'FIRST' column, so you can select column text easily. Don't forget to remove .disableSelection() option.
    – Nono
    Commented Jun 17, 2016 at 21:56
1

Try to pass an element: http://jsfiddle.net/22C2n/5/

$("table tr").sortable({
    handle: $("td:eq(0)")
}).disableSelection();
2
  • thanks for the answer but the code does not work, at leas at chrome.
    – Diego
    Commented Dec 17, 2010 at 14:58
  • Yes, i was trying with 6A. But still, 1B and 1C (also 1A after you drop it) are moved to the right.Also it is not sorting
    – Diego
    Commented Dec 17, 2010 at 15:10
0

Setting the handle to td:eq(0) makes only the first table cell sortable, all the rest of the cells are not. Try adding a span inside the td and use it as the handle (demo).

HTML

<table>
    <tr>
        <td><span>&bull;</span>1A</td>
        <td>1B</td>
        <td>1C</td>
    </tr>
    ...
</table>

Script

$("table tr").sortable({
    handle: "span"
}).disableSelection();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.