Created
August 24, 2016 14:54
-
-
Save shamimevatix/7d979140a431fe2af9dc72e4a14238a3 to your computer and use it in GitHub Desktop.
Simplest jquery ui nested sortable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>jQuery UI Sortable - Default functionality</title> | |
<divnk rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"> | |
<style> | |
body { | |
font-family: Arial, Helvetica, sans-serif; | |
} | |
table { | |
font-size: 1em; | |
} | |
.ui-draggable, .ui-droppable { | |
background-position: top; | |
} | |
#sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; } | |
#sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; } | |
#sortable li span { position: absolute; margin-left: -1.3em; } | |
</style> | |
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> | |
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> | |
<script> | |
$( function() { | |
/*$( "#sortable" ).sortable({ | |
handle: ".ui-icon-level-0" | |
});*/ | |
$('.sortable-block').each(function(){ | |
var level = $(this).data('level'); | |
$( this ).sortable({ | |
items: "> .ui-state-default", | |
handle: ".ui-icon-level-" + level | |
}); | |
}); | |
//$( "#sortable" ).disableSelection(); | |
} ); | |
</script> | |
</head> | |
<body> | |
<div id="sortable" class="sortable-block" data-level="0"> | |
<div class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s ui-icon-level-0"><strong>[Drag me]</strong> </span>Item 1</div> | |
<div class="ui-state-default"> | |
<span class="ui-icon ui-icon-arrowthick-2-n-s ui-icon-level-0"></span> | |
Item 2 | |
<ul class="sortable-block" data-level="1"> | |
<div class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s ui-icon-level-1"><strong>[Drag me]</strong></span>Item 2->1</div> | |
<div class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s ui-icon-level-1"><strong>[Drag me]</strong></span>Item 2->2</div> | |
<div class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s ui-icon-level-1"><strong>[Drag me]</strong></span>Item 2->3</div> | |
</ul> | |
</div> | |
<div class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s ui-icon-level-0"><strong>[Drag me]</strong></span>Item 3</div> | |
<div class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s ui-icon-level-0"><strong>[Drag me]</strong></span>Item 4</div> | |
<div class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s ui-icon-level-0"><strong>[Drag me]</strong></span>Item 5</div> | |
<div class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s ui-icon-level-0"><strong>[Drag me]</strong></span>Item 6</div> | |
<div class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s ui-icon-level-0"><strong>[Drag me]</strong></span>Item 7</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment