[PR #1549] Index calculation when adding panels dynamically #2803

Open
opened 2026-01-29 18:20:33 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/radzenhq/radzen-blazor/pull/1549

State: closed
Merged: No


This fixes an issue when dynamically inserting panels into the middle of a collection.

    <RadzenSplitter>

        @if (FirstItems is { Count: > 0 })
        {
            @foreach (var c in FirstItems)
            {
                <RadzenSplitterPane>
                    <SomeComponent1>
                    </SomeComponent1>
                </RadzenSplitterPane>
            }
        }

        @if (LastItem is not null)
        {
            <RadzenSplitterPane>
                <SomeComponent2>
                </SomeComponent2>
            </RadzenSplitterPane>
        }

    </RadzenSplitter>

If you first add LastItem, and then FirstItems, the index of the latter will not be calculated correctly.

But it will work like this:

    <RadzenSplitter UseGetIndex="true">

        @if (FirstItems is { Count: > 0 })
        {
            @foreach (var c in FirstItems)
            {
                <RadzenSplitterPane GetIndex="() => Array.IndexOf(FirstItems.ToArray(), c)">
                    <SomeComponent1>
                    </SomeComponent1>
                </RadzenSplitterPane>
            }
        }

        @if (LastItem is not null)
        {
            <RadzenSplitterPane GetIndex="() => FirstItems.Count">
                <SomeComponent2>
                </SomeComponent2>
            </RadzenSplitterPane>
        }

    </RadzenSplitter>
**Original Pull Request:** https://github.com/radzenhq/radzen-blazor/pull/1549 **State:** closed **Merged:** No --- This fixes an issue when dynamically inserting panels into the middle of a collection. ``` <RadzenSplitter> @if (FirstItems is { Count: > 0 }) { @foreach (var c in FirstItems) { <RadzenSplitterPane> <SomeComponent1> </SomeComponent1> </RadzenSplitterPane> } } @if (LastItem is not null) { <RadzenSplitterPane> <SomeComponent2> </SomeComponent2> </RadzenSplitterPane> } </RadzenSplitter> ``` If you first add LastItem, and then FirstItems, the index of the latter will not be calculated correctly. But it will work like this: ``` <RadzenSplitter UseGetIndex="true"> @if (FirstItems is { Count: > 0 }) { @foreach (var c in FirstItems) { <RadzenSplitterPane GetIndex="() => Array.IndexOf(FirstItems.ToArray(), c)"> <SomeComponent1> </SomeComponent1> </RadzenSplitterPane> } } @if (LastItem is not null) { <RadzenSplitterPane GetIndex="() => FirstItems.Count"> <SomeComponent2> </SomeComponent2> </RadzenSplitterPane> } </RadzenSplitter> ```
claunia added the pull-request label 2026-01-29 18:20:33 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#2803