You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

BlazorSortable

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

BlazorSortable

A Blazor component that wraps the SortableJS library to provide interactive, drag-and-drop list reordering functionality.

3.1.2
nugetNuGet
Version published
Maintainers
1
Created
Source

BlazorSortable

BlazorSortable icon

NuGet Version NuGet Downloads

A Blazor component that wraps the SortableJS library, designed for creating interactive sortable lists with drag-and-drop support. Inspired by BlazorSortable and represents an improved and extended implementation.

Installation

Via dotnet CLI

dotnet add package BlazorSortable

Via PackageReference

Add to your .csproj file:

<ItemGroup>
  <PackageReference Include="BlazorSortable" Version="3.*" />
</ItemGroup>

Setup

  • Add the SortableJS library to:

    • wwwroot/index.html (for Blazor WebAssembly)
    • Components/App.razor (for Blazor Web App)
    • Pages/_Host.cshtml (for Blazor Server)

    Using one of the following methods:

    a) Via CDN:

    <script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
    

    b) Locally:

    <script src="lib/sortable/dist/js/Sortable.min.js"></script>
    

    For local installation:

    • Download the latest version of SortableJS from GitHub
    • Create the folder structure in wwwroot: lib/sortable/dist/js/
    • Place the Sortable.min.js file in the created folder
    • Ensure the path in the script tag matches the file location
  • (Optional) Add base styles to the same file where you added the script:

<link rel="stylesheet" href="_content/BlazorSortable/css/blazor-sortable.css" />
  • Add services in Program.cs:
using BlazorSortable;

// ...

builder.Services.AddSortableServices();
  • Add the using directive in _Imports.razor:
@using BlazorSortable

Usage Examples

SortableList

<SortableList Items="Persons"
              Class="my-sortable-list"
              Group="group1">
    <PersonComponent Person="context" />
</SortableList>
<SortableList TItem="Person"
              Items="Persons"
              Class="my-sortable-list"
              Group="group1"
              Context="person">
    <div class="person-card">
        <h4>@person.Name</h4>
        <p>@person.Email</p>
        <span class="badge">@person.Department</span>
    </div>
</SortableList>

SortableDropZone

<SortableDropZone Class="my-sortable-drop-zone"
                  Group="group1"
                  OnDrop="OnDrop" />

Events

Events use Action<T> instead of EventCallback<T>. Reason: EventCallback.InvokeAsync automatically triggers StateHasChanged() in the parent component. For this component, this causes conflicts between DOM and data model.

All events receive a SortableEventArgs<TItem> parameter containing information about the operation.

SortableEventArgs

The SortableEventArgs<TItem> class provides information about sorting operations:

PropertyTypeDescription
TItemThe type of the item
ItemTItemThe item participating in the operation
FromISortableSource sortable component
OldIndexintThe previous index of the item in the source sortable
ToISortableTarget sortable component
NewIndexintThe new index of the item in the target sortable
IsCloneboolFlag indicating whether the item is a clone

SortableTransferContext

The SortableTransferContext<TItem> class represents the context of transferring an item between sortable components:

PropertyTypeDescription
TItemThe type of the item being transferred
ItemTItemThe item being transferred between sortable components
FromISortableThe source sortable component
ToISortableThe target sortable component

ISortable

The ISortable interface provides information about a sortable component:

PropertyTypeDescription
IdstringUnique identifier of the component
GroupstringGroup name for interaction with other Sortable components

Order & Notes

  • Order of events when dragging between lists:
    • OnAdd is triggered first.
    • OnRemove is triggered after.
  • During OnAdd, the item is still present in the source list.

Component Parameters

Note: MultiDrag plugin support will be added in future releases.

SortableList

