Wallogit.com
2017 © Pedro Peláez
nestedSortable is a jQuery plugin that extends jQuery Sortable UI functionalities to nested lists.
Note: Version 2.0 is published in branch '2.0alpha' and is available for testing. At the moment it has only been tested in Firefox and Chrome, if you work with IE feel free to give it a shot and let me know if something goes wrong., (*1)
The biggest change is that your nested list can now behave as a tree with expand/collapse funcionality. Simply set isTree to true in the options and you are good to go! Check the demo out to see what can be done with nestedSortable and a little CSS. (Note that all nestedSortable does is to assign/remove classes on the fly)
Also:
- isAllowed function finally works as expected, see the docs below
- Fixed: a small bug in the protectRoot function
- Changed: no drop zone will appear at all if you try to nest an item under another one that has the no-nesting class.
- Added: doNotClear option to prevent the plugin from deleting empty lists, (*2)
toArray method)<ol class="sortable">
<li><div>Some content</div></li>
<li>
<div>Some content</div>
<ol>
<li><div>Some sub-item content</div></li>
<li><div>Some sub-item content</div></li>
</ol>
</li>
<li><div>Some content</div></li>
</ol>
$(document).ready(function(){
$('.sortable').nestedSortable({
handle: 'div',
items: 'li',
toleranceElement: '> div'
});
});
Please note: every <li> must have either one or two direct children, the first one being a container element (such as <div> in the above example), and the (optional) second one being the nested list. The container element has to be set as the 'toleranceElement' in the options, and this, or one of its children, as the 'handle'., (*3)
Also, the default list type is <ol>., (*4)
This is the bare minimum to have a working nestedSortable. Check the demo out to see what can be accomplished with a little more., (*5)
isTree: true). Default: 700
setName[n] =>
{
'item_id': itemId,
'parent_id': parentId,
'depth': depth,
'left': left,
'right': right,
}
It accepts the same options as the original Sortable method (attribute and expression) plus the custom startDepthCount, that sets the starting depth number (default is 0).'0' ...
'id' => itemId
'1' ...
'id' => itemId
'children' ...
'0' ...
'id' => itemId
'1' ...
'id' => itemId
'2' ...
'id' => itemId
Similarly to toArray, it accepts attribute and expression options.nestedSortable doesn't work properly with connected draggables, because of the way Draggable simulates Sortable mouseStart and mouseStop events. This bug might or might not be fixed some time in the future (it's not specific to this plugin)., (*6)
jQuery UI Sortable 1.10+ (might work with 1.9, but not tested), (*7)
Tested with: Firefox, Chrome
NOTE: This is still an alpha version, please test thoroughly in whichever version of IE you target, (*8)
This work is licensed under the MIT License.
Which means you can do pretty much whatever you want with it., (*9)
Nonetheless if this plugin saved you money, saved you time or saved your life please take a moment to think about the work I've been doing for you and consider sharing a bit of your joy with me. Your donation, however small, will be greatly appreciated.
Thank you., (*10)
Donate with PayPal, (*11)