Sortable JAVASCRIPT UI Component API

Sortable Javascript API

Class

Sortable

Sortable allows you to rearrange a group of html elements.

Selector

smart-sortable

Properties

AanimationDefines or retrieves the current animation mode. When this property is set to 'none', all animations are disabled and elements will transition instantly without any animated effects. Use this property to enable, disable, or customize the animation behavior of components.
DdisabledControls whether items can be sorted. When enabled, users can rearrange items by sorting them; when disabled, sorting functionality is not available.
DdragModeDetermines how a sortable item can be dragged within the list. When set to 'item', users can drag the entire item itself to reorder it. When set to 'handle', a specific drag handle is displayed next to each item, and only dragging this handle will reorder the item. This property can be both retrieved (get) and modified (set) to control the user’s drag interaction method.
HhandlePositionSets or retrieves the position of the drag handle in relation to its associated sortable item. This property is only applicable when the dragMode option is set to 'handle', meaning that the user can initiate dragging only by interacting with the specified handle within the sortable item. Use this option to define where the handle appears (e.g., 'left', 'right', 'top', or 'bottom') relative to the item, allowing for precise customization of the drag-and-drop interface.
HhandleVisibilityDetermines whether the drag handle of a sortable item is always visible or only appears when the item is hovered over. This property is applicable only if dragMode is set to 'handle'. Use this setting to control the visibility of the item’s drag handle for user interaction.
IitemsSpecifies or retrieves a CSS selector used to identify which elements within the container are sortable items. By default, all direct child elements of the 'smart-sortable' custom element are considered sortable. You can customize this selector to restrict sortable functionality to specific child elements based on their class, tag, or other attributes.
UunlockKeySets or retrieves the unlockKey, a unique value required to activate or grant access to the product's features. This property enables locking and unlocking the product based on its assigned key.
LlocaleSpecifies or retrieves the current language code (e.g., 'en', 'fr', 'es'). This property determines which set of localized messages from the messages property will be used for displaying text or content. It ensures the correct language is applied throughout the application's interface.
LlocalizeFormatFunctionCallback function associated with the localization module, typically used to handle language or region-specific content updates or responses within the application.
MmessagesDefines or retrieves an object containing the localized strings that are displayed in the widget's user interface. This property allows you to customize all text elements for different languages and regions. It should be used together with the locale property to ensure the widget presents the appropriate translations based on the selected locale.
MmodeSets or retrieves the orientation (horizontal or vertical) in which sortable items are arranged and can be reordered by dragging. This determines whether items are stacked in a row or a column when using the sortable functionality.
RrightToLeftGets or sets a value that specifies whether the element's text direction is set to right-to-left (RTL), enabling proper alignment and layout for languages and locales that use right-to-left scripts, such as Arabic or Hebrew.

Events

DdragEndThis event is triggered whenever the order of items in a sortable list changes, indicating that one or more items have been repositioned within the list by the user. The event provides details about the updated order, allowing you to respond to changes, such as saving the new arrangement or updating the user interface.

Methods

MmoveRelocates a sortable item within a list from its current index to a specified target index, updating the order of items accordingly.
UupdateItemsRecalculates the list of sortable items within the custom element. This method should be called whenever items are dynamically added or removed to ensure that all current items are properly recognized and can be sorted as expected.

Properties

animation"none" | "simple" | "advanced"

Defines or retrieves the current animation mode. When this property is set to 'none', all animations are disabled and elements will transition instantly without any animated effects. Use this property to enable, disable, or customize the animation behavior of components.

Allowed Values

  • "none" - animation is disabled
  • "simple" - ripple animation is disabled
  • "advanced" - all animations are enabled

Default value

"advanced"

Example

Set the animation property.

 <smart-sortable animation='none'></smart-sortable>

Set the animation property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.animation = 'simple';

Get the animation property.

 const sortable = document.querySelector('smart-sortable');
 let animation = sortable.animation;

disabledboolean

Controls whether items can be sorted. When enabled, users can rearrange items by sorting them; when disabled, sorting functionality is not available.

Default value

false

Example

Set the disabled property.

 <smart-sortable disabled></smart-sortable>

Set the disabled property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.disabled = false;

Get the disabled property.

 const sortable = document.querySelector('smart-sortable');
 let disabled = sortable.disabled;

dragMode"item" | "handle"

Determines how a sortable item can be dragged within the list. When set to 'item', users can drag the entire item itself to reorder it. When set to 'handle', a specific drag handle is displayed next to each item, and only dragging this handle will reorder the item. This property can be both retrieved (get) and modified (set) to control the user’s drag interaction method.

Default value

"item"

Example

Set the dragMode property.

 <smart-sortable drag-mode='handle'></smart-sortable>

Set the dragMode property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.dragMode = 'item';

Get the dragMode property.

 const sortable = document.querySelector('smart-sortable');
 let dragMode = sortable.dragMode;

handlePosition"right" | "left" | "top" | "bottom"

