Skip to content

Commit

Permalink
perf(Table): improve performance for select all on header (#4740)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArgoZhang authored Nov 26, 2024
1 parent 8308fb4 commit 541eadb
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/BootstrapBlazor/Components/Table/Table.razor.Checkbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,20 @@ protected CheckboxState HeaderCheckState()
var filterRows = ShowRowCheckboxCallback == null ? Rows : Rows.Where(ShowRowCheckboxCallback);
if (filterRows.Any())
{
if (filterRows.All(AnyRow))
if (!filterRows.Except(SelectedRows).Any())
{
// 所有行被选中
// all rows are selected
ret = CheckboxState.Checked;
}
else if (filterRows.Any(AnyRow))
else if (filterRows.Any(row => SelectedRows.Any(i => Equals(i, row))))
{
// 任意一行被选中
// any one row is selected
ret = CheckboxState.Indeterminate;
}
}
return ret;

bool AnyRow(TItem row) => SelectedRows.Any(i => Equals(i, row));
}

/// <summary>
Expand Down Expand Up @@ -104,7 +102,7 @@ protected CheckboxState HeaderCheckState()
/// <param name="val"></param>
protected virtual async Task OnHeaderCheck(CheckboxState state, TItem val)
{
SelectedRows.RemoveAll(x => Rows.Any(a => Equals(a, x)));
SelectedRows.RemoveAll(Rows.Intersect(SelectedRows).Contains);
if (state == CheckboxState.Checked)
{
SelectedRows.AddRange(ShowRowCheckboxCallback == null ? Rows : Rows.Where(ShowRowCheckboxCallback));
Expand Down

0 comments on commit 541eadb

Please sign in to comment.