Support server-side pagination in SfDataGrid column filters#2544
Open
ariefwijaya wants to merge 1 commit into
Open
Support server-side pagination in SfDataGrid column filters#2544ariefwijaya wants to merge 1 commit into
ariefwijaya wants to merge 1 commit into
Conversation
Adds five related improvements so SfDataGrid's built-in filters work correctly when rows are paged from a server: - CheckboxFilterValueProvider mixin: a DataGridSource can supply a static list of checkbox-filter values per column instead of deriving them from the currently-loaded page. - equals/doesNotEqual now use text input in the advanced filter popup. - FilterPopupMenuOptions.advancedFilterType lets callers force the filter mode (text/numeric/date) per column instead of inferring it from rows. - AdvancedFilterType is exported from the public API. - Guard _debugCheckDataType so "Is Null"/"Is Not Null" conditions (null value) no longer throw FlutterError on refresh or sort.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR contains several related improvements so
SfDataGrid's built-in filters work correctly in server-side pagination scenarios, whereDataGridSource.rowsonly holds one page of data at a time:CheckboxFilterValueProvidermixin — ADataGridSourcecan opt into this mixin to supply a static list of values for the checkbox filter popup per column, instead of the default row-derived list.equalsanddoesNotEqualtotextFieldFilterTypesinDataGridAdvancedFilterHelper, enabling free-text input for these filter types in the advanced filter popup.advancedFilterTypeonFilterPopupMenuOptions— Exposes a newadvancedFilterTypefield so callers can override the filter mode (text,numeric,date) per column without relying on cell-value inference.AdvancedFilterTypeexported from public API — Re-exportsAdvancedFilterTypefrom the package's public barrel so consumers can reference the enum without reaching into internal paths._debugCheckDataTypeso that filter conditions with anullvalue (i.e. "Is Null" / "Is Not Null" filter types) no longer throw aFlutterErrorwhen rows are refreshed or a column is sorted.Motivation
When using server-side pagination,
DataGridSource.rowsonly contains one page of data at a time. This causes multiple problems with the built-in filter UI:Checkbox filter:
CheckboxFilterViewderives its unique values fromDataGridSource.rows, so values from other pages disappear from the filter list on navigation, making the checkbox filter unusable for server-side grids. TheCheckboxFilterValueProvidermixin lets the source provide the full value set explicitly.Advanced filter (equals/doesNotEqual):
equalsanddoesNotEqualwere only driven by a dropdown populated from the current page's rows. Values from other pages are not available, making exact-match filtering impractical. Users who know the exact value they want should be able to type it directly instead of selecting from an incomplete list.Advanced filter (column type inference):
For server-side grids, cell values may be stored as strings regardless of the logical column type (date, numeric). The automatic
AdvancedFilterTypeinference based on cell-value type then produces the wrong filter UI.FilterPopupMenuOptions.advancedFilterTypelets the caller set the correct filter mode explicitly.Null/Not Null filter crash:
Applying an "Is Null" / "Is Not Null" filter on a date or numeric column stores
nullas the condition value. On a subsequent data refresh or sort,_debugCheckDataTypecomparednull's runtime type against the column's expected type and threw aFlutterError, crashing the grid.Usage
CheckboxFilterValueProvider
advancedFilterType on FilterPopupMenuOptions
Test plan
nullfromgetCheckboxFilterValuesfalls back to default row-derived values.effectiveRowsare checked when a filter is active; all values are checked when no filter is active.equals/doesNotEqualin the advanced filter popup shows a text input instead of a dropdown, and filtering by a typed value works.advancedFilterTypeonFilterPopupMenuOptionsforces the popup to text/numeric/date mode.AdvancedFilterTypeis importable from the public package barrel.FlutterError.