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
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.2.9-beta03</Version>
<Version>9.2.9-beta04</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 5 additions & 3 deletions src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ protected void OnClickCardView()
StateHasChanged();
}

private async Task QueryAsync(bool shouldRender, int? pageIndex = null)
private async Task QueryAsync(bool shouldRender, int? pageIndex = null, bool triggerByPagination = false)
{
if (ScrollMode == ScrollMode.Virtual && VirtualizeElement != null)
{
Expand All @@ -405,7 +405,7 @@ private async Task QueryAsync(bool shouldRender, int? pageIndex = null)
{
PageIndex = pageIndex.Value;
}
await QueryData();
await QueryData(triggerByPagination);
await InternalToggleLoading(false);
}

Expand Down Expand Up @@ -451,12 +451,14 @@ protected async ValueTask InternalToggleLoading(bool state)
/// <summary>
/// 调用 OnQuery 回调方法获得数据源
/// </summary>
protected async Task QueryData()
protected async Task QueryData(bool triggerByPagination = false)
{
// 目前设计使用 Items 参数后不回调 OnQueryAsync 方法
if (Items == null)
{
var queryOption = BuildQueryPageOptions();
// 是否为分页查询
queryOption.TriggerByPagination = triggerByPagination;
// 设置是否为首次查询
queryOption.IsFirstQuery = _firstQuery;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected async Task OnPageLinkClick(int pageIndex)
}

// 无刷新查询数据
await QueryAsync(false);
await QueryAsync(false, triggerByPagination: true);

// 通知 SelectedRow 双向绑定集合改变
await OnSelectedRowsChanged();
Expand Down
5 changes: 5 additions & 0 deletions src/BootstrapBlazor/Options/QueryPageOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,9 @@ public class QueryPageOptions
/// </summary>
/// <remarks><see cref="Table{TItem}"/> 组件首次查询数据时为 true</remarks>
public bool IsFirstQuery { get; set; }

/// <summary>
/// 获得 是否为刷新分页查询 默认 false
/// </summary>
public bool TriggerByPagination { get; set; }
}
4 changes: 4 additions & 0 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ public void IsAutoQueryFirstQuery_Ok()
{
var isFirstQuery = true;
var isQuery = false;
var triggerByPagination = true;
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
Expand All @@ -1082,6 +1083,7 @@ public void IsAutoQueryFirstQuery_Ok()
{
isQuery = true;
isFirstQuery = option.IsFirstQuery;
triggerByPagination = option.TriggerByPagination;
return Task.FromResult(new QueryData<Foo>()
{
Items = Array.Empty<Foo>(),
Expand All @@ -1105,13 +1107,15 @@ public void IsAutoQueryFirstQuery_Ok()
// 首次加载为 true
Assert.True(isFirstQuery);
Assert.False(isQuery);
Assert.True(triggerByPagination);

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

Assert.False(isFirstQuery);
Assert.True(isQuery);
Assert.False(triggerByPagination);
}

[Fact]
Expand Down
Loading