Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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({
});
like image 586
user584018 Avatar asked Jun 14 '13 09:06

user584018


1 Answers

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

like image 98
billyonecan Avatar answered Oct 09 '22 07:10

billyonecan