Skip to content
Merged
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 @@ -4885,7 +4885,7 @@
"Affix": "Affix",
"Watermark": "Watermark",
"OctIcon": "Oct Icons",
"UniverIcons": "Univer Icons",
"UniverIcon": "Univer Icons",
"Typed": "Typed",
"UniverSheet": "UniverSheet"
},
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/Table/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@
{
@if (Items != null)
{
<Virtualize ItemSize="RowHeight" OverscanCount="10" Items="@Items.ToList()" ChildContent="RenderRow">
<Virtualize ItemSize="RowHeight" OverscanCount="@OverscanCount" Items="@Items.ToList()" ChildContent="RenderRow">
</Virtualize>
}
else
{
<Virtualize @ref="_virtualizeElement"
ItemSize="RowHeight" OverscanCount="10" Placeholder="RenderPlaceholderRow"
ItemSize="RowHeight" OverscanCount="@OverscanCount" Placeholder="RenderPlaceholderRow"
ItemsProvider="LoadItems" ItemContent="RenderRow">
</Virtualize>
}
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ protected async Task QueryData(bool triggerByPagination = false)
else
{
ResetSelectedRows(Items);
RowsCache = null;
_rowsCache = null;
}
return;

Expand Down Expand Up @@ -513,7 +513,7 @@ async Task OnQuery(QueryPageOptions queryOption)
}

// 更新数据后清除缓存防止新数据不显示
RowsCache = null;
_rowsCache = null;
return;

void ProcessData()
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ protected async Task<bool> SaveModelAsync(EditContext context, ItemChangedType c
if (DynamicContext != null)
{
await DynamicContext.SetValue(context.Model);
RowsCache = null;
_rowsCache = null;
valid = true;
}
else
Expand Down Expand Up @@ -1095,7 +1095,7 @@ private void ResetDynamicContext()

private void QueryDynamicItems(QueryPageOptions queryOption, IDynamicObjectContext? context)
{
RowsCache = null;
_rowsCache = null;
if (context != null)
{
var items = context.GetItems();
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/Table/Table.razor.TreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public partial class Table<TItem>
/// <summary>
/// 获得/设置 树形数据集合
/// </summary>
[NotNull]
private List<TableTreeNode<TItem>> TreeRows { get; } = new(100);

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

// 清除缓存
RowsCache = null;
_rowsCache = null;

// 更新 UI
StateHasChanged();
Expand All @@ -121,6 +120,7 @@ private async Task<IEnumerable<IExpandableNode<TItem>>> GetChildrenRowAsync(Tabl
{
throw new InvalidOperationException(NotSetOnTreeExpandErrorMessage);
}

return await OnTreeExpand(node.Value);
}
}
15 changes: 11 additions & 4 deletions src/BootstrapBlazor/Components/Table/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ private string GetSortTooltip(ITableColumn col) => SortName != col.GetFieldName(
[Parameter]
public float RowHeight { get; set; } = 38f;

/// <summary>
/// Gets or sets the overscan count for virtual scrolling. Default is 10.
/// </summary>
/// <remarks>Effective when <see cref="ScrollMode"/> is set to <see cref="ScrollMode.Virtual"/>.</remarks>
[Parameter]
public int OverscanCount { get; set; } = 10;

[Inject]
[NotNull]
private IOptionsMonitor<BootstrapBlazorOptions>? Options { get; set; }
Expand Down Expand Up @@ -928,7 +935,7 @@ protected override void OnParametersSet()
IsPagination = false;
}

RowsCache = null;
_rowsCache = null;

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

[NotNull]
private List<TItem>? RowsCache { get; set; }
private List<TItem>? _rowsCache = null;

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

Expand Down
1 change: 1 addition & 0 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,7 @@ public void IsFixedFooter_Ok()
pb.Add(a => a.RenderMode, TableRenderMode.Table);
pb.Add(a => a.ScrollMode, ScrollMode.Virtual);
pb.Add(a => a.RowHeight, 39.5f);
pb.Add(a => a.OverscanCount, 10);
pb.Add(a => a.ShowFooter, true);
pb.Add(a => a.IsFixedFooter, true);
pb.Add(a => a.Items, Foo.GenerateFoo(localizer));
Expand Down