ParameterTypeDefaultDescription
TItemThe type of items in the sortable list
ItemsIList<TItem>RequiredList of items to display and sort
ChildContentRenderFragment<TItem>nullTemplate for displaying each list item. Can be a component, HTML elements, or any Razor markup
KeySelectorFunc<TItem, object>nullFunction for generating the key used in @key. If not set, the item itself is used
ContextstringcontextName of the parameter used in the child content template to refer to the current item
ClassstringnullCSS class for the container
StylestringnullInline CSS styles for the container
AttributesIReadOnlyDictionary<string, object>nullAdditional custom attributes that will be rendered by the component
IdstringRandom GUIDUnique identifier of the component. Used internally for coordination between Sortable components. Must be globally unique
GroupstringRandom GUIDName of the group for interacting with other sortable instances
PullPullModenullMode for pulling items from the list
PullGroupsstring[]nullRequired when Pull="PullMode.Groups". Specifies the groups into which items from this list can be dragged
CloneFunctionFunc<TItem, TItem>nullRequired when Pull="PullMode.Clone". A factory method used to create a clone of the dragged item
OnCloneExceptionAction<Exception>nullRaised when an exception occurs during object cloning
PullFunctionFunc<SortableTransferContext<TItem>, bool>nullRequired when Pull="PullMode.Function". Function to determine if an item can be pulled to the target Sortable component
PutPutModenullMode for adding items to the list
PutGroupsstring[]nullRequired when Put="PutMode.Groups". Specifies the groups from which items are allowed to be added
PutFunctionFunc<SortableTransferContext<object>, bool>nullRequired when Put="PutMode.Function". Function to determine if an item can be put into this list. This function is invoked synchronously from JS using invokeMethod
ConvertFunctionFunc<SortableTransferContext<object>, TItem?>nullFunction to convert items from other Sortable component to the target type
OnConvertExceptionAction<Exception>nullRaised when an exception occurs during item conversion
SortbooltrueEnables or disables sorting of items within the list
DisabledboolfalseDisables the Sortable component when set to true
Animationint150Animation duration in milliseconds
HandlestringnullCSS selector for elements that can be dragged (e.g. ".my-handle")
FilterstringnullCSS selector for elements that cannot be dragged (e.g. ".ignore-elements")
DraggableSelectorFunc<TItem, bool>nullFunction to determine if an item can be dragged
DraggableClassstring"sortable-draggable"CSS class applied to items that can be dragged
GhostClassstring"sortable-ghost"CSS class for the placeholder during drag
ChosenClassstring"sortable-chosen"CSS class for the chosen element
DragClassstring"sortable-drag"CSS class for the dragged element
SwapThresholddouble1Threshold for swap detection during dragging (0-1)
ForceFallbackbooltrueForces fallback mode for dragging
FallbackClassstring"sortable-fallback"CSS class for the element in fallback mode
SwapboolfalseEnables swap mode for dragging
SwapClassstring"sortable-swap-highlight"CSS class applied to items during swap highlighting
ScrollbooltrueEnables scrolling of the container during dragging
OnUpdateAction<SortableEventArgs<TItem>>nullRaised when the order of items is changed
OnAddAction<SortableEventArgs<TItem>>nullRaised when an item is added to the list
OnRemoveAction<SortableEventArgs<TItem>>nullRaised when an item is removed from the list

SortableDropZone

ParameterTypeDefaultDescription
ClassstringnullCSS class for the container
StylestringnullInline CSS styles for the container
AttributesIReadOnlyDictionary<string, object>nullAdditional custom attributes that will be rendered by the component
IdstringRandom GUIDUnique identifier of the component. Used internally for coordination between Sortable components. Must be globally unique
GroupstringRandom GUIDName of the group for interacting with other sortable instances
PutPutModenullMode for adding items to the zone
PutGroupsstring[]nullRequired when Put="PutMode.Groups". Specifies the groups from which items are allowed to be added
PutFunctionFunc<SortableTransferContext<object>, bool>nullRequired when Put="PutMode.Function". Function to determine if an item can be put into this zone. This function is invoked synchronously from JS using invokeMethod
DisabledboolfalseDisables the Sortable component when set to true
GhostClassstring"sortable-ghost"CSS class for the placeholder during drag
OnDropAction<SortableEventArgs<object>>nullRaised when an item is dropped in the zone

PullMode

ValueDescription
TrueAllows pulling items from the list
FalseProhibits pulling items from the list
GroupsAllows pulling items only from specified groups (requires PullGroups parameter)
CloneCreates a clone of the item when dragging (requires CloneFunction parameter)
FunctionUses a custom function to determine if items can be pulled (requires PullFunction parameter)

PutMode

ValueDescription
TrueAllows adding items to the list
FalseProhibits adding items to the list
GroupsAllows adding items only from specified groups (requires PutGroups parameter)
FunctionUses a custom function to determine if items can be added (requires PutFunction parameter)

Keywords

blazor

FAQs

Package last updated on 09 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts