Sortable - Specify which items are eligible to sort by passing a jQuery selector into the items option.


SUBMITTED BY: jlolk3r

DATE: Jan. 19, 2016, 10 a.m.

FORMAT: HTML

SIZE: 1.6 kB

HITS: 867

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery UI Sortable - Include / exclude items</title>
  6. <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  7. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  8. <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  9. <link rel="stylesheet" href="/resources/demos/style.css">
  10. <style>
  11. #sortable1, #sortable2 { list-style-type: none; margin: 0; padding: 0; zoom: 1; }
  12. #sortable1 li, #sortable2 li { margin: 0 5px 5px 5px; padding: 3px; width: 90%; }
  13. </style>
  14. <script>
  15. $(function() {
  16. $( "#sortable1" ).sortable({
  17. items: "li:not(.ui-state-disabled)"
  18. });
  19. $( "#sortable2" ).sortable({
  20. cancel: ".ui-state-disabled"
  21. });
  22. $( "#sortable1 li, #sortable2 li" ).disableSelection();
  23. });
  24. </script>
  25. </head>
  26. <body>
  27. <h3 class="docs">Specify which items are sortable:</h3>
  28. <ul id="sortable1">
  29. <li class="ui-state-default">Item 1</li>
  30. <li class="ui-state-default ui-state-disabled">(I'm not sortable or a drop target)</li>
  31. <li class="ui-state-default ui-state-disabled">(I'm not sortable or a drop target)</li>
  32. <li class="ui-state-default">Item 4</li>
  33. </ul>
  34. <h3 class="docs">Cancel sorting (but keep as drop targets):</h3>
  35. <ul id="sortable2">
  36. <li class="ui-state-default">Item 1</li>
  37. <li class="ui-state-default ui-state-disabled">(I'm not sortable)</li>
  38. <li class="ui-state-default ui-state-disabled">(I'm not sortable)</li>
  39. <li class="ui-state-default">Item 4</li>
  40. </ul>
  41. </body>
  42. </html>

comments powered by Disqus