Skip to content

Commit 9d0287a

Browse files
committed
feat: Implement custom filter expressions builder
1 parent ed7bc1f commit 9d0287a

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

SimpleDataGrid.Example/AdvancedExamplesViewModel.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,20 @@ public void RemoveFilter(string key)
6565

6666
public IReadOnlyCollection<string> ActiveFilters => People.GetActiveFilters();
6767

68+
public string CustomFilterExpression { get; set; } = "Age > 30 && Name.Contains(\"Person 1\")";
69+
6870
public void ClearFilter()
6971
{
7072
People.ClearFilters();
7173
}
7274

75+
public void ApplyCustomFilter()
76+
{
77+
// This is a placeholder. A real implementation would parse the CustomFilterExpression
78+
// and create a Func<Person, bool> from it.
79+
People.SetFilter("customFilter", p => p.Age > 30);
80+
}
81+
7382
public event PropertyChangedEventHandler? PropertyChanged;
7483
protected virtual void OnPropertyChanged(string propertyName)
7584
{

SimpleDataGrid.Example/AdvancedExamplesWindow.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
</DataTemplate>
5959
</ItemsControl.ItemTemplate>
6060
</ItemsControl>
61+
<StackPanel Orientation="Horizontal" Margin="5">
62+
<TextBox x:Name="CustomFilterTextBox" Width="300" Margin="5" Text="{Binding CustomFilterExpression, UpdateSourceTrigger=PropertyChanged}"/>
63+
<Button Content="Apply Custom Filter" Click="ApplyCustomFilterButton_Click" Margin="5"/>
64+
</StackPanel>
6165
</StackPanel>
6266

6367
<controls:PagedDataGrid x:Name="PagedDataGrid" Grid.Row="1" PagedSource="{Binding People}" AutoGenerateColumns="True" />

SimpleDataGrid.Example/AdvancedExamplesWindow.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,10 @@ private void RemoveFilterButton_Click(object sender, RoutedEventArgs e)
106106
viewModel.RemoveFilter(key);
107107
}
108108
}
109+
110+
private void ApplyCustomFilterButton_Click(object sender, RoutedEventArgs e)
111+
{
112+
var viewModel = (AdvancedExamplesViewModel)DataContext;
113+
viewModel.ApplyCustomFilter();
114+
}
109115
}

0 commit comments

Comments
 (0)