Sortable Widgetversion added: 1.0
Description: Reorder elements in a list or grid using the mouse.
The jQuery UI Sortable plugin makes selected elements sortable by dragging with the mouse.
Options
appendTo
"parent"
- jQuery: A jQuery object containing the element to append the helper to.
- Element: The element to append the helper to.
- Selector: A selector specifying which element to append the helper to.
-
String: The string
"parent"
will cause the helper to be a sibling of the sortable item.
axis
false
"x"
, "y"
.cancel
":input,button"
connectWith
false
connectWith
option must be set on both sortable elements.containment
false
Defines a bounding box that the sortable items are contrained to while dragging.
Note: The element specified for containment must have a calculated width and height (though it need not be explicit). For example, if you have float: left
sortable children and specify containment: "parent"
be sure to have float: left
on the sortable/parent container as well or it will have height: 0
, causing undefined behavior.
- Element: An element to use as the container.
- Selector: A selector specifying an element to use as the container.
-
String: A string identifying an element to use as the container. Possible values:
"parent"
,"document"
,"window"
.
cursorAt
false
{ top, left, right, bottom }
.delay
0
distance
1
dropOnEmpty
true
false
, items from this sortable can't be dropped on an empty connect sortable (see the connectWith
option.grid
false
[ x, y ]
.handle
false
helper
"original"
-
String: If set to
"clone"
, then the element will be cloned and the clone will be dragged. - Function: A function that will return a DOMElement to use while dragging. The function receives the event and the element being sorted.
opacity
false
0.01
to 1
.placeholder
false
revert
false
-
Boolean: When set to
true
, the items will animate with the default duration. - Number: The duration for the animation, in milliseconds.
scrollSensitivity
20
scrollSpeed
20
scrollSensitivity
distance.tolerance
"intersect"
-
"intersect"
: The item overlaps the other item by at least 50%. -
"pointer"
: The mouse pointer overlaps the other item.
Methods
cancel()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the cancel method:
1
|
|
destroy()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the destroy method:
1
|
|
disable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the disable method:
1
|
|
enable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the enable method:
1
|
|
option( optionName )Returns: Object
optionName
.-
optionNameType: StringThe name of the option to get.
Invoke the method:
1
|
|
option()Returns: PlainObject
- This signature does not accept any arguments.
Invoke the method:
1
|
|
option( optionName, value )Returns: jQuery (plugin only)
optionName
.-
optionNameType: StringThe name of the option to set.
-
valueType: ObjectA value to set for the option.
Invoke the method:
1
|
|
option( options )Returns: jQuery (plugin only)
-
optionsType: ObjectA map of option-value pairs to set.
Invoke the method:
1
|
|
refresh()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the refresh method:
1
|
|
refreshPositions()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the refreshPositions method:
1
|
|
serialize( options )Returns: jQuery (plugin only)
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"
.
Note: 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"
, "foo-1"
, and "foo_1"
all serialize to "foo[]=1"
.
-
optionsType: ObjectOptions to customize the serialization.
Invoke the serialize method:
1
|
|
toArray()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the toArray method:
1
|
|
widget()Returns: jQuery
jQuery
object containing the sortable element.
- This method does not accept any arguments.
Invoke the widget method:
1
|
|
Events
activate( event, ui )Type: sortableactivate
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the activate callback specified:
1
2
3
|
|
Bind an event listener to the sortableactivate event:
1
|
|
beforeStop( event, ui )Type: sortablebeforestop
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the beforeStop callback specified:
1
2
3
|
|
Bind an event listener to the sortablebeforestop event:
1
|
|
change( event, ui )Type: sortablechange
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the change callback specified:
1
2
3
|
|
Bind an event listener to the sortablechange event:
1
|
|
create( event, ui )Type: sortablecreate
Note: The ui
object is empty but included for consistency with other events.
Initialize the sortable with the create callback specified:
1
2
3
|
|
Bind an event listener to the sortablecreate event:
1
|
|
deactivate( event, ui )Type: sortabledeactivate
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the deactivate callback specified:
1
2
3
|
|
Bind an event listener to the sortabledeactivate event:
1
|
|
out( event, ui )Type: sortableout
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the out callback specified:
1
2
3
|
|
Bind an event listener to the sortableout event:
1
|
|
over( event, ui )Type: sortableover
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the over callback specified:
1
2
3
|
|
Bind an event listener to the sortableover event:
1
|
|
receive( event, ui )Type: sortablereceive
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the receive callback specified:
1
2
3
|
|
Bind an event listener to the sortablereceive event:
1
|
|
remove( event, ui )Type: sortableremove
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the remove callback specified:
1
2
3
|
|
Bind an event listener to the sortableremove event:
1
|
|
sort( event, ui )Type: sortablesort
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the sort callback specified:
1
2
3
|
|
Bind an event listener to the sortablesort event:
1
|
|
start( event, ui )Type: sortablestart
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the start callback specified:
1
2
3
|
|
Bind an event listener to the sortablestart event:
1
|
|
stop( event, ui )Type: sortablestop
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the stop callback specified:
1
2
3
|
|
Bind an event listener to the sortablestop event:
1
|
|
update( event, ui )Type: sortableupdate
-
eventType: Event
-
uiType: Object
-
helperType: jQueryThe jQuery object representing the helper being sorted
-
itemType: jQueryThe jQuery object representing the current dragged element
-
offsetType: ObjectThe current absolute position of the helper represented as
{ top, left }
-
positionType: ObjectThe current position of the helper represented as
{ top, left }
-
originalPositionType: ObjectThe original position of the element represented as
{ top, left }
-
senderType: jQueryThe sortable that the item comes from if moving from one sortable to another
-
Initialize the sortable with the update callback specified:
1
2
3
|
|
Bind an event listener to the sortableupdate event:
1
|
|
Example:
A simple jQuery UI Sortable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
|