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
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.9.0</Version>
<Version>9.9.1-beta02</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public class DynamicElement : BootstrapComponentBase
[Parameter]
public bool GenerateElement { get; set; } = true;

/// <summary>
/// 获得/设置 组件 Key 值
/// </summary>
[Parameter]
public object? Key { get; set; }

/// <summary>
/// BuildRenderTree 方法
/// </summary>
Expand Down Expand Up @@ -119,6 +125,11 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)

builder.AddContent(8, ChildContent);

if (Key != null)
{
builder.SetKey(Key);
}

if (GenerateElement || IsTriggerClick() || IsTriggerDoubleClick())
{
builder.CloseElement();
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 @@ -243,7 +243,7 @@
}
else
{
<DynamicElement class="@GetRowClassString(item, "table-row")" @key="item"
<DynamicElement class="@GetRowClassString(item, "table-row")" Key="GetKeyByITem(item)"
TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
@ontouchstart="e => OnTouchStart(e, item)"
@ontouchend="OnTouchEnd"
Expand Down Expand Up @@ -687,7 +687,7 @@
</thead>;

RenderFragment<TItem> RenderRow => item =>
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" @key="item"
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" Key="GetKeyByITem(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
8 changes: 8 additions & 0 deletions src/BootstrapBlazor/Components/Table/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ private string GetSortTooltip(ITableColumn col) => SortName != col.GetFieldName(
[Parameter]
public bool ShowColumnWidthTooltip { get; set; }

/// <summary>
/// 获得/设置 行 Key 回调方法
/// </summary>
[Parameter]
public Func<TItem, object?>? OnGetRowKey { get; set; }

private string ScrollWidthString => $"width: {ActualScrollWidth}px;";

private string? GetScrollStyleString(bool condition) => condition
Expand Down Expand Up @@ -1681,6 +1687,8 @@ private void OnTouchEnd()
TouchStart = false;
}

private object? GetKeyByITem(TItem item) => OnGetRowKey?.Invoke(item);

/// <summary>
/// Dispose 方法
/// </summary>
Expand Down
Loading