Skip to content

Commit

Permalink
feat(SelectTable): add EmptyTemplate parameter (#5217)
Browse files Browse the repository at this point in the history
* feat: 增加 EmptyTemplate 参数

* test: 增加单元测试
  • Loading branch information
ArgoZhang authored Jan 26, 2025
1 parent 895170d commit f0fd5dc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/BootstrapBlazor/Components/Select/SelectTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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"></Table>
OnClickRowCallback="OnClickRowCallback" OnQueryAsync="OnQueryAsync"
ShowEmpty="ShowEmpty" EmptyTemplate="EmptyTemplate"></Table>
</div>
</RenderTemplate>
</div>
12 changes: 12 additions & 0 deletions src/BootstrapBlazor/Components/Select/SelectTable.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ namespace BootstrapBlazor.Components;
[Parameter]
public bool IsClearable { get; set; }

/// <summary>
/// 获得/设置 是否显示无数据空记录 默认 false 不显示
/// </summary>
[Parameter]
public bool ShowEmpty { get; set; }

/// <summary>
/// 获得/设置 无数据时显示模板 默认 null
/// </summary>
[Parameter]
public RenderFragment? EmptyTemplate { get; set; }

/// <summary>
/// 获得/设置 IIconTheme 服务实例
/// </summary>
Expand Down
38 changes: 38 additions & 0 deletions test/UnitTest/Components/SelectTableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,44 @@ public void Group_OK()
Assert.Equal(2, labels.Count);
}

[Fact]
public void EmptyTemplate_OK()
{
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var items = Foo.GenerateFoo(localizer);
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<SelectTable<Foo>>(pb =>
{
pb.Add(a => a.OnQueryAsync, options =>
{
return Task.FromResult(new QueryData<Foo>()
{
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<TableColumn<Foo, string>>(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("<div class=\"empty\"><div class=\"empty-telemplate\">empty-template</div></div>");
}

private static Task<QueryData<Foo>> OnFilterQueryAsync(QueryPageOptions options, IEnumerable<Foo> _filterItems)
{
_filterItems = _filterItems.Where(options.ToFilterFunc<Foo>());
Expand Down

0 comments on commit f0fd5dc

Please sign in to comment.