@@ -4,9 +4,12 @@ A simple DataGrid for WPF that supports pagination, filtering, and searching.
44
55## Features
66
7- * ** Pagination:** Easily page through large datasets.
8- * ** Filtering:** Filter data based on custom criteria.
9- * ** Searching:** Search for data using strings or wildcards.
7+ * ** Pagination:** Easily page through large datasets, with navigation controls and page size selection.
8+ * ** Filtering:** Filter data based on custom criteria, including named filters for easy management.
9+ * ** Searching:** Search for data using strings, wildcards, and multi-column search with debouncing.
10+ * ** Sorting:** Sort data by clicking on column headers.
11+ * ** Empty State Support:** Provides clear feedback when no items are found after filtering or searching.
12+ * ** Observability Events:** Exposes events for page changes, filter changes, search changes, and sort changes.
1013
1114## Installation
1215
@@ -35,6 +38,7 @@ Install-Package SimpleDataGrid
3538 xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3639 xmlns : x =" http://schemas.microsoft.com/winfx/2006/xaml"
3740 xmlns : local =" clr-namespace:SimpleDataGrid.Example"
41+ xmlns : controls =" clr-namespace:SimpleDataGrid.Controls;assembly=SimpleDataGrid"
3842 mc : Ignorable =" d"
3943 Title =" MainWindow" Height =" 450" Width =" 800" >
4044 <Window .DataContext>
@@ -48,16 +52,13 @@ Install-Package SimpleDataGrid
4852 </Grid .RowDefinitions>
4953
5054 <StackPanel Grid.Row=" 0" Orientation =" Horizontal" Margin =" 5" >
51- <TextBox x : Name =" SearchTextBox" Width =" 200" Margin =" 5" />
55+ <TextBox x : Name =" SearchTextBox" Width =" 200" Margin =" 5" TextChanged = " SearchTextBox_TextChanged " />
5256 <Button Content =" Search" Click =" SearchButton_Click" Margin =" 5" />
5357 <CheckBox x : Name =" WildcardCheckBox" Content =" Use Wildcards" VerticalAlignment =" Center" Margin =" 5" />
54-
55- <TextBox x : Name =" MinAgeTextBox" Width =" 50" Margin =" 5" />
56- <Button Content =" Filter by Min Age" Click =" FilterButton_Click" Margin =" 5" />
57- <Button Content =" Clear Filter" Click =" ClearFilterButton_Click" Margin =" 5" />
58+ <Button Content =" Advanced Examples" Click =" AdvancedExamplesButton_Click" Margin =" 5" />
5859 </StackPanel >
5960
60- <local : PersonPagedDataGrid x : Name =" PagedDataGrid" Grid.Row=" 1" PagedSource =" {Binding People}" AutoGenerateColumns =" True" />
61+ <controls : PagedDataGrid x : Name =" PagedDataGrid" Grid.Row=" 1" PagedSource =" {Binding People}" AutoGenerateColumns =" True" />
6162
6263 <StackPanel Grid.Row=" 2" Orientation =" Horizontal" HorizontalAlignment =" Center" >
6364 <Button Content =" Previous" Click =" PreviousButton_Click" Margin =" 5" />
@@ -90,25 +91,22 @@ public partial class MainWindow : Window
9091 viewModel .People .NextPage ();
9192 }
9293
93- private void SearchButton_Click (object sender , RoutedEventArgs e )
94+ private void SearchTextBox_TextChanged (object sender , TextChangedEventArgs e )
9495 {
9596 var viewModel = (MainViewModel )DataContext ;
96- viewModel .People .SetSearch (p => p .Name , SearchTextBox .Text , WildcardCheckBox .IsChecked == true );
97+ viewModel .People .SetSearch (p => p .Name , SearchTextBox .Text , WildcardCheckBox .IsChecked == true , 300 );
9798 }
9899
99- private void FilterButton_Click (object sender , RoutedEventArgs e )
100+ private void SearchButton_Click (object sender , RoutedEventArgs e )
100101 {
101102 var viewModel = (MainViewModel )DataContext ;
102- if (int .TryParse (MinAgeTextBox .Text , out var minAge ))
103- {
104- viewModel .ApplyFilter (minAge );
105- }
103+ viewModel .People .SetSearch (p => p .Name , SearchTextBox .Text , WildcardCheckBox .IsChecked == true );
106104 }
107105
108- private void ClearFilterButton_Click (object sender , RoutedEventArgs e )
106+ private void AdvancedExamplesButton_Click (object sender , RoutedEventArgs e )
109107 {
110- var viewModel = ( MainViewModel ) DataContext ;
111- viewModel . ClearFilter ();
108+ var advancedExamplesWindow = new AdvancedExamplesWindow () ;
109+ advancedExamplesWindow . Show ();
112110 }
113111}
114112
@@ -127,24 +125,33 @@ public class MainViewModel
127125 var people = new List <Person >();
128126 for (var i = 1 ; i <= 100 ; i ++ )
129127 {
130- people .Add (new Person { Id = i , Name = $" Person {i }" , Age = 20 + (i % 50 ) });
128+ people .Add (new Person { Id = i , Name = $" Person {i }" , Age = 20 + (i % 50 ), Email = $" person{ i }@example.com " , Department = ( i % 2 == 0 ) ? " Sales " : " Marketing " });
131129 }
132130 return people ;
133131 }
132+ }
134133
135- public void ApplyFilter (int minAge )
136- {
137- People .ClearFilters ();
138- People .AddFilter (p => p .Age >= minAge );
139- }
140-
141- public void ClearFilter ()
142- {
143- People .ClearFilters ();
144- }
134+ public class Person
135+ {
136+ public int Id { get ; set ; }
137+ public string Name { get ; set ; } = string .Empty ;
138+ public int Age { get ; set ; }
139+ public string Email { get ; set ; } = string .Empty ;
140+ public string Department { get ; set ; } = string .Empty ;
141+ public bool IsActive { get ; set ; }
142+ public DateTime HireDate { get ; set ; }
145143}
144+
145+ ## Example Project
146+
147+ The `SimpleDataGrid .Example ` project demonstrates various features of the `SimpleDataGrid ` library . It includes a basic `MainWindow ` for quick usage and an `AdvancedExamplesWindow` for showcasing more complex functionalities.
148+
149+ To run the example project:
150+
151+ ```bash
152+ dotnet run --project SimpleDataGrid.Example
146153```
147154
148155## License
149156
150- This project is licensed under the MIT License. See the [ LICENSE] ( LICENSE ) file for details.
157+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
0 commit comments