Skip to content

VeithBuergerhoff/BlazorSortableJS

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BlazorSortableJS

BlazorSortableJS is a Blazor Wrapper over JavaScript Sortable lib.

Sortable is a JavaScript library for reorderable drag-and-drop lists.

This is a very early project. However, it does function and is very much usable. The user experience will get better over.

NuGet Pre Release

  • _host.cshtml
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
<script src="_content/BlazorSortableJs/js/BlazorSortableJs.js"></script>
  • Usage
Sortable List
<SortableGroup Class="list-group" TItem="string" @ref="MyGroup">
    @foreach (var item in @MyGroup.Sortable.GetRaw())
    {
        <SortableItem Class="list-group-item" Item="item" TItem="string">@item.Data</SortableItem>
    }
</SortableGroup>
@code
{
    SortableGroup<string> MyGroup;
    bool FirstRun = true;
    List<string> items { get; set; } = new List<string> { "T1", "T2", "T3" };
    List<string> resultsList { get; set; } = new List<string>();

    protected override Task OnInitializedAsync()
    {
        resultsList = items;
        return base.OnInitializedAsync();
    }

    protected async override Task OnAfterRenderAsync()
    {
        if (FirstRun)
        {
            MyGroup.Sortable.SetData(items);
            await MyGroup.Sortable.Create(MyGroup.Id, new SortableJsOptions
            {
                group = "test",
                animation = 100,
            });         
            FirstRun = false;
            StateHasChanged();
        }
    }
}

Change Log

https://github.com/jbomhold3/BlazorSortableJS/releases

Packages

No packages published

Languages

  • C# 44.0%
  • JavaScript 16.6%
  • HTML 15.5%
  • CSS 14.4%
  • TypeScript 9.5%