Skip to content

Commit cd681ef

Browse files
fix(Table): line no support SortableList (#6045)
* fix: 修复拖动导致不更新问题 * doc: 更新示例 * chore: bump version 9.6.4-beta02 * chore: bump version 9.6.4-beta02 Co-Authored-By: ChrisHsieh999 <[email protected]> * chore: bump version 9.6.4-beta02 * chore: bump version 9.6.3-beta01 * test: 更新单元测试 --------- Co-authored-by: ChrisHsieh999 <[email protected]>
1 parent 61769ed commit cd681ef

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/BootstrapBlazor.Server/Components/Samples/SortableLists.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@
186186
<DemoBlock Title="@Localizer["SortableListTableTitle"]"
187187
Introduction="@Localizer["SortableListTableIntro"]"
188188
Name="Table">
189-
<SortableList Option="_optionTable">
190-
<Table TItem="Foo" Items="@Items.Take(3)" IsStriped="true">
189+
<SortableList Option="_optionTable" OnUpdate="OnUpdateTable">
190+
<Table TItem="Foo" Items="@Items" IsStriped="true" ShowLineNo="true">
191191
<TableColumns>
192192
<TableColumn @bind-Field="@context.DateTime" Width="180" />
193193
<TableColumn @bind-Field="@context.Name" />

src/BootstrapBlazor.Server/Components/Samples/SortableLists.razor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ protected override void OnInitialized()
136136
AddItems3 = Foo.GenerateFoo(FooLocalizer, 12).Skip(8).ToList();
137137
}
138138

139+
private Task OnUpdateTable(SortableEvent @event)
140+
{
141+
var oldItem = Items[@event.OldIndex];
142+
Items.Remove(oldItem);
143+
Items.Insert(@event.NewIndex, oldItem);
144+
145+
StateHasChanged();
146+
return Task.CompletedTask;
147+
}
148+
139149
private Task OnUpdate(SortableEvent @event)
140150
{
141151
var oldIndex = @event.OldIndex;

src/BootstrapBlazor/Components/Table/Table.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
}
238238
else
239239
{
240-
<DynamicElement class="@GetRowClassString(item, "table-row")"
240+
<DynamicElement class="@GetRowClassString(item, "table-row")" @key="item"
241241
TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
242242
@ontouchstart="e => OnTouchStart(e, item)"
243243
@ontouchend="OnTouchEnd"
@@ -675,7 +675,7 @@
675675
</thead>;
676676

677677
RenderFragment<TItem> RenderRow => item =>
678-
@<DynamicElement TagName="tr" class="@GetRowClassString(item)"
678+
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" @key="item"
679679
TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
680680
@ontouchstart="e => OnTouchStart(e, item)" @ontouchend="OnTouchEnd"
681681
TriggerClick="@(ClickToSelect || OnClickRowCallback != null)" OnClick="() => ClickRow(item)"

test/UnitTest/Components/TableTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4582,6 +4582,7 @@ public async Task KeepSelectedRows_Ok()
45824582
await cut.InvokeAsync(() => nextBtn.Click());
45834583

45844584
//选中行数为空
4585+
inputs = cut.FindComponents<Checkbox<Foo>>();
45854586
checkboxs = inputs.Count(i => i.Instance.State == CheckboxState.Checked);
45864587
Assert.Equal(0, checkboxs);
45874588

@@ -4593,6 +4594,7 @@ public async Task KeepSelectedRows_Ok()
45934594
await cut.InvokeAsync(input.Instance.OnToggleClick);
45944595

45954596
//加上表头的复选框选中,结果有3项
4597+
inputs = cut.FindComponents<Checkbox<Foo>>();
45964598
checkboxs = inputs.Count(i => i.Instance.State == CheckboxState.Checked);
45974599
Assert.Equal(3, checkboxs);
45984600

@@ -4601,27 +4603,31 @@ public async Task KeepSelectedRows_Ok()
46014603
await cut.InvokeAsync(() => prevBtn.Click());
46024604

46034605
//恢复选中行数为0
4606+
inputs = cut.FindComponents<Checkbox<Foo>>();
46044607
checkboxs = inputs.Count(i => i.Instance.State == CheckboxState.Checked);
46054608
Assert.Equal(0, checkboxs);
46064609

46074610
//点击向前按钮翻页
46084611
await cut.InvokeAsync(() => prevBtn.Click());
46094612

46104613
//恢复选中行数为1
4614+
inputs = cut.FindComponents<Checkbox<Foo>>();
46114615
checkboxs = inputs.Count(i => i.Instance.State == CheckboxState.Checked);
46124616
Assert.Equal(1, checkboxs);
46134617

46144618
//点击向后翻页按钮
46154619
await cut.InvokeAsync(() => nextBtn.Click());
46164620

46174621
//恢复选中行数为0
4622+
inputs = cut.FindComponents<Checkbox<Foo>>();
46184623
checkboxs = inputs.Count(i => i.Instance.State == CheckboxState.Checked);
46194624
Assert.Equal(0, checkboxs);
46204625

46214626
//点击向后翻页按钮
46224627
await cut.InvokeAsync(() => nextBtn.Click());
46234628

46244629
//恢复选中行数为2,加上表头的复选框选中,结果有3项
4630+
inputs = cut.FindComponents<Checkbox<Foo>>();
46254631
checkboxs = inputs.Count(i => i.Instance.State == CheckboxState.Checked);
46264632
Assert.Equal(3, checkboxs);
46274633
}

0 commit comments

Comments
 (0)