From f0fd5dc37b87d21e4889358433cd2aeced15b92f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 26 Jan 2025 12:38:06 +0800 Subject: [PATCH] feat(SelectTable): add EmptyTemplate parameter (#5217) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 增加 EmptyTemplate 参数 * test: 增加单元测试 --- .../Components/Select/SelectTable.razor | 3 +- .../Components/Select/SelectTable.razor.cs | 12 ++++++ test/UnitTest/Components/SelectTableTest.cs | 38 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Select/SelectTable.razor b/src/BootstrapBlazor/Components/Select/SelectTable.razor index 4b795476538..c8b1e346ee6 100644 --- a/src/BootstrapBlazor/Components/Select/SelectTable.razor +++ b/src/BootstrapBlazor/Components/Select/SelectTable.razor @@ -46,7 +46,8 @@ SearchModel="SearchModel" SearchTemplate="SearchTemplate" CollapsedTopSearch="CollapsedTopSearch" CustomerSearchModel="CustomerSearchModel" CustomerSearchTemplate="CustomerSearchTemplate" IsPagination="IsPagination" PageItemsSource="PageItemsSource" ShowGotoNavigator="false" MaxPageLinkCount="3" - OnClickRowCallback="OnClickRowCallback" OnQueryAsync="OnQueryAsync"> + OnClickRowCallback="OnClickRowCallback" OnQueryAsync="OnQueryAsync" + ShowEmpty="ShowEmpty" EmptyTemplate="EmptyTemplate"> diff --git a/src/BootstrapBlazor/Components/Select/SelectTable.razor.cs b/src/BootstrapBlazor/Components/Select/SelectTable.razor.cs index b870da27d9f..d8a45b1ab35 100644 --- a/src/BootstrapBlazor/Components/Select/SelectTable.razor.cs +++ b/src/BootstrapBlazor/Components/Select/SelectTable.razor.cs @@ -67,6 +67,18 @@ namespace BootstrapBlazor.Components; [Parameter] public bool IsClearable { get; set; } + /// + /// 获得/设置 是否显示无数据空记录 默认 false 不显示 + /// + [Parameter] + public bool ShowEmpty { get; set; } + + /// + /// 获得/设置 无数据时显示模板 默认 null + /// + [Parameter] + public RenderFragment? EmptyTemplate { get; set; } + /// /// 获得/设置 IIconTheme 服务实例 /// diff --git a/test/UnitTest/Components/SelectTableTest.cs b/test/UnitTest/Components/SelectTableTest.cs index 7fe6564b7cb..5ece54ea84a 100644 --- a/test/UnitTest/Components/SelectTableTest.cs +++ b/test/UnitTest/Components/SelectTableTest.cs @@ -543,6 +543,44 @@ public void Group_OK() Assert.Equal(2, labels.Count); } + [Fact] + public void EmptyTemplate_OK() + { + var localizer = Context.Services.GetRequiredService>(); + var items = Foo.GenerateFoo(localizer); + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.OnQueryAsync, options => + { + return Task.FromResult(new QueryData() + { + Items = [], + IsAdvanceSearch = true, + IsFiltered = true, + IsSearch = true, + IsSorted = true + }); + }); + pb.Add(a => a.ShowEmpty, true); + pb.Add(a => a.EmptyTemplate, builder => builder.AddContent(0, "empty-template")); + pb.Add(a => a.Value, items[0]); + pb.Add(a => a.GetTextCallback, foo => foo.Name); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.AddAttribute(3, "Searchable", true); + builder.CloseComponent(); + }); + }); + }); + + cut.Contains("
empty-template
"); + } + private static Task> OnFilterQueryAsync(QueryPageOptions options, IEnumerable _filterItems) { _filterItems = _filterItems.Where(options.ToFilterFunc());