|
5 | 5 | [](https://www.nuget.org/packages/SimpleDataGrid/) |
6 | 6 | [](https://github.com/DerekGooding/SimpleDataGrid/actions/workflows/api-docs.yml) |
7 | 7 |
|
8 | | -A simple DataGrid for WPF that supports pagination, filtering, and searching. |
| 8 | +A powerful and simple DataGrid for WPF applications, offering seamless pagination, advanced filtering, and robust searching capabilities. Easily integrate and manage large datasets with a modern UI. |
9 | 9 |
|
10 | 10 | ## Features |
11 | 11 |
|
12 | | -* **Pagination:** Easily page through large datasets, with navigation controls and page size selection. |
13 | | -* **Filtering:** Filter data based on custom criteria, including named filters for easy management. |
14 | | -* **Searching:** Search for data using strings, wildcards, and multi-column search with debouncing. |
15 | | -* **Sorting:** Sort data by clicking on column headers. |
16 | | -* **Empty State Support:** Provides clear feedback when no items are found after filtering or searching. |
17 | | -* **Observability Events:** Exposes events for page changes, filter changes, search changes, and sort changes. |
| 12 | +* **Pagination:** Easily page through large datasets with comprehensive controls including `NextPage`, `PreviousPage`, `GoToPage`, `GoToFirstPage`, `GoToLastPage`, and `ResetToFirstPage`. Supports configurable page sizes and provides properties like `TotalItems`, `IsEmpty`, `HasItems`, and `IsSourceEmpty` for detailed state management. |
| 13 | +* **Filtering:** Filter data based on custom criteria using `AddFilter`, `SetFilter`, `RemoveFilter`, and `ClearFilters`. Supports named filters for easy management and retrieval of active filters. |
| 14 | +* **Searching:** Robust search functionality with `SetSearchAsync` (OR logic for multiple selectors) and `SetSearchAllAsync` (AND logic for multiple selectors). Supports wildcards (`*` and `?`), debouncing for efficient input handling, and an `IsSearching` property to indicate active search operations. |
| 15 | +* **Sorting:** Sort data by clicking on column headers or programmatically using `SetSort` and `ClearSort`. The `IsSorted` property indicates the current sort status. |
| 16 | +* **Empty State Support:** Provides clear feedback when no items are found after filtering or searching, leveraging `IsEmpty` and `HasItems` properties. |
| 17 | +* **Observability Events:** Exposes a rich set of events including `PageSizeChanged`, `SortChanged`, `FilterChanged`, `PageChanged`, `SourceChanged`, and `SearchChanged` for reactive UI updates. |
| 18 | +* **Resource Management:** Implements `IDisposable` for proper cleanup of resources, particularly for search debouncing mechanisms. |
18 | 19 |
|
19 | 20 | ## Installation |
20 | 21 |
|
@@ -147,6 +148,98 @@ public class Person |
147 | 148 | public DateTime HireDate { get; set; } |
148 | 149 | } |
149 | 150 |
|
| 151 | +## Usage Examples |
| 152 | + |
| 153 | +Here are some examples of how to use the `PagedCollection` for advanced filtering and searching: |
| 154 | + |
| 155 | +### Basic Setup |
| 156 | + |
| 157 | +```csharp |
| 158 | +public class MyViewModel |
| 159 | +{ |
| 160 | + public PagedCollection<MyItem> Items { get; } |
| 161 | + |
| 162 | + public MyViewModel() |
| 163 | + { |
| 164 | + Items = new PagedCollection<MyItem>(pageSize: 20); |
| 165 | + Items.SetSource(LoadMyItems()); |
| 166 | + } |
| 167 | + |
| 168 | + private List<MyItem> LoadMyItems() => /* ... load your data ... */ new List<MyItem>(); |
| 169 | +} |
| 170 | + |
| 171 | +public class MyItem |
| 172 | +{ |
| 173 | + public int Id { get; set; } |
| 174 | + public string Name { get; set; } = string.Empty; |
| 175 | + public string Category { get; set; } = string.Empty; |
| 176 | + public decimal Price { get; set; } |
| 177 | +} |
| 178 | +``` |
| 179 | + |
| 180 | +### Filtering |
| 181 | + |
| 182 | +```csharp |
| 183 | +// Add a filter for items in a specific category |
| 184 | +Items.SetFilter("CategoryFilter", item => item.Category == "Electronics"); |
| 185 | + |
| 186 | +// Remove a filter |
| 187 | +Items.RemoveFilter("CategoryFilter"); |
| 188 | + |
| 189 | +// Clear all filters |
| 190 | +Items.ClearFilters(); |
| 191 | +``` |
| 192 | + |
| 193 | +### Searching (OR Logic) |
| 194 | + |
| 195 | +```csharp |
| 196 | +// Search for a term in Name OR Category, with debouncing |
| 197 | +await Items.SetSearchAsync( |
| 198 | + selectors: new Func<MyItem, string>[] { item => item.Name, item => item.Category }, |
| 199 | + term: "laptop", |
| 200 | + useWildcards: true, |
| 201 | + debounceMilliseconds: 300 |
| 202 | +); |
| 203 | + |
| 204 | +// Clear search |
| 205 | +await Items.ClearSearchAsync(); |
| 206 | +``` |
| 207 | + |
| 208 | +### Searching (AND Logic) |
| 209 | + |
| 210 | +```csharp |
| 211 | +// Search for a term in Name AND Category, with debouncing |
| 212 | +await Items.SetSearchAllAsync( |
| 213 | + selectors: new Func<MyItem, string>[] { item => item.Name, item => item.Category }, |
| 214 | + term: "gaming", |
| 215 | + useWildcards: false, |
| 216 | + debounceMilliseconds: 300 |
| 217 | +); |
| 218 | +``` |
| 219 | + |
| 220 | +### Sorting |
| 221 | + |
| 222 | +```csharp |
| 223 | +// Sort by Price in ascending order |
| 224 | +Items.SetSort(item => item.Price, ascending: true); |
| 225 | + |
| 226 | +// Clear sorting |
| 227 | +Items.ClearSort(); |
| 228 | +``` |
| 229 | + |
| 230 | +### Pagination Controls |
| 231 | + |
| 232 | +```csharp |
| 233 | +// Go to the next page |
| 234 | +Items.NextPage(); |
| 235 | + |
| 236 | +// Go to a specific page |
| 237 | +Items.GoToPage(5); |
| 238 | + |
| 239 | +// Change page size |
| 240 | +Items.SetPageSize(10); |
| 241 | +``` |
| 242 | + |
150 | 243 | ## Example Project |
151 | 244 |
|
152 | 245 | 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. |
|
0 commit comments