Skip to content

Commit 3b228df

Browse files
committed
use defer refresh when sorting and filtering
1 parent 2b7be4c commit 3b228df

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

src/TableViewColumnHeader.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Threading.Tasks;
1313
using Windows.System;
1414
using Windows.UI.Core;
15+
using WinUI.TableView.Collections;
1516
using WinUI.TableView.Extensions;
1617
using SD = WinUI.TableView.SortDirection;
1718

@@ -97,28 +98,23 @@ private void DoSort(SD? direction, bool singleSorting = true)
9798
{
9899
if (CanSort && Column is not null && _tableView is { CollectionView: CollectionView { } collectionView })
99100
{
100-
var defer = collectionView.DeferRefresh();
101+
using var defer = collectionView.DeferRefresh();
102+
if (singleSorting)
101103
{
102-
if (singleSorting)
103-
{
104-
_tableView.ClearAllSortingWithEvent();
105-
}
106-
else
107-
{
108-
ClearSortingWithEvent();
109-
}
110-
111-
if (direction is not null)
112-
{
113-
var boundColumn = Column as TableViewBoundColumn;
114-
Column.SortDirection = direction;
115-
_tableView.SortDescriptions.Add(
116-
new ColumnSortDescription(Column!, boundColumn?.PropertyPath, direction.Value));
117-
118-
_tableView.EnsureAlternateRowColors();
119-
}
104+
_tableView.ClearAllSortingWithEvent();
105+
}
106+
else
107+
{
108+
ClearSortingWithEvent();
109+
}
110+
111+
if (direction is not null)
112+
{
113+
var boundColumn = Column as TableViewBoundColumn;
114+
Column.SortDirection = direction;
115+
_tableView.SortDescriptions.Add(
116+
new ColumnSortDescription(Column!, boundColumn?.PropertyPath, direction.Value));
120117
}
121-
defer.Complete();
122118
}
123119
}
124120

@@ -135,11 +131,12 @@ private void ClearSortingWithEvent()
135131
return;
136132
}
137133

138-
if (CanSort && _tableView is not null && Column is not null)
134+
if (CanSort && _tableView?.CollectionView is CollectionView { } collectionView && Column is not null)
139135
{
136+
using var defer = collectionView.DeferRefresh();
140137
_tableView.DeselectAll();
141138
Column.SortDirection = null;
142-
_tableView.SortDescriptions.RemoveWhere(x => x is ColumnSortDescription columnSort && columnSort.Column == Column);
139+
collectionView.SortDescriptions.RemoveWhere(x => x is ColumnSortDescription columnSort && columnSort.Column == Column);
143140
}
144141
}
145142

@@ -163,10 +160,10 @@ private void ApplyFilter()
163160
else if (_tableView is not null)
164161
{
165162
_optionsFlyoutViewModel.SelectedValues = GetSelectedValues();
166-
_tableView.FilterHandler.SelectedValues[Column!] = _optionsFlyoutViewModel.SelectedValues;
167-
_tableView.FilterHandler?.ApplyFilter(Column!);
168-
}
163+
_tableView.FilterHandler.SelectedValues[Column!] = _optionsFlyoutViewModel.SelectedValues;
164+
_tableView.FilterHandler?.ApplyFilter(Column!);
169165
}
166+
}
170167

171168
private ICollection<object?> GetSelectedValues()
172169
{

0 commit comments

Comments
 (0)