Skip to content

Commit 9c0cecd

Browse files
authored
feat(Table): add SetRowStyleFormatter parameter (#7758)
* feat(Table): add SetRowStyleFormatter parameter * test: 增加单元测试 * chore: bump version 10.4.1-beta02
1 parent d739238 commit 9c0cecd

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

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>10.4.1-beta01</Version>
4+
<Version>10.4.1-beta02</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Table/Table.razor

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@
275275
}
276276
else
277277
{
278-
<DynamicElement class="@GetRowClassString(item, "table-row")" @key="GetKeyByITem(item)"
278+
<DynamicElement @key="GetKeyByITem(item)"
279+
class="@GetRowClassString(item, "table-row")" style="@GetRowStyleString(item)"
279280
TriggerContextMenu="ContextMenuZone != null"
280281
OnContextMenu="e => OnContextMenu(e, item)"
281282
@ontouchstart="e => OnTouchStart(e, item)"
@@ -747,7 +748,8 @@
747748
</thead>;
748749

749750
RenderFragment<TItem> RenderRow => item =>
750-
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" @key="GetKeyByITem(item)"
751+
@<DynamicElement @key="GetKeyByITem(item)" TagName="tr"
752+
class="@GetRowClassString(item)" style="@GetRowStyleString(item)"
751753
TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
752754
@ontouchstart="e => OnTouchStart(e, item)" @ontouchend="OnTouchEnd"
753755
TriggerClick="@(ClickToSelect || OnClickRowCallback != null)" OnClick="() => ClickRow(item)"

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ public partial class Table<TItem>
101101
[Parameter]
102102
public Func<TItem, string?>? SetRowClassFormatter { get; set; }
103103

104+
/// <summary>
105+
/// <para lang="zh">获得/设置 行样式格式回调委托</para>
106+
/// <para lang="en">Gets or sets Row Style Formatter Callback</para>
107+
/// </summary>
108+
[Parameter]
109+
public Func<TItem, string?>? SetRowStyleFormatter { get; set; }
110+
104111
/// <summary>
105112
/// <para lang="zh">获得/设置 取消保存后回调委托方法</para>
106113
/// <para lang="en">Gets or sets After Cancel Save Callback</para>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ public partial class Table<TItem> : ITable, IModelEqualityComparer<TItem> where
133133
.AddClass("is-edit", EditInCell)
134134
.Build();
135135

136+
/// <summary>
137+
/// <para lang="zh">获得 Body 内行内联样式</para>
138+
/// <para lang="en">Get Body Row Inline Style</para>
139+
/// </summary>
140+
protected string? GetRowStyleString(TItem item) => CssBuilder.Default()
141+
.AddClass(SetRowStyleFormatter?.Invoke(item))
142+
.Build();
143+
136144
/// <summary>
137145
/// <para lang="zh">明细行首小图标单元格样式</para>
138146
/// <para lang="en">Detail Row Icon Cell CSS Class</para>

test/UnitTest/Components/TableTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5405,6 +5405,7 @@ public void SetRowClassFormatter_Ok()
54055405
pb.Add(a => a.ShowLoading, false);
54065406
pb.Add(a => a.RenderModeResponsiveWidth, BreakPoint.Medium);
54075407
pb.Add(a => a.SetRowClassFormatter, foo => "test_row_class");
5408+
pb.Add(a => a.SetRowStyleFormatter, foo => "height: 36px;");
54085409
pb.Add(a => a.TableColumns, foo => builder =>
54095410
{
54105411
builder.OpenComponent<TableColumn<Foo, string>>(0);
@@ -5415,6 +5416,7 @@ public void SetRowClassFormatter_Ok()
54155416
});
54165417
});
54175418
cut.Contains("test_row_class");
5419+
cut.Contains("height: 36px;");
54185420
}
54195421

54205422
[Fact]

0 commit comments

Comments
 (0)