An Angularjs ui component that can sort nested lists.
- Items can be sorted in their own list, moved across the tree, or nested under other items.
- It is possible to define elements that will not accept a new item/list
- Data binding. If you change the order, the data you bound will be updated.
Angularjs script
var app = angular.module('nestedSortableDemoApp', [
'ui.nestedSortable'
]);Injecting ui.nestedSortable to your App.
HTML View or Templates
<ol ui-nested-sortable="" ng-model="list">
<li ng-repeat="item in list" ui-nested-sortable-item="">
<div ui-nested-sortable-handle>
{{item.title}}
</div>
<ol ui-nested-sortable="" ng-model="item.items">
<li ng-repeat="subItem in item.items" ui-nested-sortable-item="">
<div ui-nested-sortable-handle>
{{subItem.title}}
</div>
</li>
</ol>
</li>
</ol> - Adding
ui-nested-sortableto your root element. - Using
ng-modelto bind the list data with element. It should be an array. - Adding
ui-nested-sortable-itemto your item element, it always follow theng-repeatattribute. - Adding
ui-nested-sortable-handleto mark which element do you want to handle the drage action - All
ui-nested-sortable,ng-model,ui-nested-sortable-itemandui-nested-sortable-handleare necessary. And they can be nested. - If you add a
nodragattribute to an element, the element won't response for the drag action.
A nested list, it binds with a nested array, it the sort order changed, the data will be updated.
Try Sample1
Two-level list, the data type of top level is 'chapter', the data type of the secend level is 'lecture', the node can only be dragged & dropped to another node which with same data type.
Try Sampl2
A nested recursive list, it binds with an unlimited nested array.
Try Sample3