Skip to content

Commit 7ea1b4c

Browse files
authored
feat(Table): add OverscanCount parameter (#5730)
* doc: 更新资源文件键值 * refactor: 更改变量可见性 * feat: 增加 OverscanCount 参数 * test: 更新单元测试 * test: 更新单元测试 * refactor: 代码格式化 * Revert "refactor: 代码格式化" This reverts commit 35b74d6. * Revert "test: 更新单元测试" This reverts commit f574004. * refactor: 代码格式化 * Revert "test: 更新单元测试" This reverts commit 22d153f. * Reapply "test: 更新单元测试" This reverts commit 370c624. * Revert "refactor: 更改变量可见性" This reverts commit 0c234b2. * refactor: 更新私有属性为私有变量
1 parent da29238 commit 7ea1b4c

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4885,7 +4885,7 @@
48854885
"Affix": "Affix",
48864886
"Watermark": "Watermark",
48874887
"OctIcon": "Oct Icons",
4888-
"UniverIcons": "Univer Icons",
4888+
"UniverIcon": "Univer Icons",
48894889
"Typed": "Typed",
48904890
"UniverSheet": "UniverSheet"
48914891
},

src/BootstrapBlazor/Components/Table/Table.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,13 @@
369369
{
370370
@if (Items != null)
371371
{
372-
<Virtualize ItemSize="RowHeight" OverscanCount="10" Items="@Items.ToList()" ChildContent="RenderRow">
372+
<Virtualize ItemSize="RowHeight" OverscanCount="@OverscanCount" Items="@Items.ToList()" ChildContent="RenderRow">
373373
</Virtualize>
374374
}
375375
else
376376
{
377377
<Virtualize @ref="_virtualizeElement"
378-
ItemSize="RowHeight" OverscanCount="10" Placeholder="RenderPlaceholderRow"
378+
ItemSize="RowHeight" OverscanCount="@OverscanCount" Placeholder="RenderPlaceholderRow"
379379
ItemsProvider="LoadItems" ItemContent="RenderRow">
380380
</Virtualize>
381381
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ protected async Task QueryData(bool triggerByPagination = false)
484484
else
485485
{
486486
ResetSelectedRows(Items);
487-
RowsCache = null;
487+
_rowsCache = null;
488488
}
489489
return;
490490

@@ -513,7 +513,7 @@ async Task OnQuery(QueryPageOptions queryOption)
513513
}
514514

515515
// 更新数据后清除缓存防止新数据不显示
516-
RowsCache = null;
516+
_rowsCache = null;
517517
return;
518518

519519
void ProcessData()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ protected async Task<bool> SaveModelAsync(EditContext context, ItemChangedType c
648648
if (DynamicContext != null)
649649
{
650650
await DynamicContext.SetValue(context.Model);
651-
RowsCache = null;
651+
_rowsCache = null;
652652
valid = true;
653653
}
654654
else
@@ -1095,7 +1095,7 @@ private void ResetDynamicContext()
10951095

10961096
private void QueryDynamicItems(QueryPageOptions queryOption, IDynamicObjectContext? context)
10971097
{
1098-
RowsCache = null;
1098+
_rowsCache = null;
10991099
if (context != null)
11001100
{
11011101
var items = context.GetItems();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public partial class Table<TItem>
2828
/// <summary>
2929
/// 获得/设置 树形数据集合
3030
/// </summary>
31-
[NotNull]
3231
private List<TableTreeNode<TItem>> TreeRows { get; } = new(100);
3332

3433
/// <summary>
@@ -107,7 +106,7 @@ protected Func<Task> ToggleTreeRow(TItem item) => async () =>
107106
IsLoadChildren = false;
108107

109108
// 清除缓存
110-
RowsCache = null;
109+
_rowsCache = null;
111110

112111
// 更新 UI
113112
StateHasChanged();
@@ -121,6 +120,7 @@ private async Task<IEnumerable<IExpandableNode<TItem>>> GetChildrenRowAsync(Tabl
121120
{
122121
throw new InvalidOperationException(NotSetOnTreeExpandErrorMessage);
123122
}
123+
124124
return await OnTreeExpand(node.Value);
125125
}
126126
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ private string GetSortTooltip(ITableColumn col) => SortName != col.GetFieldName(
370370
[Parameter]
371371
public float RowHeight { get; set; } = 38f;
372372

373+
/// <summary>
374+
/// Gets or sets the overscan count for virtual scrolling. Default is 10.
375+
/// </summary>
376+
/// <remarks>Effective when <see cref="ScrollMode"/> is set to <see cref="ScrollMode.Virtual"/>.</remarks>
377+
[Parameter]
378+
public int OverscanCount { get; set; } = 10;
379+
373380
[Inject]
374381
[NotNull]
375382
private IOptionsMonitor<BootstrapBlazorOptions>? Options { get; set; }
@@ -928,7 +935,7 @@ protected override void OnParametersSet()
928935
IsPagination = false;
929936
}
930937

931-
RowsCache = null;
938+
_rowsCache = null;
932939

933940
if (IsExcel)
934941
{
@@ -1267,7 +1274,7 @@ protected async Task LoopQueryAsync()
12671274
private IEnumerable<TItem> QueryItems { get; set; } = [];
12681275

12691276
[NotNull]
1270-
private List<TItem>? RowsCache { get; set; }
1277+
private List<TItem>? _rowsCache = null;
12711278

12721279
/// <summary>
12731280
/// 获得 当前表格所有 Rows 集合
@@ -1279,8 +1286,8 @@ public List<TItem> Rows
12791286
// https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I5JG5D
12801287
// 如果 QueryItems 无默认值
12811288
// 页面 OnInitializedAsync 二刷再 OnAfterRender 过程中导致 QueryItems 变量为空 ToList 报错
1282-
RowsCache ??= IsTree ? TreeRows.GetAllItems() : [.. (Items ?? QueryItems)];
1283-
return RowsCache;
1289+
_rowsCache ??= IsTree ? TreeRows.GetAllItems() : [.. (Items ?? QueryItems)];
1290+
return _rowsCache;
12841291
}
12851292
}
12861293

test/UnitTest/Components/TableTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,7 @@ public void IsFixedFooter_Ok()
21042104
pb.Add(a => a.RenderMode, TableRenderMode.Table);
21052105
pb.Add(a => a.ScrollMode, ScrollMode.Virtual);
21062106
pb.Add(a => a.RowHeight, 39.5f);
2107+
pb.Add(a => a.OverscanCount, 10);
21072108
pb.Add(a => a.ShowFooter, true);
21082109
pb.Add(a => a.IsFixedFooter, true);
21092110
pb.Add(a => a.Items, Foo.GenerateFoo(localizer));

0 commit comments

Comments
 (0)