The user should have the ability to reorder elements (such as items in a list) by dragging and dropping them. Without drag and drop, it is not an ordinary task to reorder but script.aculo.us provides extended reordering support out of the box through the Sortable class.
When the tree option is set to “true”, it enables sorting with sub-elements within the sortable element. The default value is “false“. The element to make it sortable is passed to the create() method in the sortable namespace.
A Sortable consists of item elements in a container element. When you create a new Sortable, it takes care of the creation of the corresponding draggables and dropables.
To use script.aculo.us sortable capabilities, you’ll need to load the drag drop module, which also requires the effects module. The pre-compiled files required for code implementation are as follows.
Syntax: The create() method is used to create a sortable item. The create() method takes the id of the container element and sorts them out based on the options which are passed.
Sortable.destroy() method is used to remove all the event handlers and references created by Sortable.create() method.
A call to Sortable.create, implicitly calls on Sortable.destroy if the referenced element was already Sortable.
Sortable.destroy( element );
Example 1: The following demonstrates the drag and drop feature for a list. The next example will demonstrate the drag and drop for a tree which is developed on top of a simple list element.
Example 2: The following example demonstrates the drag and drops for a tree structure created out of list elements.