addFilter method

void addFilter(
  1. String columnName,
  2. FilterCondition filterCondition
)
inherited

Call this method to add the FilterCondition programmatically.

@override
Widget build(BuildContext context) {
  return Column(
    children: [
      Expanded(
        child: SfDataGrid(source: _employeeDataSource, columns: [
          GridColumn(columnName: 'id', label: Text('ID')),
          GridColumn(columnName: 'name', label: Text('Name')),
          GridColumn(columnName: 'designation', label: Text('Designation')),
          GridColumn(columnName: 'salary', label: Text('Salary')),
        ]),
      ),
      MaterialButton(
          child: Text('Add Filter'),
          onPressed: () {
            _employeeDataSource.addFilter('id',
                FilterCondition(type: FilterType.greaterThan, value: 1005));
          }),
    ],
  );
}

Implementation

void addFilter(String columnName, FilterCondition filterCondition) {
  final List<FilterCondition> conditions = <FilterCondition>[
    if (_filterConditions.containsKey(columnName))
      ..._filterConditions[columnName]!,
    filterCondition
  ];

  _filterConditions[columnName] = conditions;

  if (_dataGridStateDetails != null) {
    _refreshFilter(_dataGridStateDetails!());
  }
}