diff --git a/src/BootstrapBlazor/Components/ListView/ListView.razor b/src/BootstrapBlazor/Components/ListView/ListView.razor index 8f2ee33bf76..4493a83b7f8 100644 --- a/src/BootstrapBlazor/Components/ListView/ListView.razor +++ b/src/BootstrapBlazor/Components/ListView/ListView.razor @@ -10,43 +10,54 @@ }
- @if (BodyTemplate != null) + @if (Rows.Count > 0) { - if (GroupName == null) + if (BodyTemplate != null) { - foreach (var item in Rows) + if (GroupName == null) { -
- @BodyTemplate(item) -
+ foreach (var item in Rows) + { +
+ @BodyTemplate(item) +
+ } } - } - else if (Collapsible) - { - - - @RenderCollapsibleItems(GroupName) - - - } - else - { - foreach (var key in GetGroupItems(GroupName)) + else if (Collapsible) { -
-
@key.GroupName
-
- @foreach (var item in key.Items) - { -
- @BodyTemplate(item) -
- } + + + @RenderCollapsibleItems(GroupName) + + + } + else + { + foreach (var key in GetGroupItems(GroupName)) + { +
+
@key.GroupName
+
+ @foreach (var item in key.Items) + { +
+ @BodyTemplate(item) +
+ } +
-
+ } } } } + else if (EmptyTemplate != null) + { + @EmptyTemplate + } + else + { + @EmptyText + }
@if (FooterTemplate != null || Pageable) { diff --git a/src/BootstrapBlazor/Components/ListView/ListView.razor.cs b/src/BootstrapBlazor/Components/ListView/ListView.razor.cs index 523f45de544..40de42b1de7 100644 --- a/src/BootstrapBlazor/Components/ListView/ListView.razor.cs +++ b/src/BootstrapBlazor/Components/ListView/ListView.razor.cs @@ -128,6 +128,18 @@ public partial class ListView : BootstrapComponentBase [Parameter] public string? Height { get; set; } + /// + /// 获得/设置 无数据时模板 默认 null 未设置 + /// + [Parameter] + public RenderFragment? EmptyTemplate { get; set; } + + /// + /// 获得/设置 无数据时显示文字 默认 null 未设置使用资源文件设置文字 + /// + [Parameter] + public string? EmptyText { get; set; } + /// /// 获得/设置 当前页码 /// diff --git a/test/UnitTest/Components/ListViewTest.cs b/test/UnitTest/Components/ListViewTest.cs index befceb68fe9..63df5a1f26a 100644 --- a/test/UnitTest/Components/ListViewTest.cs +++ b/test/UnitTest/Components/ListViewTest.cs @@ -14,7 +14,7 @@ public void Items_Ok() { pb.Add(a => a.BodyTemplate, p => builder => builder.AddContent(0, $"{p.ImageUrl}-{p.Description}-{p.Category}")); }); - cut.Markup.Contains("listview-body"); + cut.Contains("listview-body"); } [Fact] @@ -24,7 +24,7 @@ public void Height_Ok() { pb.Add(a => a.Height, "50vh"); }); - cut.Markup.Contains("style=\"height: 50vh;\""); + cut.Contains("style=\"height: 50vh;\""); } [Fact] @@ -293,6 +293,32 @@ public void OnCollapseChanged_Ok() }); } + [Fact] + public void EmptyTemplate_Ok() + { + var cut = Context.RenderComponent>(pb => + { + pb.Add(a => a.OnQueryAsync, option => + { + var ret = new QueryData() + { + Items = [], + TotalCount = 0 + }; + return Task.FromResult(ret); + }); + pb.Add(a => a.EmptyTemplate, builder => builder.AddContent(0, "empty-template")); + }); + cut.Contains("empty-template"); + + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.EmptyTemplate, null); + pb.Add(a => a.EmptyText, "text-empty"); + }); + cut.Contains("text-empty"); + } + private class Product { public string? ImageUrl { get; set; }