jQuery UI API β Sortable Widget
Category
Usage
Description: Use the mouse to reorder elements within a list or grid.
Added in version: 1.0
Dependencies:
Note: The jQuery UI Sortable plugin allows selected elements to be sorted by dragging with the mouse.
Note: To sort table rows, the tbody must be sortable, not the table.
Quick Navigation
| Option | Type | Description | Default |
|---|---|---|---|
| appendTo | jQuery or Element or Selector or String |
Where the helper being moved with the mouse is appended to (e.g., to resolve overlap/zIndex issues).
Multiple types supported:
Initialize a sortable with the specified appendTo option:
After initialization, get or set the appendTo option:
|
"parent" |
| axis | String |
If defined, the items can only be moved horizontally or vertically. Possible values: "x", "y".
Code examples: Initialize a sortable with the specified axis option:
After initialization, get or set the axis option:
|
false |
| cancel | Selector |
Prevents sorting from starting on elements matching the selector.
Code examples: Initialize a sortable with the specified cancel option:
After initialization, get or set the cancel option:
|
"input, textarea, button, select, option" |
| connectWith | Selector |
A selector of other sortable elements that the items in this list should be connected to. This is a one-way relationship. If you want items to be connected both ways, the connectWith option must be set on both sortable elements.
Code examples: Initialize a sortable with the specified connectWith option:
After initialization, get or set the connectWith option:
|
false |
| containment | Element or Selector or String |
Defines the boundaries that the sortable items are constrained to while dragging.
Note: The element specified for containment must have a calculated width and height (though it doesn't need to be explicit). For example, if you have float: left sortable children and specify containment: "parent", ensure the sortable/parent container also has float: left, otherwise it will have height: 0, leading to undefined behavior.
Multiple types supported:
Initialize a sortable with the specified containment option:
After initialization, get or set the containment option:
|
false |
| cursor | String |
Defines the cursor that is shown when sorting.
Code examples: Initialize a sortable with the specified cursor option:
After initialization, get or set the cursor option:
|
"auto" |
| cursorAt | Object |
Moves the sorting element or helper so the cursor always appears to drag from the same position. Coordinates can be given as a hash with one or two keys: { top, left, right, bottom }.
Code examples: Initialize a sortable with the specified cursorAt option:
After initialization, get or set the cursorAt option:
|
false |
| delay | Integer |
Time in milliseconds after mousedown before sorting begins. This option can prevent unwanted drags when clicking on an element.
Code examples: Initialize a sortable with the specified delay option:
After initialization, get or set the delay option:
|
0 |
| disabled | Boolean |
If set to true, disables the sortable.
Code examples: Initialize a sortable with the specified disabled option:
After initialization, get or set the disabled option:
|
false |
| distance | Number |
Distance in pixels that the mouse must move before sorting begins. If this option is specified, sorting will not begin until the mouse has moved beyond the specified distance. This option can be used to allow clicks on elements within a handle.
Code examples: Initialize a sortable with the specified distance option:
After initialization, get or set the distance option:
|
1 |
| dropOnEmpty | Boolean |
If false, items from this sortable cannot be dropped on an empty connected sortable (see the connectWith option).
Code examples: Initialize a sortable with the specified dropOnEmpty option:
After initialization, get or set the dropOnEmpty option:
|
true |
| forceHelperSize | Boolean |
If true, forces the helper to have a size.
Code examples: Initialize a sortable with the specified forceHelperSize option:
After initialization, get or set the forceHelperSize option:
|
false |
| forcePlaceholderSize | Boolean |
If true, forces the placeholder to have a size.
Code examples: Initialize a sortable with the specified forcePlaceholderSize option:
After initialization, get or set the forcePlaceholderSize option:
|
false |
| grid | Array |
Snaps the sorting element or helper to a grid, every x and y pixel. The array form must be [ x, y ].
Code examples: Initialize a sortable with the specified grid option:
After initialization, get or set the grid option:
|
false |
| handle | Selector or Element |
If specified, restricts sorting from starting on elements other than the specified one(s).
Code examples: Initialize a sortable with the specified handle option:
After initialization, get or set the handle option:
|
false |
| helper | String or Function() |
Allows for a helper element to be used for dragging display.
Multiple types supported:
Initialize a sortable with the specified helper option:
After initialization, get or set the helper option:
|
"original" |
| items | Selector |
Specifies which items inside the element should be sortable.
Code examples: Initialize a sortable with the specified items option:
After initialization, get or set the items option:
|
"> *" |
| opacity | Number |
The opacity of the helper while sorting. From 0.01 to 1.
Code examples: Initialize a sortable with the specified opacity option:
After initialization, get or set the opacity option:
|
false |
| placeholder | String |
A class name to apply to the placeholder. Otherwise, a white space.
Code examples: Initialize a sortable with the specified placeholder option:
After initialization, get or set the placeholder option:
|
false |
| revert | Boolean or Number |
Whether the sortable items should revert to their new positions using a smooth animation.
Multiple types supported:
Initialize a sortable with the specified revert option:
After initialization, get or set the revert option:
|
false |
YouTip