Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<DemoBlock Title="@Localizer["TablesPageShowTopPaginationTitle"]"
Introduction="@Localizer["TablesPageShowTopPaginationIntro"]"
Name="ShowTopPagination">
<Table TItem="Foo"
IsPagination="true" ShowTopPagination="true" PageItemsSource="@PageItemsSource" _pageItems="10" OnQueryAsync="@OnQueryAsync">
<Table TItem="Foo" IsAutoScrollTopWhenClickPage="true" IsFixedHeader="true" Height="200"
IsPagination="true" ShowTopPagination="true" PageItemsSource="@PageItemsSource" OnQueryAsync="@OnQueryAsync">
<TableColumns>
<TableColumn @bind-Field="@context.DateTime" Width="180" />
<TableColumn @bind-Field="@context.Name" />
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"TablesPagePaginationTitle": "Pagination table",
"TablesPagePaginationIntro": "Set <code>IsPagination</code> to display the pagination component",
"TablesPageShowTopPaginationTitle": "Show on top",
"TablesPageShowTopPaginationIntro": "Set <code>ShowTopPagination</code> to <code>true</code> is the top display pagination component"
"TablesPageShowTopPaginationIntro": "Set <code>ShowTopPagination</code> to <code>true</code> is the top display pagination component. You can use <code>IsAutoScrollTopWhenClickPage</code> to control whether to automatically scroll to the top after turning the page. The default value is <code>false</code> to keep the scroll bar position"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesFixedColumn": {
"TablesFixedColumnTitle": "Fixed column",
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"TablesPagePaginationTitle": "分页表格",
"TablesPagePaginationIntro": "设置 <code>IsPagination</code> 显示分页组件",
"TablesPageShowTopPaginationTitle": "显示在顶端",
"TablesPageShowTopPaginationIntro": "设置 <code>ShowTopPagination</code> 为 <code>true</code> 是顶端显示分页组件"
"TablesPageShowTopPaginationIntro": "设置 <code>ShowTopPagination</code> 为 <code>true</code> 是顶端显示分页组件,可通过 <code>IsAutoScrollTopWhenClickPage</code> 控制是否翻页后自动滚动到顶端,默认值为 <code>false</code> 保持滚动条位置"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesFixedColumn": {
"TablesFixedColumnTitle": "固定列功能",
Expand Down
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.6.4-beta06</Version>
<Version>9.6.4</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ protected async Task OnPageLinkClick(int pageIndex)

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

// 通知 UI 滚动到顶端
if(IsAutoScrollTopWhenClickPage)
{
await InvokeVoidAsync("scrollTop", Id);
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/BootstrapBlazor/Components/Table/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,12 @@ public async Task ExpandDetailRow(TItem item)
[Parameter]
public Func<List<TItem>, bool>? DisableEditButtonCallback { get; set; }

/// <summary>
/// 获得/设置 翻页时是否自动滚动到顶部 默认 false
/// </summary>
[Parameter]
public bool IsAutoScrollTopWhenClickPage { get; set; }

[CascadingParameter]
private ContextMenuZone? ContextMenuZone { get; set; }

Expand Down Expand Up @@ -1055,7 +1061,7 @@ private async Task OnTableRenderAsync(bool firstRender)
},
new
{
Key = "align-left",
Key = "align-right",
Icon = "fa-solid fa-align-right",
Text = Localizer["AlignRightText"].Value,
Tooltip = Localizer["AlignRightTooltipText"].Value
Expand Down
14 changes: 14 additions & 0 deletions src/BootstrapBlazor/Components/Table/Table.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ export function init(id, invoke, options) {
reset(id)
}

export function scrollTop(id) {
const table = Data.get(id)
if (table === null) {
return;
}

const body = table.tables.length === 2 ? table.tables[1] : table.tables[0];
body.parentElement.scrollTo({
top: 0,
left: 0,
behavior: "smooth",
});
}

export function reloadColumnWidth(tableName) {
const key = `bb-table-column-width-${tableName}`
return localStorage.getItem(key);
Expand Down
3 changes: 2 additions & 1 deletion test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ public async Task PageItemsSource_Ok()
pb.Add(a => a.RenderMode, TableRenderMode.Table);
pb.Add(a => a.PageItemsSource, [2, 4, 8]);
pb.Add(a => a.IsPagination, true);
pb.Add(a => a.IsAutoScrollTopWhenClickPage, true);
pb.Add(a => a.OnQueryAsync, OnQueryAsync(localizer));
pb.Add(a => a.TableColumns, foo => builder =>
{
Expand Down Expand Up @@ -1058,7 +1059,7 @@ Task<QueryData<Foo>> MockOnQueryAsync(QueryPageOptions options)
return Task.FromResult(new QueryData<Foo>()
{
Items = items,
TotalCount = items.Count(),
TotalCount = 80,
IsAdvanceSearch = true,
IsFiltered = true,
IsSearch = true,
Expand Down