Skip to content

Commit b035872

Browse files
committed
!3764 feat(#I6ALST): add CollapsedGroupCallback parameter on ListView
* chore: bump version 7.2.4-beta01 * doc: 增加 CollapsedGroupCallback 参数说明文档 * refactor: 重命名回调方法 * doc: 更新资源文件 * doc: 精简示例 * refactor: 增加默认展开第一个分组项目逻辑 * doc: 更新示例文档 * feat: 增加 CollapsedGroupCallbackFirstRender 回调 * doc: 更新注释文档
1 parent 583c3fc commit b035872

8 files changed

Lines changed: 37 additions & 15 deletions

File tree

src/BootstrapBlazor.Shared/Locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4253,7 +4253,8 @@
42534253
"IsAccordion": "Group accordion",
42544254
"OnQueryAsync": "Asynchronous query callback method",
42554255
"OnListViewItemClick": "The ListView element calls back when it clicks on the delegate",
4256-
"QueryAsync": "Manually query data methods"
4256+
"QueryAsync": "Manually query data methods",
4257+
"CollapsedGroupCallback": "Callback for set the IsCollapsed parameter of Collapse component"
42574258
},
42584259
"BootstrapBlazor.Shared.Samples.Locators": {
42594260
"Title": "Get the IP geographic location",

src/BootstrapBlazor.Shared/Locales/zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4260,7 +4260,8 @@
42604260
"IsAccordion": "分组数据手风琴效果",
42614261
"OnQueryAsync": "异步查询回调方法",
42624262
"OnListViewItemClick": "ListView元素点击时回调委托",
4263-
"QueryAsync": "手工查询数据方法"
4263+
"QueryAsync": "手工查询数据方法",
4264+
"CollapsedGroupCallback": "组件分组项是否收缩回调委托方法"
42644265
},
42654266
"BootstrapBlazor.Shared.Samples.Locators": {
42664267
"Title": "获取 IP 地理位置",

src/BootstrapBlazor.Shared/Samples/ListViews.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
<DemoBlock Title="@Localizer["CollapsableTitle"]" Introduction="@Localizer["CollapsableIntro"]" Name="Collapsable">
7171
<div class="listview-demo">
72-
<ListView TItem="Product" GroupName="@(p => p.Category)" OnQueryAsync="@OnQueryAsync" Collapsable="true">
72+
<ListView TItem="Product" GroupName="@(p => p.Category)" OnQueryAsync="@OnQueryAsync" Collapsable="true" CollapsedGroupCallback="CollapsedGroupCallback">
7373
<HeaderTemplate>
7474
<div>@Localizer["ProductListText"]</div>
7575
</HeaderTemplate>

src/BootstrapBlazor.Shared/Samples/ListViews.razor.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ private Task OnListViewItemClick(Product item)
4646
return Task.CompletedTask;
4747
}
4848

49+
private static bool CollapsedGroupCallback(object? groupKey) => groupKey?.ToString() != "Group1";
50+
4951
private IEnumerable<AttributeItem> GetAttributes() => new AttributeItem[]
5052
{
5153
new AttributeItem(){
@@ -110,6 +112,13 @@ private Task OnListViewItemClick(Product item)
110112
Type = "Func<TItem, Task>",
111113
ValueList = " — ",
112114
DefaultValue = " — "
115+
},
116+
new AttributeItem() {
117+
Name = nameof(ListView<Foo>.CollapsedGroupCallback),
118+
Description = Localizer["CollapsedGroupCallback"],
119+
Type = "Func<object?, bool>",
120+
ValueList = " — ",
121+
DefaultValue = " — "
113122
}
114123
};
115124

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>7.2.3</Version>
4+
<Version>7.2.4-beta01</Version>
55
</PropertyGroup>
66

77
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">

src/BootstrapBlazor/Components/Collapse/CollapseItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class CollapseItem : BootstrapComponentBase, IDisposable
1616
public string? Text { get; set; }
1717

1818
/// <summary>
19-
/// 获得/设置 当前状态是否激活
19+
/// 获得/设置 当前状态是否激活 默认 true
2020
/// </summary>
2121
[Parameter]
2222
public bool IsCollapsed { get; set; } = true;

src/BootstrapBlazor/Components/ListView/ListView.razor

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@
2525
{
2626
<Collapse IsAccordion="IsAccordion" OnCollapseChanged="OnCollapseChanged!">
2727
<CollapseItems>
28-
@foreach (var key in Rows.GroupBy(GroupName).OrderBy(k => k.Key))
29-
{
30-
<CollapseItem @key="@key.Key" Text="@key.Key?.ToString()">
31-
@foreach (var item in key)
32-
{
33-
<div class="listview-item" @onclick="@(e => OnClick(item))">
34-
@BodyTemplate.Invoke(item)
35-
</div>
36-
}
37-
</CollapseItem>
28+
@{
29+
var index = 0;
30+
foreach (var key in Rows.GroupBy(GroupName).OrderBy(k => k.Key))
31+
{
32+
<CollapseItem @key="@key.Key" Text="@key.Key?.ToString()" IsCollapsed="IsCollapsed(index++, key.Key)">
33+
@foreach (var item in key)
34+
{
35+
<div class="listview-item" @onclick="@(e => OnClick(item))">
36+
@BodyTemplate.Invoke(item)
37+
</div>
38+
}
39+
</CollapseItem>
40+
}
3841
}
3942
</CollapseItems>
4043
</Collapse>

src/BootstrapBlazor/Components/ListView/ListView.razor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ public partial class ListView<TItem> : BootstrapComponentBase
7575
[Parameter]
7676
public Func<CollapseItem, Task>? OnCollapseChanged { get; set; }
7777

78+
/// <summary>
79+
/// 获得/设置 首次渲染是否收缩回调委托
80+
/// </summary>
81+
[Parameter]
82+
public Func<object?, bool>? CollapsedGroupCallback { get; set; }
83+
7884
/// <summary>
7985
/// 异步查询回调方法
8086
/// </summary>
@@ -125,6 +131,8 @@ protected override async Task OnParametersSetAsync()
125131
}
126132
}
127133

134+
private bool IsCollapsed(int index, object? groupKey) => CollapsedGroupCallback?.Invoke(groupKey) ?? index > 0;
135+
128136
/// <summary>
129137
/// 点击页码调用此方法
130138
/// </summary>

0 commit comments

Comments
 (0)