Sortable icon indicating copy to clipboard operation
Sortable copied to clipboard

[bug] When moving one item, another moves with it (Blazor Server)

Open nzdvis opened this issue 3 years ago • 6 comments

Describe the bug

I have two lists, one for rows and one for columns. When moving from column to row, and then back to column, another item moves with the first one.

It works fine when only running html and javascript.

The problem/bug seems to happen then I run StateHasChanged in Blazor, to update som of my other components.

But the weird part is, that I also run StateHasChanged when sorting, but then everything works fine.

Video of the problem: https://youtu.be/c-rBwSPlFRQ

(The flashing part in the video is when StateHasChanged runs, it makes some calculations and applies an overlay)

Expected behavior

Only the selected item should be moved.

Information

The environment is Blazor Server (dotnetcore 5)

sortablejs = 1.14.0

Code: JS

new Sortable(CERDimensions, {
    group: 'shared',
    animation: 150,
    dragClass: "dragPlaceholder-ce-item",
    ghostClass: "dragGhost-ce-item"
});

new Sortable(CECDimensions, {
    group: 'shared',
    animation: 150,
    dragClass: "dragPlaceholder-ce-item",
    ghostClass: "dragGhost-ce-item"
});

C#

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender)
    {
        var dotNetRef = DotNetObjectReference.Create(this);
        await _jsRunTime.InvokeVoidAsync("activateSortableJS", dotNetRef);
    }
    await base.OnAfterRenderAsync(firstRender);
}

nzdvis avatar Nov 29 '21 10:11 nzdvis

I tried logging the CustomEvent.

Output from moving column to row: image

Output from moving row back to column: image

Seems like the item is the wrong one, but the clone is the right one? I don't know how or why. because it's moving the right and wrong item.

nzdvis avatar Nov 29 '21 12:11 nzdvis

how are you rendering the list items? i also faced this weird bug when i tried to implement my own drag and drop and the problem was i did not use the @key attribute for each items

ivanjx avatar Dec 01 '21 14:12 ivanjx

I don't know anything about Blazor, but it could be interfering with the native browser drag and drop API. Only advice I can give is to try the option forceFallback: true. This circumvents native D&D api.

owen-m1 avatar Dec 02 '21 02:12 owen-m1

I use this in blazer server and I don’t notice this problem. Are you sure that you are rebuilding the list items correctly when calling StateHasChanged? It looks like the ABC_ITEM item may be rebuilt as a child of OLDSALESPERSON instead of a sibling?

clamchoda avatar Jun 24 '22 16:06 clamchoda

how are you rendering the list items? i also faced this weird bug when i tried to implement my own drag and drop and the problem was i did not use the @key attribute for each items

it's work tanks.

mhbayan avatar Jan 17 '24 06:01 mhbayan

Did you resolve this? I've run into now with current versions of everything. I have the same bug with sortableJS or jqueryui sortable. I've given the container and the items id and @key attributes. I'm stuck!

nibsonline avatar Jan 27 '24 09:01 nibsonline