[PR #1549] [CLOSED] Index calculation when adding panels dynamically #2801

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

📋 Pull Request Information

Original PR: https://github.com/radzenhq/radzen-blazor/pull/1549
Author: @AscarGb
Created: 6/8/2024
Status: Closed

Base: masterHead: radzen-splitter-pane-order-fix


📝 Commits (1)

  • 2010d8a Index calculation when adding panels dynamically

📊 Changes

2 files changed (+55 additions, -19 deletions)

View changed files

📝 Radzen.Blazor/RadzenSplitter.razor.cs (+46 -18)
📝 Radzen.Blazor/RadzenSplitterPane.razor.cs (+9 -1)

📄 Description

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>

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/radzenhq/radzen-blazor/pull/1549 **Author:** [@AscarGb](https://github.com/AscarGb) **Created:** 6/8/2024 **Status:** ❌ Closed **Base:** `master` ← **Head:** `radzen-splitter-pane-order-fix` --- ### 📝 Commits (1) - [`2010d8a`](https://github.com/radzenhq/radzen-blazor/commit/2010d8a33bb0f2b567adc5bbe4b3394e927c61aa) Index calculation when adding panels dynamically ### 📊 Changes **2 files changed** (+55 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `Radzen.Blazor/RadzenSplitter.razor.cs` (+46 -18) 📝 `Radzen.Blazor/RadzenSplitterPane.razor.cs` (+9 -1) </details> ### 📄 Description 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> ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#2801