Skip to content

Commit 2f53676

Browse files
authored
feat(Table): add IsGroupExtendButtons parameter (#7044)
* feat(Table): add UseButtonGroup parameter * refactor: 更改名字 * test: 增加单元测试 * refactor: 更改参数名称
1 parent d4e13e8 commit 2f53676

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

src/BootstrapBlazor/Components/Table/Table.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@
869869
RenderFragment<TItem> RenderExtendButtons => item =>
870870
@<div class="table-cell">
871871
<label>@ColumnButtonTemplateHeaderText</label>
872-
<span class="btn-group">
872+
<div class="@ExtendButtonGroupClassString">
873873
@if (BeforeRowButtonTemplate != null)
874874
{
875875
<TableExtensionButton OnClickButton="cell => OnClickExtensionButton(item, cell)">
@@ -897,13 +897,13 @@
897897
@RowButtonTemplate.Invoke(item)
898898
</TableExtensionButton>
899899
}
900-
</span>
900+
</div>
901901
</div>;
902902

903903
RenderFragment<TItem> RenderRowExtendButtons => item =>
904904
@<td class="@FixedExtendButtonsColumnClassString" style="@GetFixedExtendButtonsColumnStyleString()">
905905
<div class="@ExtendButtonsCellClassString">
906-
<div class="btn-group" @onclick:stopPropagation="true">
906+
<div class="@ExtendButtonGroupClassString" @onclick:stopPropagation="true">
907907
@{
908908
var isInCell = InCellMode && SelectedRows.FirstOrDefault() == item;
909909
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public partial class Table<TItem> : ITable, IModelEqualityComparer<TItem> where
4747
[Parameter]
4848
public int DefaultFixedColumnWidth { get; set; } = 200;
4949

50+
/// <summary>
51+
/// 获得/设置 是否使用按钮组显示行内扩展按钮 默认 true
52+
/// </summary>
53+
[Parameter]
54+
public bool IsGroupExtendButtons { get; set; } = true;
55+
5056
/// <summary>
5157
/// 获得/设置 内置虚拟化组件实例
5258
/// </summary>
@@ -153,6 +159,11 @@ public partial class Table<TItem> : ITable, IModelEqualityComparer<TItem> where
153159
.AddClass(ExtendButtonColumnAlignment.ToDescriptionString())
154160
.Build();
155161

162+
private string? ExtendButtonGroupClassString => CssBuilder.Default()
163+
.AddClass("btn-group", IsGroupExtendButtons)
164+
.AddClass("btn-separate", !IsGroupExtendButtons)
165+
.Build();
166+
156167
private string GetSortTooltip(ITableColumn col) => SortName != col.GetFieldName()
157168
? UnsetText
158169
: SortOrder switch

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,3 +968,7 @@ form .table .table-cell > textarea {
968968
.bb-sortable tr {
969969
cursor: pointer;
970970
}
971+
972+
.btn-separate > button:not(:last-child) {
973+
margin-inline-end: .25rem;
974+
}

test/UnitTest/Components/TableTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,17 @@ public void RowButtonTemplate_Ok()
20262026
});
20272027
});
20282028
});
2029+
2030+
cut.Contains("<div class=\"btn-group\">");
2031+
2032+
var table = cut.FindComponent<Table<Foo>>();
2033+
Assert.NotNull(table);
2034+
2035+
table.SetParametersAndRender(pb =>
2036+
{
2037+
pb.Add(a => a.IsGroupExtendButtons, false);
2038+
});
2039+
cut.Contains("<div class=\"btn-separate\">");
20292040
}
20302041

20312042
[Fact]

0 commit comments

Comments
 (0)