Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(Table): improve performance for select all on header #4740

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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