Skip to content

Support server-side pagination in SfDataGrid column filters#2544

Open
ariefwijaya wants to merge 1 commit into
syncfusion:masterfrom
ariefwijaya:pr/datagrid-server-side-filters
Open

Support server-side pagination in SfDataGrid column filters#2544
ariefwijaya wants to merge 1 commit into
syncfusion:masterfrom
ariefwijaya:pr/datagrid-server-side-filters

Conversation

@ariefwijaya

Copy link
Copy Markdown

Summary

This PR contains several related improvements so SfDataGrid's built-in filters work correctly in server-side pagination scenarios, where DataGridSource.rows only holds one page of data at a time:

  1. CheckboxFilterValueProvider mixin — A DataGridSource can 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.
  2. Equals/DoesNotEqual use text input — Adds equals and doesNotEqual to textFieldFilterTypes in DataGridAdvancedFilterHelper, enabling free-text input for these filter types in the advanced filter popup.
  3. advancedFilterType on FilterPopupMenuOptions — Exposes a new advancedFilterType field so callers can override the filter mode (text, numeric, date) per column without relying on cell-value inference.
  4. AdvancedFilterType exported from public API — Re-exports AdvancedFilterType from the package's public barrel so consumers can reference the enum without reaching into internal paths.
  5. Fix null-value type-check crash — Guards _debugCheckDataType so that filter conditions with a null value (i.e. "Is Null" / "Is Not Null" filter types) no longer throw a FlutterError when rows are refreshed or a column is sorted.

Motivation

When using server-side pagination, DataGridSource.rows only contains one page of data at a time. This causes multiple problems with the built-in filter UI:

Checkbox filter:
CheckboxFilterView derives its unique values from DataGridSource.rows, so values from other pages disappear from the filter list on navigation, making the checkbox filter unusable for server-side grids. The CheckboxFilterValueProvider mixin lets the source provide the full value set explicitly.

Advanced filter (equals/doesNotEqual):
equals and doesNotEqual were 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 AdvancedFilterType inference based on cell-value type then produces the wrong filter UI. FilterPopupMenuOptions.advancedFilterType lets 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 null as the condition value. On a subsequent data refresh or sort, _debugCheckDataType compared null's runtime type against the column's expected type and threw a FlutterError, crashing the grid.

Usage

CheckboxFilterValueProvider

class MyDataSource extends DataGridSource with CheckboxFilterValueProvider {
  @override
  List<Object>? getCheckboxFilterValues(String columnName) {
    if (columnName == 'status') return <Object>['Active', 'Inactive'];
    return null; // fall back to default (row-derived) behaviour
  }
}

advancedFilterType on FilterPopupMenuOptions

GridColumn(
  columnName: 'trx_date',
  filterPopupMenuOptions: const FilterPopupMenuOptions(
    advancedFilterType: AdvancedFilterType.date,
  ),
  label: const Text('Date'),
)

Test plan

  • Checkbox filter popup shows all custom values on any page of a server-side paginated grid.
  • Returning null from getCheckboxFilterValues falls back to default row-derived values.
  • Sources that do not use the mixin are unaffected.
  • Selection state: values present in effectiveRows are checked when a filter is active; all values are checked when no filter is active.
  • Selecting equals / doesNotEqual in the advanced filter popup shows a text input instead of a dropdown, and filtering by a typed value works.
  • Other advanced filter types (begins with, ends with, contains, etc.) are unaffected.
  • advancedFilterType on FilterPopupMenuOptions forces the popup to text/numeric/date mode.
  • AdvancedFilterType is importable from the public package barrel.
  • Applying "Is Null" / "Is Not Null" on a date column, then refreshing or sorting, does not throw a FlutterError.
  • Existing default filter behaviour is unchanged.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant