Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 39 additions & 28 deletions src/BootstrapBlazor/Components/ListView/ListView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,54 @@
</div>
}
<div class="@BodyClassString">
@if (BodyTemplate != null)
@if (Rows.Count > 0)
{
if (GroupName == null)
if (BodyTemplate != null)
{
foreach (var item in Rows)
if (GroupName == null)
{
<div class="listview-item" @onclick="@(e => OnClick(item))">
@BodyTemplate(item)
</div>
foreach (var item in Rows)
{
<div class="listview-item" @onclick="@(e => OnClick(item))">
@BodyTemplate(item)
</div>
}
}
}
else if (Collapsible)
{
<Collapse IsAccordion="IsAccordion" OnCollapseChanged="OnCollapseChanged!">
<CollapseItems>
@RenderCollapsibleItems(GroupName)
</CollapseItems>
</Collapse>
}
else
{
foreach (var key in GetGroupItems(GroupName))
else if (Collapsible)
{
<div @key="@key.GroupName" class="accordion-item">
<div class="accordion-header">@key.GroupName</div>
<div class="accordion-body">
@foreach (var item in key.Items)
{
<div class="listview-item" @onclick="@(e => OnClick(item))">
@BodyTemplate(item)
</div>
}
<Collapse IsAccordion="IsAccordion" OnCollapseChanged="OnCollapseChanged!">
<CollapseItems>
@RenderCollapsibleItems(GroupName)
</CollapseItems>
</Collapse>
}
else
{
foreach (var key in GetGroupItems(GroupName))
{
<div @key="@key.GroupName" class="accordion-item">
<div class="accordion-header">@key.GroupName</div>
<div class="accordion-body">
@foreach (var item in key.Items)
{
<div class="listview-item" @onclick="@(e => OnClick(item))">
@BodyTemplate(item)
</div>
}
</div>
</div>
</div>
}
}
}
}
else if (EmptyTemplate != null)
{
@EmptyTemplate
}
else
{
@EmptyText
}
</div>
@if (FooterTemplate != null || Pageable)
{
Expand Down
12 changes: 12 additions & 0 deletions src/BootstrapBlazor/Components/ListView/ListView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ public partial class ListView<TItem> : BootstrapComponentBase
[Parameter]
public string? Height { get; set; }

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

/// <summary>
/// 获得/设置 无数据时显示文字 默认 null 未设置使用资源文件设置文字
/// </summary>
[Parameter]
public string? EmptyText { get; set; }

/// <summary>
/// 获得/设置 当前页码
/// </summary>
Expand Down
30 changes: 28 additions & 2 deletions test/UnitTest/Components/ListViewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -293,6 +293,32 @@ public void OnCollapseChanged_Ok()
});
}

[Fact]
public void EmptyTemplate_Ok()
{
var cut = Context.RenderComponent<ListView<Product>>(pb =>
{
pb.Add(a => a.OnQueryAsync, option =>
{
var ret = new QueryData<Product>()
{
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<RenderFragment?>(a => a.EmptyTemplate, null);
pb.Add(a => a.EmptyText, "text-empty");
});
cut.Contains("text-empty");
}

private class Product
{
public string? ImageUrl { get; set; }
Expand Down