Skip to content
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