Skip to content

Commit f99ad91

Browse files
authored
feat(Table): throw exception when set IsTree to true in virtualize mode (#5721)
* refactor: 更新变量名称 * refactor: 更新变量名称 * test: 更新单元测试
1 parent 7af1d0e commit f99ad91

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/BootstrapBlazor/Components/Table/Table.razor

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,12 @@
369369
{
370370
@if (Items != null)
371371
{
372-
<Virtualize @ref="VirtualizeElement"
373-
ItemSize="RowHeight" OverscanCount="10" Items="@Items.ToList()" ChildContent="RenderRow">
372+
<Virtualize ItemSize="RowHeight" OverscanCount="10" Items="@Items.ToList()" ChildContent="RenderRow">
374373
</Virtualize>
375374
}
376375
else
377376
{
378-
<Virtualize @ref="VirtualizeElement"
377+
<Virtualize @ref="_virtualizeElement"
379378
ItemSize="RowHeight" OverscanCount="10" Placeholder="RenderPlaceholderRow"
380379
ItemsProvider="LoadItems" ItemContent="RenderRow">
381380
</Virtualize>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ protected void OnClickCardView()
404404

405405
private async Task QueryAsync(bool shouldRender, int? pageIndex = null, bool triggerByPagination = false)
406406
{
407-
if (ScrollMode == ScrollMode.Virtual && VirtualizeElement != null)
407+
if (ScrollMode == ScrollMode.Virtual && _virtualizeElement != null)
408408
{
409-
await VirtualizeElement.RefreshDataAsync();
409+
await _virtualizeElement.RefreshDataAsync();
410410
}
411411
else
412412
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public partial class Table<TItem> : ITable, IModelEqualityComparer<TItem> where
3838
/// <summary>
3939
/// 获得/设置 内置虚拟化组件实例
4040
/// </summary>
41-
protected Virtualize<TItem>? VirtualizeElement { get; set; }
41+
[NotNull]
42+
private Virtualize<TItem>? _virtualizeElement = null;
4243

4344
/// <summary>
4445
/// 获得 Table 组件样式表

test/UnitTest/Components/TableTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8911,9 +8911,10 @@ public async Task TestLoopQueryAsync()
89118911

89128912
public RenderFragment RenderVirtualPlaceHolder() => new(builder =>
89138913
{
8914-
if (ScrollMode == ScrollMode.Virtual && VirtualizeElement != null)
8914+
var fieldInfo = GetType().BaseType!.GetField("_virtualizeElement", BindingFlags.NonPublic | BindingFlags.Instance)!;
8915+
if (ScrollMode == ScrollMode.Virtual && fieldInfo.GetValue(this) is Virtualize<Foo> element)
89158916
{
8916-
builder.AddContent(0, VirtualizeElement.Placeholder?.Invoke(new Microsoft.AspNetCore.Components.Web.Virtualization.PlaceholderContext()));
8917+
builder.AddContent(0, element.Placeholder?.Invoke(new PlaceholderContext()));
89178918
}
89188919
});
89198920

0 commit comments

Comments
 (0)