From a9a0f2e937c9cd2c307df34c21e81fd8495e4b1e Mon Sep 17 00:00:00 2001 From: Andrzej Bakun Date: Sat, 3 Apr 2021 20:40:23 +0200 Subject: [PATCH] fix(module: table): perf optimization & data source change issue (#1304) * chore: add GitHub Actions for auto preview (#1205) * chore: add github actions for auto preview * fix setup job * chore: add GitHub Actions for auto preview (#1205) * fix(module:table): guard against false entries in _dataSourceCache * fix(module:table): perf - double to single render on datasource change * fix(module:table): perf optimization to avoid multiple renders Co-authored-by: James Yeung --- components/table/Table.razor | 5 +++-- components/table/Table.razor.cs | 32 +++++++++++++++++--------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/components/table/Table.razor b/components/table/Table.razor index a5c9fa55..87eb5515 100644 --- a/components/table/Table.razor +++ b/components/table/Table.razor @@ -146,6 +146,7 @@ RenderFragment<(Table table, IEnumerable showItems, int level)> bo var table = context.table; var showItems = context.showItems; var level = context.level; + var count = Math.Min(showItems.Count(), table._dataSourceCount); } @if (table._total <= 0) @@ -158,7 +159,7 @@ RenderFragment<(Table table, IEnumerable showItems, int level)> bo } else if (showItems != null && table.ColumnContext.Columns.Count > 0) { - for (int i = 0; i < showItems.Count(); i++) + for (int i = 0; i < count; i++) { var rowIndex = table.PageSize * (table.PageIndex - 1) + i + 1; var data = showItems.ElementAt(i); @@ -192,7 +193,7 @@ RenderFragment<(Table table, IEnumerable showItems, int level)> bo { @table.body((table, table.TreeChildren(data), level + 1)); } - @if (!hasChildren && table.ExpandTemplate != null && table.RowExpandable(currentRowData)) + @if (!hasChildren && table.ExpandTemplate != null && table.RowExpandable(currentRowData) && currentRowData.Expanded) { diff --git a/components/table/Table.razor.cs b/components/table/Table.razor.cs index de52832a..5ba6cdbf 100644 --- a/components/table/Table.razor.cs +++ b/components/table/Table.razor.cs @@ -241,7 +241,7 @@ namespace AntDesign { _treeExpandIconColumnIndex = ExpandIconColumnIndex + (_selection != null && _selection.ColIndex <= ExpandIconColumnIndex ? 1 : 0); } - + _waitingReload = false; StateHasChanged(); return queryModel; @@ -292,19 +292,6 @@ namespace AntDesign { base.OnAfterRender(firstRender); - if (_waitingReloadAndInvokeChange) - { - _waitingReloadAndInvokeChange = false; - _waitingReload = false; - - ReloadAndInvokeChange(); - } - else if (_waitingReload) - { - _waitingReload = false; - Reload(); - } - if (!firstRender) { this.FinishLoadPage(); @@ -349,7 +336,22 @@ namespace AntDesign } } - protected override bool ShouldRender() => this._shouldRender; + protected override bool ShouldRender() + { + if (_waitingReloadAndInvokeChange) + { + _waitingReloadAndInvokeChange = false; + _waitingReload = false; + + ReloadAndInvokeChange(); + } + else if (_waitingReload) + { + _waitingReload = false; + Reload(); + } + return this._shouldRender; + } void ITable.HasFixLeft() => _hasFixLeft = true;