.sortable()
Categories: UI
.sortable( [ options ] )
Plugin: jQuery.ui.sortable
Description: Apply the Sortable widget for each element in the set of matched elements
-
.sortable( [ options ] )
version added: 1.0options A map of additional options pass to the widget.
The jQuery UI Sortable plugin makes selected elements sortable by dragging with the mouse.
All callbacks receive two arguments: The original browser event and a prepared ui object, view below for a documentation of this object (if you name your second argument 'ui'):
- ui.helper - the current helper element (most often a clone of the item)
- ui.position - current position of the helper
- ui.offset - current absolute position of the helper
- ui.item - the current dragged element
- ui.placeholder - the placeholder (if you defined one)
- ui.sender - the sortable where the item comes from (only exists if you move from one connected list to another)
-
create
This event is triggered when sortable is created.
-
start
This event is triggered when sorting starts.
-
sort
This event is triggered during sorting.
-
change
This event is triggered during sorting, but only when the DOM position has changed.
-
beforeStop
This event is triggered when sorting stops, but when the placeholder/helper is still available.
-
stop
This event is triggered when sorting has stopped.
-
update
This event is triggered when the user stopped sorting and the DOM position has changed.
-
receive
This event is triggered when a connected sortable list has received an item from another list.
-
remove
This event is triggered when a sortable item has been dragged out from the list and into another.
-
over
This event is triggered when a sortable item is moved into a connected list.
-
out
This event is triggered when a sortable item is moved away from a connected list.
-
activate
This event is triggered when using connected lists, every connected list on drag start receives it.
-
deactivate
This event is triggered when sorting was stopped, is propagated to all possible connected lists.
-
destroy
-
.sortable( "destroy" )
version added: 1.0
Remove the sortable functionality completely. This will return the element back to its pre-init state.
-
-
disable
-
.sortable( "disable" )
version added: 1.0
Disable the sortable.
-
-
enable
-
.sortable( "enable" )
version added: 1.0
Enable the sortable.
-
-
option
-
.sortable( "option" , optionName , [value] )
version added: 1.0
Get or set any sortable option. If no value is specified, will act as a getter.
-
-
option
-
.sortable( "option" , options )
version added: 1.0
Set multiple sortable options at once by providing an options object.
-
-
widget
-
.sortable( "widget" )
version added: 1.0
Returns the .ui-sortable element.
-
-
serialize
-
.sortable( "serialize" , [options] )
version added: 1.0
Serializes the sortable's item id's into a form/ajax submittable string. Calling this method produces a hash that can be appended to any url to easily submit a new item order back to the server.
It works by default by looking at the id of each item in the format 'setname_number', and it spits out a hash like "setname[]=number&setname[]=number".
You can also give in a option hash as second argument to custom define how the function works. The possible options are: 'key' (replaces part1[] with whatever you want), 'attribute' (test another attribute than 'id') and 'expression' (use your own regexp).
If serialize returns an empty string, make sure the id attributes include an underscore. They must be in the form: "set_number" For example, a 3 element list with id attributes foo_1, foo_5, foo_2 will serialize to foo[]=1&foo[]=5&foo[]=2. You can use an underscore, equal sign or hyphen to separate the set and number. For example foo=1 or foo-1 or foo_1 all serialize to foo[]=1.
-
-
toArray
-
.sortable( "toArray" )
version added: 1.0
Serializes the sortable's item id's into an array of string. If you have
<ul id="a_sortable"><br> <li id="hello">Hello</li><br> <li id="goodbye">Good bye</li><br> </ul>
and do
var result = $('#a_sortable').sortable('toArray');
then
result[0] will contain "hello" and result[1] will contain "goodbye".
-
-
refresh
-
.sortable( "refresh" )
version added: 1.0
Refresh the sortable items. Custom trigger the reloading of all sortable items, causing new items to be recognized.
-
-
refreshPositions
-
.sortable( "refreshPositions" )
version added: 1.0
Refresh the cached positions of the sortables' items. Calling this method refreshes the cached item positions of all sortables. This is usually done automatically by the script and slows down performance. Use wisely.
-
-
cancel
-
.sortable( "cancel" )
version added: 1.0
Cancels a change in the current sortable and reverts it back to how it was before the current sort started. Useful in the stop and receive callback functions.
If the sortable item is not being moved from one connected sortable to another:
$(this).sortable('cancel');
will cancel the change.
If the sortable item is being moved from one connected sortable to another:
$(ui.sender).sortable('cancel');
will cancel the change. Useful in the 'receive' callback.
-