Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@
<DemoBlock Title="@Localizer["SortableListTableTitle"]"
Introduction="@Localizer["SortableListTableIntro"]"
Name="Table">
<SortableList Option="_optionTable">
<Table TItem="Foo" Items="@Items.Take(3)" IsStriped="true">
<SortableList Option="_optionTable" OnUpdate="OnUpdateTable">
<Table TItem="Foo" Items="@Items" IsStriped="true" ShowLineNo="true">
<TableColumns>
<TableColumn @bind-Field="@context.DateTime" Width="180" />
<TableColumn @bind-Field="@context.Name" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ protected override void OnInitialized()
AddItems3 = Foo.GenerateFoo(FooLocalizer, 12).Skip(8).ToList();
}

private Task OnUpdateTable(SortableEvent @event)
{
var oldItem = Items[@event.OldIndex];
Items.Remove(oldItem);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Validate indices before reordering

Add range checks for @event.OldIndex and @event.NewIndex before calling Remove or Insert to prevent out-of-range exceptions.

Items.Insert(@event.NewIndex, oldItem);

StateHasChanged();
return Task.CompletedTask;
}
Comment on lines +139 to +147
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Favor InvokeAsync(StateHasChanged) in event handlers

Await InvokeAsync(StateHasChanged) to ensure the UI update runs on the proper synchronization context in sortable event callbacks.

Suggested change
private Task OnUpdateTable(SortableEvent @event)
{
var oldItem = Items[@event.OldIndex];
Items.Remove(oldItem);
Items.Insert(@event.NewIndex, oldItem);
StateHasChanged();
return Task.CompletedTask;
}
private async Task OnUpdateTable(SortableEvent @event)
{
var oldItem = Items[@event.OldIndex];
Items.Remove(oldItem);
Items.Insert(@event.NewIndex, oldItem);
await InvokeAsync(StateHasChanged);
}


private Task OnUpdate(SortableEvent @event)
{
var oldIndex = @event.OldIndex;
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.6.4-beta01</Version>
<Version>9.6.4-beta02</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/Table/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
}
else
{
<DynamicElement class="@GetRowClassString(item, "table-row")"
<DynamicElement class="@GetRowClassString(item, "table-row")" @key="item"
TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
@ontouchstart="e => OnTouchStart(e, item)"
@ontouchend="OnTouchEnd"
Expand Down Expand Up @@ -675,7 +675,7 @@
</thead>;

RenderFragment<TItem> RenderRow => item =>
@<DynamicElement TagName="tr" class="@GetRowClassString(item)"
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" @key="item"
TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
@ontouchstart="e => OnTouchStart(e, item)" @ontouchend="OnTouchEnd"
TriggerClick="@(ClickToSelect || OnClickRowCallback != null)" OnClick="() => ClickRow(item)"
Expand Down
Loading