user584018
user584018

Reputation: 11304

Exclude items from sortable

I have below sample table code,

<table id="Table1">
<thead>
    <th>Title</th>
</thead>
<tbody>
    <tr>
        <td>Row 1</td>
    </tr>
    <tr>
        <td>Row 2</td>
    </tr>
    <tr>
        <td>Row 3</td>
    </tr>
    <tr class='disabled'>
        <td>Row 4</td>
    </tr>
    <tr>
        <td>Row 5</td>
    </tr>
</tbody>
</table>

I'm applying below jQuery Sortable, which works fine,

$("#Table1 tbody").sortable({
});

But, now I want to exclude sortable for "tr" having class "disabled", to do I'm applying below code (the jquery selector), but it DOESN't work. Is there anything wrong with selector? I have to use "thead" and "tbody" in HTML table.

Or is there any alternative approach? Thanks,

$("#Table1 tbody tr:not(.disabled)").sortable({
});

Upvotes: 9

Views: 5595

Answers (2)

Sanjeev Rai
Sanjeev Rai

Reputation: 6972

you can Use items option to specifiy which items inside the element should be sortable. Like:

$("#Table1 tbody").sortable({
    items: ':not(.disabled)'
});

Click here for more references:

Upvotes: 1

billyonecan
billyonecan

Reputation: 20250

Use the items option:

Specify which items are eligible to sort by passing a jQuery selector into the items option. Items excluded from this option are not sortable, nor are they valid targets for sortable items.

$("#Table1 tbody").sortable({
    items: 'tr:not(.disabled)'  
});

Demo

Upvotes: 19

Related Questions