Skip to content

Commit 89b2fd3

Browse files
committed
feat: 增加 IsAutoScrollTopWhenClickPage 参数
1 parent ee28d98 commit 89b2fd3

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ protected async Task OnPageLinkClick(int pageIndex)
169169

170170
// 通知 SelectedRow 双向绑定集合改变
171171
await OnSelectedRowsChanged();
172+
173+
// 通知 UI 滚动到顶端
174+
if(IsAutoScrollTopWhenClickPage)
175+
{
176+
await InvokeVoidAsync("scrollTop", Id);
177+
}
172178
}
173179
}
174180

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,12 @@ public async Task ExpandDetailRow(TItem item)
759759
[Parameter]
760760
public Func<List<TItem>, bool>? DisableEditButtonCallback { get; set; }
761761

762+
/// <summary>
763+
/// 获得/设置 翻页时是否自动滚动到顶部 默认 false
764+
/// </summary>
765+
[Parameter]
766+
public bool IsAutoScrollTopWhenClickPage { get; set; }
767+
762768
[CascadingParameter]
763769
private ContextMenuZone? ContextMenuZone { get; set; }
764770

src/BootstrapBlazor/Components/Table/Table.razor.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ export function init(id, invoke, options) {
2121
reset(id)
2222
}
2323

24+
export function scrollTop(id) {
25+
const table = Data.get(id)
26+
if (table === null) {
27+
return;
28+
}
29+
30+
const body = table.tables.length === 2 ? table.tables[1] : table.tables[0];
31+
body.parentElement.scrollTo({
32+
top: 0,
33+
left: 0,
34+
behavior: "smooth",
35+
});
36+
}
37+
2438
export function reloadColumnWidth(tableName) {
2539
const key = `bb-table-column-width-${tableName}`
2640
return localStorage.getItem(key);

0 commit comments

Comments
 (0)