Skip to content

Commit

Permalink
fix(module: table): perf optimization & data source change issue (#1304)
Browse files Browse the repository at this point in the history
* 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 <shunjiey@hotmail.com>
  • Loading branch information
anddrzejb and ElderJames authored Apr 3, 2021
1 parent 12ca2f7 commit 5b0dbfb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
5 changes: 3 additions & 2 deletions components/table/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ RenderFragment<(Table<TItem> table, IEnumerable<TItem> 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)
Expand All @@ -158,7 +159,7 @@ RenderFragment<(Table<TItem> table, IEnumerable<TItem> 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);
Expand Down Expand Up @@ -192,7 +193,7 @@ RenderFragment<(Table<TItem> table, IEnumerable<TItem> 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)
{
<tr class="ant-table-expanded-row ant-table-expanded-row-level-1 @table.ExpandedRowClassName(currentRowData)"
style="@(currentRowData.Expanded?"":"display: none;")">
Expand Down
32 changes: 17 additions & 15 deletions components/table/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private QueryModel<TItem> Reload()
{
_treeExpandIconColumnIndex = ExpandIconColumnIndex + (_selection != null && _selection.ColIndex <= ExpandIconColumnIndex ? 1 : 0);
}

_waitingReload = false;
StateHasChanged();

return queryModel;
Expand Down Expand Up @@ -292,19 +292,6 @@ protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);

if (_waitingReloadAndInvokeChange)
{
_waitingReloadAndInvokeChange = false;
_waitingReload = false;

ReloadAndInvokeChange();
}
else if (_waitingReload)
{
_waitingReload = false;
Reload();
}

if (!firstRender)
{
this.FinishLoadPage();
Expand Down Expand Up @@ -349,7 +336,22 @@ protected override void OnParametersSet()
}
}

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;

Expand Down

0 comments on commit 5b0dbfb

Please sign in to comment.