Skip to content

Why BlazorGridStackBody doesn't sync the new BlazorGridStackWidgetOptions added? #4

@nima-ghomri

Description

@nima-ghomri

I've created multiple sets of widgets so I could switch between them using a button.

Index.razor

@page "/"
@using BlazorGridStack.Models
@using System.Diagnostics.CodeAnalysis;

@foreach (var info in infos)
{
    <div>@info</div>
}

<button @onclick=OnClick>Change Widgets</button>
<BlazorGridStackBody @ref=grid GridStackOptions=options OnChange=OnChange>
    @foreach (var item in items)
    {
        <BlazorGridStackWidget WidgetOptions=item>
            <MyComponent Name=@item.Id.ToString() />
        </BlazorGridStackWidget>
    }
</BlazorGridStackBody>


@code {
    bool flag;
    [AllowNull]
    BlazorGridStackBody grid;
    BlazorGridStackBodyOptions options = new()
        {
            Row = 10
        };

    IEnumerable<string> infos = Enumerable.Empty<string>();
    IEnumerable<BlazorGridStackWidgetOptions> items => flag ? items1 : items2;
    IEnumerable<BlazorGridStackWidgetOptions> items1 = new[] {
        new BlazorGridStackWidgetOptions {Id = "A", W = 2, H = 2},
        new BlazorGridStackWidgetOptions {Id = "B", W = 3, H = 3, X = 3, Y = 0},
        new BlazorGridStackWidgetOptions {Id = "C", W = 3, H = 3, X = 3, Y = 3},
    };
    IEnumerable<BlazorGridStackWidgetOptions> items2 = new[] {
        new BlazorGridStackWidgetOptions {Id = "1", W = 2, H = 2},
        new BlazorGridStackWidgetOptions {Id = "2", W = 2, H = 2, X = 3, Y = 3},
    };

    void OnClick()
    {
        flag = !flag;
    }

    private void OnChange(BlazorGridStackWidgetListEventArgs e)
    {
        infos = e.Items.Select(x => $"Id: {x.Id ?? "NULL"}, Content: {x.Content.Substring(0, 20)}...");
    }
}

MyComponent.razor

<h3>@Name.ToUpper()</h3>

@code {
    [Parameter]
    public string Name { get; set; }
}

As the items get switched, not all the corresponding widgets get created by the body. Actually the 3rd widget "C", not getting detected by the body making it not draggable. how to make it to work? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions