Instrucciones de origen · Vista previa de solo lectura
name
umbraco-sorter
description
Implement drag-and-drop sorting with UmbSorterController in Umbraco backoffice
version
1.0.0
location
managed
allowed-tools
Read, Write, Edit, WebFetch
Umbraco Sorter
What is it?
The UmbSorterController provides drag-and-drop sorting functionality for lists of items in the Umbraco backoffice. It handles reordering items within a container, moving items between containers, and supports nested sorting scenarios. This is useful for block editors, content trees, and any UI that requires user-driven ordering.
Key: Both lists use the same identifier in their UmbSorterController to enable dragging between them.
UmbSorterController Options
Option
Type
Description
identifier
string
Shared ID for connected sorters (enables cross-container dragging)
itemSelector
string
CSS selector for sortable items
containerSelector
string
CSS selector for the container
getUniqueOfElement
(element) => string
Extract unique ID from DOM element
getUniqueOfModel
(model) => string
Extract unique ID from data model
onChange
({ model }) => void
Called when order changes
onStart
() => void
Called when dragging starts
onEnd
() => void
Called when dragging ends
Key Methods
// Set the model (call when items change externally)this.#sorter.setModel(items);
// Get current modelconst currentItems = this.#sorter.getModel();
// Disable sorting temporarilythis.#sorter.disable();
// Re-enable sortingthis.#sorter.enable();
CSS Classes Applied During Drag
Class
Applied To
When
.umb-sorter-dragging
Container
While any item is being dragged
.umb-sorter-placeholder
Placeholder element
Indicates drop position
Best Practices
Use unique identifiers - Each item must have a unique ID
Match selectors carefully - itemSelector and containerSelector must match your DOM
Share identifier - Use same identifier for connected sorters
Handle nested updates - Propagate changes up through nested structures
Use repeat directive - Always use repeat() with a key function for proper DOM diffing
Provide visual feedback - Style drag handles and drop zones clearly