Skip to content

Commit

Permalink
clear selection on sort or filter changed
Browse files Browse the repository at this point in the history
  • Loading branch information
w-ahmad committed Jun 13, 2024
1 parent c2d8d94 commit 56d470b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/WinUI.TableView/TableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ private void UpdateVerticalScrollBarMargin()

internal void ClearSorting()
{
DeselectAll();
CollectionView.SortDescriptions.Clear();

foreach (var header in Columns.Select(x => x.HeaderControl))
Expand All @@ -532,6 +533,7 @@ internal void ClearSorting()

internal void ClearFilters()
{
DeselectAll();
ActiveFilters.Clear();
CollectionView.RefreshFilter();

Expand Down Expand Up @@ -626,6 +628,7 @@ private void DeselectAllCells()
{
SelectedCellRanges.Clear();
OnCellSelectionChanged();
SetCurrentCell(null);
}

internal async void SelectCells(TableViewCellSlot slot, bool shiftKey, bool ctrlKey = false)
Expand Down
5 changes: 5 additions & 0 deletions src/WinUI.TableView/TableViewColumnHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ private void DoSort(SD direction, bool singleSorting = true)
}
}

_tableView.DeselectAll();

if (_tableView.CollectionView.SortDescriptions.FirstOrDefault(x => x.PropertyName == _propertyPath) is { } description)
{
_tableView.CollectionView.SortDescriptions.Remove(description);
Expand All @@ -88,6 +90,7 @@ private void ClearSorting()
{
if (CanSort && _tableView is not null && SortDirection is not null)
{
_tableView.DeselectAll();
SortDirection = null;

if (_tableView.CollectionView.SortDescriptions.FirstOrDefault(x => x.PropertyName == _propertyPath) is { } description)
Expand All @@ -102,6 +105,7 @@ private void ClearFilter()
if (_tableView?.ActiveFilters.ContainsKey(_propertyPath) == true)
{
_tableView.ActiveFilters.Remove(_propertyPath);
_tableView.DeselectAll();
}

IsFiltered = false;
Expand All @@ -116,6 +120,7 @@ private void ApplyFilter()
return;
}

_tableView.DeselectAll();
_tableView.ActiveFilters[_propertyPath] = Filter;
_tableView.CollectionView.RefreshFilter();
IsFiltered = true;
Expand Down

0 comments on commit 56d470b

Please sign in to comment.