JQuery UI Sortable - how to include / exclude multiple "elements"?

I have a working example of a jQuery UI sorting function. I apply it to an HTML table to drag and sort table rows. It works fine, except that I want to exclude sorting of certain string classes. Using the items parameter, I can successfully exclude the ONE class (class "list-button-bar" ), but I can’t understand for the rest of my life the syntax of how to exclude more than one class. For example, I want to exclude <th> and other <tr> classes.

This is probably one of the ones in the documentation, but I am not familiar with the jQuery user interface yet to know what to look for.

Here's the working code:

 <script> $(function() { $("#applications_list tbody.list-tbody").sortable({ items: "tr:not(.list-button-bar)", cursor: 'crosshair' }); $("#applications_list tbody.list-tbody").disableSelection(); }); </script> 
+6
source share
3 answers

Did you try to use a comma? The items parameter accepts a jQuery selector:

  $("#applications_list tbody.list-tbody").sortable({ items: "tr:not(.list-button-bar), :not(th)", // Excludes <tr>s without a class and <th>s cursor: 'crosshair' }); 
+14
source

To exclude several tr usage classes:

 $("#applications_list tbody.list-tbody").sortable({ items: "tr:not(.list-button-bar,.other-class1,.other-class2)", cursor: 'crosshair' }); 
+2
source

In the jQuery 1.8 user interface, use the following:

 $("#applications_list tbody.list-tbody").sortable({ // Excludes <tr>s without a class and <th>s filter: "tr:not(.list-button-bar), :not(th)" }); 
+1
source

Source: https://habr.com/ru/post/888053/


All Articles