Skip to content

Repository files navigation

SimpleDataGrid

Build StatusOpen IssuesNuGet VersionAPI Docs

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.

Features

  • 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.
  • Filtering: Filter data based on custom criteria using AddFilter, SetFilter, RemoveFilter, and ClearFilters. Supports named filters for easy management and retrieval of active filters.
  • 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.
  • Sorting: Sort data by clicking on column headers or programmatically using SetSort and ClearSort. The IsSorted property indicates the current sort status.
  • Empty State Support: Provides clear feedback when no items are found after filtering or searching, leveraging IsEmpty and HasItems properties.
  • Observability Events: Exposes a rich set of events including PageSizeChanged, SortChanged, FilterChanged, PageChanged, SourceChanged, and SearchChanged for reactive UI updates.
  • Resource Management: Implements IDisposable for proper cleanup of resources, particularly for search debouncing mechanisms.

Installation

You can install the SimpleDataGrid NuGet package using either the .NET CLI or the NuGet Package Manager.

.NET CLI

dotnet add package SimpleDataGrid

NuGet Package Manager

Install-Package SimpleDataGrid

Usage

  1. Install the SimpleDataGrid NuGet package.
  2. Add the PagedDataGrid control to your XAML.
  3. Create a PagedCollection and bind it to the PagedSource property of the PagedDataGrid.
<Windowx:Class="SimpleDataGrid.Example.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-namespace:SimpleDataGrid.Example"xmlns:controls="clr-namespace:SimpleDataGrid.Controls;assembly=SimpleDataGrid"mc:Ignorable="d"Title="MainWindow"Height="450"Width="800">
<Window.DataContext>
<local:MainViewModel />
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinitionHeight="Auto" />
<RowDefinitionHeight="*" />
<RowDefinitionHeight="Auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0"Orientation="Horizontal"Margin="5">
<TextBoxx:Name="SearchTextBox"Width="200"Margin="5"TextChanged="SearchTextBox_TextChanged"/>
<ButtonContent="Search"Click="SearchButton_Click"Margin="5" />
<CheckBoxx:Name="WildcardCheckBox"Content="Use Wildcards"VerticalAlignment="Center"Margin="5" />
<ButtonContent="Advanced Examples"Click="AdvancedExamplesButton_Click"Margin="5"/>
</StackPanel>
<controls:PagedDataGridx:Name="PagedDataGrid" Grid.Row="1"PagedSource="{Binding People}"AutoGenerateColumns="True" />
<StackPanel Grid.Row="2"Orientation="Horizontal"HorizontalAlignment="Center">
<ButtonContent="Previous"Click="PreviousButton_Click"Margin="5" />
<TextBlockText="{Binding People.CurrentPage}"VerticalAlignment="Center"Margin="5" />
<TextBlockText="/"VerticalAlignment="Center" />
<TextBlockText="{Binding People.TotalPages}"VerticalAlignment="Center"Margin="5" />
<ButtonContent="Next"Click="NextButton_Click"Margin="5" />
</StackPanel>
</Grid>
</Window>
publicpartialclassMainWindow:Window{publicMainWindow(){InitializeComponent();}privatevoidPreviousButton_Click(objectsender,RoutedEventArgse){varviewModel=(MainViewModel)DataContext;viewModel.People.PreviousPage();}privatevoidNextButton_Click(objectsender,RoutedEventArgse){varviewModel=(MainViewModel)DataContext;viewModel.People.NextPage();}privatevoidSearchTextBox_TextChanged(objectsender,TextChangedEventArgse){varviewModel=(MainViewModel)DataContext;viewModel.People.SetSearch(p =>p.Name,SearchTextBox.Text,WildcardCheckBox.IsChecked==true,300);}privatevoidSearchButton_Click(objectsender,RoutedEventArgse){varviewModel=(MainViewModel)DataContext;viewModel.People.SetSearch(p =>p.Name,SearchTextBox.Text,WildcardCheckBox.IsChecked==true);}privatevoidAdvancedExamplesButton_Click(objectsender,RoutedEventArgse){varadvancedExamplesWindow=newAdvancedExamplesWindow();advancedExamplesWindow.Show();}}publicclassMainViewModel{publicPagedCollection<Person>People{get;}publicMainViewModel(){People=newPagedCollection<Person>(10);People.SetSource(GetPeople());}privatestaticList<Person>GetPeople(){varpeople=newList<Person>();for(vari=1;i<=100;i++){people.Add(newPerson{Id=i,Name=$"Person {i}",Age=20+(i%50),Email=$"person{i}@example.com",Department=(i%2==0)?"Sales":"Marketing"});}returnpeople;}}publicclassPerson{publicintId{get;set;}publicstringName{get;set;}=string.Empty;publicintAge{get;set;}publicstringEmail{get;set;}=string.Empty;publicstringDepartment{get;set;}=string.Empty;publicboolIsActive{get;set;}publicDateTimeHireDate{get;set;}}
## UsageExamples
Here are some examples of how to use the `PagedCollection` for advanced filteringand searching:
### Basic Setup
```csharp
publicclassMyViewModel{publicPagedCollection<MyItem>Items{get;}publicMyViewModel(){Items=newPagedCollection<MyItem>(pageSize:20);Items.SetSource(LoadMyItems());}privateList<MyItem>LoadMyItems()=>/* ... load your data ... */newList<MyItem>();}publicclassMyItem{publicintId{get;set;}publicstringName{get;set;}=string.Empty;publicstringCategory{get;set;}=string.Empty;publicdecimalPrice{get;set;}}

Filtering

// Add a filter for items in a specific categoryItems.SetFilter("CategoryFilter", item =>item.Category=="Electronics");// Remove a filterItems.RemoveFilter("CategoryFilter");// Clear all filtersItems.ClearFilters();

Searching (OR Logic)

// Search for a term in Name OR Category, with debouncingawaitItems.SetSearchAsync(selectors:newFunc<MyItem,string>[]{ item =>item.Name, item =>item.Category},term:"laptop",useWildcards:true,debounceMilliseconds:300);// Clear searchawaitItems.ClearSearchAsync();

Searching (AND Logic)

// Search for a term in Name AND Category, with debouncingawaitItems.SetSearchAllAsync(selectors:newFunc<MyItem,string>[]{ item =>item.Name, item =>item.Category},term:"gaming",useWildcards:false,debounceMilliseconds:300);

Sorting

// Sort by Price in ascending orderItems.SetSort(item =>item.Price,ascending:true);// Clear sortingItems.ClearSort();

Pagination Controls

// Go to the next pageItems.NextPage();// Go to a specific pageItems.GoToPage(5);// Change page sizeItems.SetPageSize(10);

Example Project

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.

To run the example project:

dotnet run --project SimpleDataGrid.Example

Performance

For detailed information on performance characteristics and best practices, refer to the PERFORMANCE.md document.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A powerful and simple DataGrid for WPF applications, offering seamless pagination, advanced filtering, and robust searching capabilities. Easily integrate and manage large datasets.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Contributors

Languages