RMN.Blazor.DragDrop 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package RMN.Blazor.DragDrop --version 2.0.0                
NuGet\Install-Package RMN.Blazor.DragDrop -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RMN.Blazor.DragDrop" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RMN.Blazor.DragDrop --version 2.0.0                
#r "nuget: RMN.Blazor.DragDrop, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RMN.Blazor.DragDrop as a Cake Addin
#addin nuget:?package=RMN.Blazor.DragDrop&version=2.0.0

// Install RMN.Blazor.DragDrop as a Cake Tool
#tool nuget:?package=RMN.Blazor.DragDrop&version=2.0.0                

Blazor.DragDrop

NuGet Version

This component provides simple and user-friendly drag and drop functionality for Blazor applications.

Features

  • Drag and drop items within a list, both horizontally and vertically.
  • Drag and drop items between multiple lists. (Coming soon)
  • Choose any HTML element to serve as the parent.
  • Use a drag handle to drag items only by the handle.
  • Fully customizable item template.
  • Support for both desktop and mobile devices.
  • And more...

How to set up

  1. Install the RMN.Blazor.DragDrop NuGet package in your project.

  2. Add the component namespace to your _Imports.razor file:

@using RMN.Blazor.DragDrop
  1. Add SortableJS:
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>

API

Properties

Name Type Default Description
Items List<TItem> [ ] List of items.
OrderPropertyName String "" Item's order property to update after reordering the list.
RootElement String "div" Element that will serve as the parent.
Id String Guid Id for the parent element.
Class String "" CSS classes for the parent element.
Style String "" Inline styles for the parent element.
DragHandleClass String "" CSS class for the drag handle.
UndraggableItemClass String "" CSS class for undraggable items.
AllowDragging Boolean true Enables or disables dragging of all items.
AllowReorder Boolean true Enables or disables reordering the list.
Context String context Parameter name for the list items.

Events

OnUpdate: The method to be called after reordering the list.

Examples

Basic example

<DragDropList Items="Items" Context="item">

    <ItemTemplate>
        <p>@item.Name</p>
    </ItemTemplate>

</DragDropList>

Advanced example 1

<DragDropList Items="Items"
              RootElement="ul"
              DragHandleClass="drag-handle"
              Context="item"
              OnUpdate="OnListUpdate">

    <ItemTemplate>
        <li>
            <i class="fa-solid fa-grip-vertical drag-handle"></i>
            <span>@item.Name</span>
        </li>
    </ItemTemplate>

</DragDropList>

Advanced example 2

<DragDropList Items="Items.OrderBy(x => x.Order).ToList()"
              OrderPropertyName="Order"
              RootElement="tbody"
              UndraggableItemClass="undraggable-item"
              Context="item"
              OnUpdate="OnListUpdate">

    <ItemTemplate>
        <tr class="@(item.Disabled ? "undraggable-item" : null)">
            <td>@item.Name</td>
        </tr>
    </ItemTemplate>

</DragDropList>

For updating the order property of your items after reordering the list, you have 2 options:

  1. Specify the order property name as shown in the example above.

  2. Update manually:

public async Task OnListUpdate() 
{
    Items.ForEach(x => x.Order = Items.IndexOf(x));

    // Saving to database or something else
}

Styling

For styling the item that is being dragged, use the class selector .dragging-item.

License

Project is licensed under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version 2.0.0

     BREAKING CHANGES:
     - Renamed "DragDrop" to "DragDropList".
     - Renamed "DragDropItem" to "ItemTemplate".
     - Renamed "Handle" to "DragHandleClass".
     - Renamed "Filter" to "UndraggableItemClass".
     - Renamed "Sort" to "AllowReorder".
     - Renamed "T" to "TItem".

     NEW FEATURES:
     - Added parameter "OrderPropertyName":
     You can now specify your item's order property name, and the property will automatically be updated after reordering the list.
     - Added parameter "AllowDragging":
     You can now enable or disable dragging of all items in the list.
     - Added parameter "Style":
     You can now add inline styles for the parent element.
     - Disposed of object references:
     Improved memory management by properly disposing of unused object references.

     OTHER CHANGES:
     - Minor corrections.
     - Updated documentation.

     DEPRECATION NOTICE:
     - Previous versions have been deprecated and unlisted. This version aligns with what was originally planned for 1.0.0.