Sets or retrieves the position of the drag handle in relation to its associated sortable item. This property is only applicable when the dragMode option is set to 'handle', meaning that the user can initiate dragging only by interacting with the specified handle within the sortable item. Use this option to define where the handle appears (e.g., 'left', 'right', 'top', or 'bottom') relative to the item, allowing for precise customization of the drag-and-drop interface.

Default value

"right"

Example

Set the handlePosition property.

 <smart-sortable handle-position='top'></smart-sortable>

Set the handlePosition property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.handlePosition = 'left';

Get the handlePosition property.

 const sortable = document.querySelector('smart-sortable');
 let handlePosition = sortable.handlePosition;

handleVisibility"hover" | "visible"

Determines whether the drag handle of a sortable item is always visible or only appears when the item is hovered over. This property is applicable only if dragMode is set to 'handle'. Use this setting to control the visibility of the item’s drag handle for user interaction.

Default value

"hover"

Example

Set the handleVisibility property.

 <smart-sortable handle-visibility='visible'></smart-sortable>

Set the handleVisibility property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.handleVisibility = 'hover';

Get the handleVisibility property.

 const sortable = document.querySelector('smart-sortable');
 let handleVisibility = sortable.handleVisibility;

itemsstring | null

Specifies or retrieves a CSS selector used to identify which elements within the container are sortable items. By default, all direct child elements of the 'smart-sortable' custom element are considered sortable. You can customize this selector to restrict sortable functionality to specific child elements based on their class, tag, or other attributes.

Example

Set the items property.

 <smart-sortable items='li'></smart-sortable>

Set the items property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.items = .special-item;

Get the items property.

 const sortable = document.querySelector('smart-sortable');
 let items = sortable.items;

unlockKeystring

Sets or retrieves the unlockKey, a unique value required to activate or grant access to the product's features. This property enables locking and unlocking the product based on its assigned key.

Default value

""

Example

Set the unlockKey property.

 <smart-sortable unlock-key=''></smart-sortable>

Set the unlockKey property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.unlockKey = '1111-2222-3333-4444-5555';

Get the unlockKey property.

 const sortable = document.querySelector('smart-sortable');
 let unlockKey = sortable.unlockKey;

localestring

Specifies or retrieves the current language code (e.g., 'en', 'fr', 'es'). This property determines which set of localized messages from the messages property will be used for displaying text or content. It ensures the correct language is applied throughout the application's interface.

Default value

"en"

Example

Set the locale property.

 <smart-sortable locale='de'></smart-sortable>

Set the locale property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.locale = 'en';

Get the locale property.

 const sortable = document.querySelector('smart-sortable');
 let locale = sortable.locale;

localizeFormatFunctionfunction | null

Callback function associated with the localization module, typically used to handle language or region-specific content updates or responses within the application.

Example

Set the localizeFormatFunction property.

 <smart-sortable localize-format-function='function(){return '...'}'></smart-sortable>

Set the localizeFormatFunction property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.localizeFormatFunction = function(){return '...'};

Get the localizeFormatFunction property.

 const sortable = document.querySelector('smart-sortable');
 let localizeFormatFunction = sortable.localizeFormatFunction;

messagesobject

Defines or retrieves an object containing the localized strings that are displayed in the widget's user interface. This property allows you to customize all text elements for different languages and regions. It should be used together with the locale property to ensure the widget presents the appropriate translations based on the selected locale.

Default value




"en": {

"propertyUnknownType": "'{{name}}' property is with undefined 'type' member!",

"propertyInvalidValue": "Invalid '{{name}}' property value! Actual value: '{{actualValue}}', Expected value: '{{value}}'!",

"propertyInvalidValueType": "Invalid '{{name}}' property value type! Actual type: '{{actualType}}', Expected type: '{{type}}'!",

"methodInvalidValueType": "Invalid '{{name}}' method argument value type! Actual type: '{{actualType}}', Expected type: '{{type}}' for argument with index: '{{argumentIndex}}'!",

"methodInvalidArgumentsCount": "Invalid '{{name}}' method arguments count! Actual arguments count: '{{actualArgumentsCount}}', Expected at least: '{{argumentsCount}}' argument(s)!",

"methodInvalidReturnType": "Invalid '{{name}}' method return type! Actual type: '{{actualType}}', Expected type: '{{type}}'!",

"elementNotInDOM": "Element does not exist in DOM! Please, add the element to the DOM, before invoking a method.",

"moduleUndefined": "Module is undefined.",

"missingReference": "{{elementType}}: Missing reference to '{{files}}'.",

"htmlTemplateNotSuported": "{{elementType}}: Web Browser doesn't support HTMLTemplate elements.",

"invalidTemplate": "{{elementType}}: '{{property}}' property accepts a string that must match the id of an HTMLTemplate element from the DOM."

}

Example

