Skip to content

Commit 1435764

Browse files
authored
feat(ISortableList): add ISortableList interface (#6527)
* feat: 增加 Key 参数 * refactor: 使用回调方法 GetKeyByITem 获得行 Key 值 * chore: bump version 9.9.1-beta02 * doc: 调整示例 * refactor: 增加键值 * doc: 更新示例 * refactor: 内置可拖动行样式 * feat: 增加 ISortableList 接口 * chore: bump version 9.9.1-beta04 * chore: 更新 SortableList 组件 * refactor: 增加级联参数 * refactor: 内置 SortableList 行键值逻辑向下兼容 * revert: 撤销更改 * revert: 撤销 Key 参数 * revert: 撤销依赖 * revert: 临时移除 OnGetRowKey 回调方法
1 parent 09e200c commit 1435764

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
Introduction="@Localizer["SortableListTableIntro"]"
188188
Name="Table">
189189
<SortableList Option="_optionTable" OnUpdate="OnUpdateTable">
190-
<Table TItem="Foo" Items="@Items" IsStriped="true" ShowLineNo="true">
190+
<Table TItem="Foo" Items="@Items" IsStriped="true" ShowLineNo="true" RenderMode="TableRenderMode.Table">
191191
<TableColumns>
192192
<TableColumn @bind-Field="@context.DateTime" Width="180" />
193193
<TableColumn @bind-Field="@context.Name" />

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.9.1-beta03</Version>
4+
<Version>9.9.1-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Components;
7+
8+
/// <summary>
9+
/// SortableList 组件接口
10+
/// </summary>
11+
public interface ISortableList
12+
{
13+
14+
}

src/BootstrapBlazor/Components/Table/Table.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
}
244244
else
245245
{
246-
<DynamicElement class="@GetRowClassString(item, "table-row")" @key="item"
246+
<DynamicElement class="@GetRowClassString(item, "table-row")" @key="GetKeyByITem(item)"
247247
TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
248248
@ontouchstart="e => OnTouchStart(e, item)"
249249
@ontouchend="OnTouchEnd"
@@ -692,7 +692,7 @@
692692
</thead>;
693693

694694
RenderFragment<TItem> RenderRow => item =>
695-
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" @key="item"
695+
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" @key="GetKeyByITem(item)"
696696
TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
697697
@ontouchstart="e => OnTouchStart(e, item)" @ontouchend="OnTouchEnd"
698698
TriggerClick="@(ClickToSelect || OnClickRowCallback != null)" OnClick="() => ClickRow(item)"

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ private string GetSortTooltip(ITableColumn col) => SortName != col.GetFieldName(
198198
[Parameter]
199199
public bool ShowColumnWidthTooltip { get; set; }
200200

201+
///// <summary>
202+
///// 获得/设置 行 Key 回调方法
203+
///// </summary>
204+
//[Parameter]
205+
//public Func<TItem, object?>? OnGetRowKey { get; set; }
206+
201207
private string ScrollWidthString => $"width: {ActualScrollWidth}px;";
202208

203209
private string? GetScrollStyleString(bool condition) => condition
@@ -780,6 +786,9 @@ public async Task ExpandDetailRow(TItem item)
780786
[CascadingParameter]
781787
private ContextMenuZone? ContextMenuZone { get; set; }
782788

789+
[CascadingParameter]
790+
private ISortableList? SortableList { get; set; }
791+
783792
[Inject]
784793
[NotNull]
785794
private IIconTheme? IconTheme { get; set; }
@@ -1681,6 +1690,8 @@ private void OnTouchEnd()
16811690
TouchStart = false;
16821691
}
16831692

1693+
private object? GetKeyByITem(TItem item) => SortableList != null ? item : null; //OnGetRowKey?.Invoke(item);
1694+
16841695
/// <summary>
16851696
/// Dispose 方法
16861697
/// </summary>

src/BootstrapBlazor/Components/Table/Table.razor.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,3 +963,7 @@ form .table .table-cell > textarea {
963963
border-bottom-color: var(--bs-primary);
964964
}
965965
}
966+
967+
.bb-sortable tr {
968+
cursor: pointer;
969+
}

0 commit comments

Comments
 (0)