DataGrid: Make extension methods to apply filters
Description
Added some extension methods on IEnumerable<T> in DataGridExtensions.
This makes it more obvious and convenient to apply filters in cases such as when using the ServerData parameter. Instead of having to iterate over the IEnumerable and apply .Where(filter.GetnerateFilterFunction()) for each filter, users will have a more obvious method to accomplish this common behaviour, which is precedented by the already existing IEnumerable.OrderBySortDefinitions extension method.
How Has This Been Tested?
Changes tested via integration and experimentation with my own code.
Type of Changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation (fix or improvement to the website or code docs)
Checklist
- [x] The PR is submitted to the correct branch (
dev). - [x] My code follows the code style of this project.
- [ ] I've added relevant tests.
Codecov Report
Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
Project coverage is 90.66%. Comparing base (
28bc599) to head (c068b2e). Report is 275 commits behind head on dev.
| Files | Patch % | Lines |
|---|---|---|
| src/MudBlazor/Extensions/DataGridExtensions.cs | 0.00% | 4 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## dev #9181 +/- ##
==========================================
+ Coverage 89.82% 90.66% +0.83%
==========================================
Files 412 400 -12
Lines 11878 12518 +640
Branches 2364 2437 +73
==========================================
+ Hits 10670 11350 +680
+ Misses 681 627 -54
- Partials 527 541 +14
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Hi. Thank you for your contribution. Please add unit tests for these extension methods.
I have already opened a pull request a while ago that covers this topic, was discussed and is fully covered with unit tests: #8254
I just rebased it on the dev branch, it's ready to merge.
I have already opened a pull request a while ago that covers this topic, was discussed and is fully covered with unit tests: #8254
I just rebased it on the
devbranch, it's ready to merge.
Can this PR be closed then?
This one is a little different as it operates on IEnumerable<T> rather than IQueryable<T>.
I'd still simplify it to this (also renaming ApplyFilters simply into Where) and, as already mentioned, adding tests.
public static IEnumerable<T> Where<T>(this IEnumerable<T> source, GridState<T> state, FilterOptions? filterOptions = null)
=> Where(source, state.FilterDefinitions, filterOptions);
public static IEnumerable<T> Where<T>(this IEnumerable<T> source, ICollection<IFilterDefinition<T>> filterDefinitions, FilterOptions? filterOptions)
=> filterDefinitions.Aggregate(source, (current, filter) => current.Where(filter.GenerateFilterFunction(filterOptions)));