Skip to content

Commit 9642a80

Browse files
authored
feat(SelectTable): add ShowToolbar parameter (#7668)
* refactor: 调整默认宽度防止分页折行 * feat(SelectTable): add ShowToolbar parameter * doc: 更新文档注释 * chore: bump version 10.3.3-beta01 * test: 更正单词拼写错误 * test: 增加 Toolbar 单元测试 * test: 更新单元测试
1 parent def30fc commit 9642a80

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
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.3.2</Version>
4+
<Version>10.3.3-beta01</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Select/SelectTable.razor

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
IsPagination="IsPagination" PageItemsSource="PageItemsSource" ShowGotoNavigator="false" MaxPageLinkCount="3"
8181
OnClickRowCallback="OnClickRowCallback" OnQueryAsync="OnQueryAsync"
8282
IsMultipleSelect="IsMultipleSelect" @bind-SelectedRows="SelectedItems"
83+
ShowToolbar="ShowToolbar" ToolbarTemplate="ToolbarTemplate"
84+
TableExtensionToolbarTemplate="TableExtensionToolbarTemplate"
85+
ShowDefaultButtons="false" ShowRefresh="false"
8386
ShowEmpty="ShowEmpty" EmptyTemplate="EmptyTemplate"></Table>
8487
</div>
8588
</RenderTemplate>

src/BootstrapBlazor/Components/Select/SelectTable.razor.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ namespace BootstrapBlazor.Components;
8888
public bool ShowAppendArrow { get; set; } = true;
8989

9090
/// <summary>
91-
/// <para lang="zh">获得/设置 弹窗表格最小宽度 默认为 null 未设置使用样式中的默认值</para>
92-
/// <para lang="en">Gets or sets Dropdown Table Min Width. Default null (use style default)</para>
91+
/// <para lang="zh">获得/设置 弹窗表格最小宽度 默认为 null 未设置使用样式中的默认值 602px</para>
92+
/// <para lang="en">Gets or sets Dropdown Table Min Width. Default null (use style default 602px)</para>
9393
/// </summary>
9494
[Parameter]
9595
public int? TableMinWidth { get; set; }
@@ -139,6 +139,27 @@ namespace BootstrapBlazor.Components;
139139
[Parameter]
140140
public string? MultiSelectedItemMaxWidth { get; set; }
141141

142+
/// <summary>
143+
/// <para lang="zh">获得/设置 是否显示工具栏 默认 false 不显示</para>
144+
/// <para lang="en">Gets or sets Whether to show toolbar. Default false</para>
145+
/// </summary>
146+
[Parameter]
147+
public bool ShowToolbar { get; set; }
148+
149+
/// <summary>
150+
/// <para lang="zh">获得/设置 表格 Toolbar 工具栏模板</para>
151+
/// <para lang="en">Gets or sets the table toolbar template, content appears center of toolbar</para>
152+
/// </summary>
153+
[Parameter]
154+
public RenderFragment? ToolbarTemplate { get; set; }
155+
156+
/// <summary>
157+
/// <para lang="zh">获得/设置 表格 Toolbar 工具栏右侧按钮模板,模板中内容出现在默认按钮后面</para>
158+
/// <para lang="en">Gets or sets the table toolbar right-side button template, content appears after the default buttons</para>
159+
/// </summary>
160+
[Parameter]
161+
public RenderFragment? TableExtensionToolbarTemplate { get; set; }
162+
142163
/// <summary>
143164
/// <para lang="zh">获得/设置 IIconTheme 服务实例</para>
144165
/// <para lang="en">Gets or sets IIconTheme Service Instance</para>

src/BootstrapBlazor/Components/Select/SelectTable.razor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function init(id, invoke) {
1010
}
1111

1212
const setWidth = () => {
13-
const minWidth = parseFloat(el.dataset.bbMinWidth || '580');
13+
const minWidth = parseFloat(el.dataset.bbMinWidth || '602');
1414
let width = getWidth(el);
1515
if (width < minWidth) {
1616
width = minWidth;

test/UnitTest/Components/SelectTableTest.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,59 @@ public async Task IsMultipleSelect_Ok()
686686
cut.Contains("multi-select-item-ph");
687687
}
688688

689+
[Fact]
690+
public void ToolbarTemplate_Ok()
691+
{
692+
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
693+
var items = Foo.GenerateFoo(localizer);
694+
var cut = Context.Render<BootstrapBlazorRoot>(pb =>
695+
{
696+
pb.AddChildContent<SelectTable<Foo>>(pb =>
697+
{
698+
pb.Add(a => a.OnQueryAsync, options =>
699+
{
700+
return Task.FromResult(new QueryData<Foo>()
701+
{
702+
Items = items,
703+
IsAdvanceSearch = true,
704+
IsFiltered = true,
705+
IsSearch = true,
706+
IsSorted = true
707+
});
708+
});
709+
pb.Add(a => a.GetTextCallback, foo => foo.Name);
710+
pb.Add(a => a.TableColumns, foo => builder =>
711+
{
712+
builder.OpenComponent<TableColumn<Foo, string>>(0);
713+
builder.AddAttribute(1, "Field", "Name");
714+
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
715+
builder.AddAttribute(3, "Searchable", true);
716+
builder.CloseComponent();
717+
});
718+
pb.Add(a => a.ShowToolbar, true);
719+
pb.Add(a => a.ToolbarTemplate, builder =>
720+
{
721+
builder.AddContent(0, "toolbar-template");
722+
});
723+
pb.Add(a => a.TableExtensionToolbarTemplate, builder =>
724+
{
725+
builder.AddContent(0, "toolbar-extension-template");
726+
});
727+
});
728+
});
729+
730+
cut.Contains("toolbar-template");
731+
cut.Contains("toolbar-extension-template");
732+
733+
var table = cut.FindComponent<SelectTable<Foo>>();
734+
table.Render(pb =>
735+
{
736+
pb.Add(a => a.ShowToolbar, false);
737+
});
738+
cut.DoesNotContain("toolbar-template");
739+
cut.DoesNotContain("toolbar-extension-template");
740+
}
741+
689742
private static Task<QueryData<Foo>> OnFilterQueryAsync(QueryPageOptions options, IEnumerable<Foo> _filterItems)
690743
{
691744
_filterItems = _filterItems.Where(options.ToFilterFunc<Foo>());

0 commit comments

Comments
 (0)