Set the messages property.

 <smart-sortable messages='{"de":{"propertyUnknownType":"'{{name}}' Eigenschaft ist mit undefined 'Typ'-Member!","propertyInvalidValue":"Invalid '{{name}}' property value! Actual value: '{{actualValue}}', Expected value: '{{value}}'!","propertyInvalidValueType":"Invalid '{{name}}' property value type! Actual type: '{{actualType}}', Expected type: '{{type}}'!","methodInvalidValueType":"Invalid '{{name}}' method argument value type! Actual type: '{{actualType}}', Expected type: '{{type}}' for argument with index: '{{argumentIndex}}'!","methodInvalidArgumentsCount":"Invalid '{{name}}' method arguments count! Actual arguments count: '{{actualArgumentsCount}}', Expected at least: '{{argumentsCount}}' argument(s)!","methodInvalidReturnType":"Invalid '{{name}}' method return type! Actual type: '{{actualType}}', Expected type: '{{type}}'!","elementNotInDOM":"Element does not exist in DOM! Please, add the element to the DOM, before invoking a method.","moduleUndefined":"Modul ist nicht definiert.","missingReference":"{{elementType}}: Fehlender Verweis auf {{files}}.","htmlTemplateNotSuported":"{{elementType}}: Web Browser doesn't support HTMLTemplate elements.","invalidTemplate":"{{elementType}}: '{{property}}' property accepts a string that must match the id of an HTMLTemplate element from the DOM."}}'></smart-sortable>

Set the messages property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.messages = {"en":{"propertyUnknownType":"'{{name}}' property is with undefined 'type' member!","propertyInvalidValue":"Invalid '{{name}}' property value! Actual value: '{{actualValue}}', Expected value: '{{value}}'!","propertyInvalidValueType":"Invalid '{{name}}' property value type! Actual type: '{{actualType}}', Expected type: '{{type}}'!","methodInvalidValueType":"Invalid '{{name}}' method argument value type! Actual type: '{{actualType}}', Expected type: '{{type}}' for argument with index: '{{argumentIndex}}'!","methodInvalidArgumentsCount":"Invalid '{{name}}' method arguments count! Actual arguments count: '{{actualArgumentsCount}}', Expected at least: '{{argumentsCount}}' argument(s)!","methodInvalidReturnType":"Invalid '{{name}}' method return type! Actual type: '{{actualType}}', Expected type: '{{type}}'!","elementNotInDOM":"Element does not exist in DOM! Please, add the element to the DOM, before invoking a method.","moduleUndefined":"Module is undefined.","missingReference":"{{elementType}}: Missing reference to '{{files}}'.","htmlTemplateNotSuported":"{{elementType}}: Web Browser doesn't support HTMLTemplate elements.","invalidTemplate":"{{elementType}}: '{{property}}' property accepts a string that must match the id of an HTMLTemplate element from the DOM."}};

Get the messages property.

 const sortable = document.querySelector('smart-sortable');
 let messages = sortable.messages;

mode"horizontal" | "vertical"

Sets or retrieves the orientation (horizontal or vertical) in which sortable items are arranged and can be reordered by dragging. This determines whether items are stacked in a row or a column when using the sortable functionality.

Default value

"vertical"

Example

Set the mode property.

 <smart-sortable mode='horizontal'></smart-sortable>

Set the mode property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.mode = 'vertical';

Get the mode property.

 const sortable = document.querySelector('smart-sortable');
 let mode = sortable.mode;

rightToLeftboolean

Gets or sets a value that specifies whether the element's text direction is set to right-to-left (RTL), enabling proper alignment and layout for languages and locales that use right-to-left scripts, such as Arabic or Hebrew.

Default value

false

Example

Set the rightToLeft property.

 <smart-sortable right-to-left></smart-sortable>

Set the rightToLeft property by using the HTML Element's instance.

 const sortable = document.querySelector('smart-sortable');
 sortable.rightToLeft = true;

Get the rightToLeft property.

 const sortable = document.querySelector('smart-sortable');
 let rightToLeft = sortable.rightToLeft;

Events

dragEndCustomEvent

This event is triggered whenever the order of items in a sortable list changes, indicating that one or more items have been repositioned within the list by the user. The event provides details about the updated order, allowing you to respond to changes, such as saving the new arrangement or updating the user interface.

  • Bubbles Yes
  • Cancelable Yes
  • Interface CustomEvent
  • Event handler property onDragEnd

Arguments

evCustomEvent

Methods

isDefaultPrevented

Returns true if the event was prevented by any of its subscribers.

Returns

boolean true if the default action was prevented. Otherwise, returns false.

preventDefault

The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.

stopPropagation

The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.

Example

Set up the event handler of dragEnd event.

const sortable = document.querySelector('smart-sortable');
sortable.addEventListener('dragEnd', function (event) {
	// event handling code goes here.
})

Methods

move( fromIndex?: number, toIndex?: number): void

Relocates a sortable item within a list from its current index to a specified target index, updating the order of items accordingly.

Arguments

fromIndex?number

The original index of the item.

toIndex?number

The index to move the item to.


Invoke the move method.

const sortable = document.querySelector('smart-sortable');
sortable.move("0, 5");

updateItems(): void

Recalculates the list of sortable items within the custom element. This method should be called whenever items are dynamically added or removed to ensure that all current items are properly recognized and can be sorted as expected.


Invoke the updateItems method.

const sortable = document.querySelector('smart-sortable');
sortable.updateItems();

CSS Variables

--smart-sortable-handle-sizevar()

Default value

"25px"

smartSortable handle size