Skip to content

Commit c607323

Browse files
authored
feat(QueryPageOptions): add TriggerByPagination parameter (#5193)
* feat(QueryPageOptions): add TriggerByPagination parameter * test: 更新单元测试 * chore: bump version 9.2.9-beta04
1 parent 8526429 commit c607323

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.2.9-beta03</Version>
4+
<Version>9.2.9-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ protected void OnClickCardView()
392392
StateHasChanged();
393393
}
394394

395-
private async Task QueryAsync(bool shouldRender, int? pageIndex = null)
395+
private async Task QueryAsync(bool shouldRender, int? pageIndex = null, bool triggerByPagination = false)
396396
{
397397
if (ScrollMode == ScrollMode.Virtual && VirtualizeElement != null)
398398
{
@@ -405,7 +405,7 @@ private async Task QueryAsync(bool shouldRender, int? pageIndex = null)
405405
{
406406
PageIndex = pageIndex.Value;
407407
}
408-
await QueryData();
408+
await QueryData(triggerByPagination);
409409
await InternalToggleLoading(false);
410410
}
411411

@@ -451,12 +451,14 @@ protected async ValueTask InternalToggleLoading(bool state)
451451
/// <summary>
452452
/// 调用 OnQuery 回调方法获得数据源
453453
/// </summary>
454-
protected async Task QueryData()
454+
protected async Task QueryData(bool triggerByPagination = false)
455455
{
456456
// 目前设计使用 Items 参数后不回调 OnQueryAsync 方法
457457
if (Items == null)
458458
{
459459
var queryOption = BuildQueryPageOptions();
460+
// 是否为分页查询
461+
queryOption.TriggerByPagination = triggerByPagination;
460462
// 设置是否为首次查询
461463
queryOption.IsFirstQuery = _firstQuery;
462464

src/BootstrapBlazor/Components/Table/Table.razor.Pagination.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected async Task OnPageLinkClick(int pageIndex)
165165
}
166166

167167
// 无刷新查询数据
168-
await QueryAsync(false);
168+
await QueryAsync(false, triggerByPagination: true);
169169

170170
// 通知 SelectedRow 双向绑定集合改变
171171
await OnSelectedRowsChanged();

src/BootstrapBlazor/Options/QueryPageOptions.cs

+5
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,9 @@ public class QueryPageOptions
124124
/// </summary>
125125
/// <remarks><see cref="Table{TItem}"/> 组件首次查询数据时为 true</remarks>
126126
public bool IsFirstQuery { get; set; }
127+
128+
/// <summary>
129+
/// 获得 是否为刷新分页查询 默认 false
130+
/// </summary>
131+
public bool TriggerByPagination { get; set; }
127132
}

test/UnitTest/Components/TableTest.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ public void IsAutoQueryFirstQuery_Ok()
10701070
{
10711071
var isFirstQuery = true;
10721072
var isQuery = false;
1073+
var triggerByPagination = true;
10731074
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
10741075
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
10751076
{
@@ -1082,6 +1083,7 @@ public void IsAutoQueryFirstQuery_Ok()
10821083
{
10831084
isQuery = true;
10841085
isFirstQuery = option.IsFirstQuery;
1086+
triggerByPagination = option.TriggerByPagination;
10851087
return Task.FromResult(new QueryData<Foo>()
10861088
{
10871089
Items = Array.Empty<Foo>(),
@@ -1105,13 +1107,15 @@ public void IsAutoQueryFirstQuery_Ok()
11051107
// 首次加载为 true
11061108
Assert.True(isFirstQuery);
11071109
Assert.False(isQuery);
1110+
Assert.True(triggerByPagination);
11081111

11091112
// 二次查询
11101113
var table = cut.FindComponent<Table<Foo>>();
11111114
cut.InvokeAsync(() => table.Instance.QueryAsync());
11121115

11131116
Assert.False(isFirstQuery);
11141117
Assert.True(isQuery);
1118+
Assert.False(triggerByPagination);
11151119
}
11161120

11171121
[Fact]

0 commit comments

Comments
 (0)