Skip to content

Commit 4a209c9

Browse files
committed
improved column filter behavior & UI
1 parent a7302a2 commit 4a209c9

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/WinUI.TableView/TableViewColumnHeader.OptionsFlyoutViewModel.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ private void InitializeCommands()
3939

4040
OkCommand.ExecuteRequested += delegate
4141
{
42-
SelectedValues = FilterItems.Where(x => x.IsSelected).Select(x => x.Value).ToList();
43-
ColumnHeader.ApplyFilter();
42+
ColumnHeader.HideFlyout();
43+
44+
if (ColumnHeader!._selectAllCheckBox!.IsChecked is true)
45+
{
46+
ColumnHeader.ClearFilter();
47+
}
48+
else
49+
{
50+
SelectedValues = FilterItems.Where(x => x.IsSelected).Select(x => x.Value).ToList();
51+
ColumnHeader.ApplyFilter();
52+
}
4453
};
4554

46-
CancelCommand.ExecuteRequested += delegate { ColumnHeader._optionsFlyout?.Hide(); };
55+
CancelCommand.ExecuteRequested += delegate { ColumnHeader.HideFlyout(); };
4756
}
4857

4958
public TableView TableView { get; }

src/WinUI.TableView/TableViewColumnHeader.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,16 @@ private void ApplyFilter()
106106
return;
107107
}
108108

109-
_optionsFlyout?.Hide();
110109
_tableView.ActiveFilters[_propertyPath] = Filter;
111110
_tableView.CollectionView.RefreshFilter();
112111
IsFiltered = true;
113112
}
114113

114+
private void HideFlyout()
115+
{
116+
_optionsFlyout?.Hide();
117+
}
118+
115119
private bool Filter(object item)
116120
{
117121
var value = GetValue(item);
@@ -221,10 +225,9 @@ private void PrepareFilterItems(string? _filterText)
221225
{
222226
var value = GetValue(item);
223227
value = string.IsNullOrWhiteSpace(value?.ToString()) ? "(Blank)" : value;
224-
var isSelected = !string.IsNullOrEmpty(_filterText) ||
228+
var isSelected = !isFiltered || !string.IsNullOrEmpty(_filterText) ||
225229
(isFiltered && _optionsFlyoutViewModel.SelectedValues.Contains(value));
226230

227-
228231
return string.IsNullOrEmpty(_filterText)
229232
|| value?.ToString()?.Contains(_filterText, StringComparison.OrdinalIgnoreCase) == true
230233
? new FilterItem(isSelected, value, _optionsFlyoutViewModel)

src/WinUI.TableView/Themes/TableViewColumnHeader.xaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,15 @@
195195
<MenuFlyoutItem>
196196
<MenuFlyoutItem.Template>
197197
<ControlTemplate TargetType="MenuFlyoutItem">
198-
<StackPanel Margin="8,4"
199-
Spacing="16"
200-
HorizontalAlignment="Right"
201-
Orientation="Horizontal">
202-
<Button Command="{Binding OkCommand}" />
203-
<Button Command="{Binding CancelCommand}" />
204-
</StackPanel>
198+
<Grid Margin="12,4"
199+
ColumnSpacing="16">
200+
<Grid.ColumnDefinitions>
201+
<ColumnDefinition Width="*" />
202+
<ColumnDefinition Width="*" />
203+
</Grid.ColumnDefinitions>
204+
<Button Command="{Binding OkCommand}" HorizontalAlignment="Stretch" Style="{StaticResource AccentButtonStyle}" />
205+
<Button Command="{Binding CancelCommand}" Grid.Column="1" HorizontalAlignment="Stretch" />
206+
</Grid>
205207
</ControlTemplate>
206208
</MenuFlyoutItem.Template>
207209
</MenuFlyoutItem>

0 commit comments

Comments
 (0)