clearFilters method
Clear the FilterCondition
from a given column or clear all the filter
conditions from all the columns.
Pass the required columnName
to remove the filter conditions from the
specific column.
@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('Clear Filters'),
onPressed: () {
_employeeDataSource.clearFilters();
}),
],
);
}
Implementation
void clearFilters({String? columnName}) {
if (_filterConditions.isNotEmpty) {
if (columnName != null && _filterConditions.containsKey(columnName)) {
_filterConditions.remove(columnName);
if (_dataGridStateDetails != null) {
_refreshFilter(_dataGridStateDetails!());
}
} else if (columnName == null) {
_filterConditions.clear();
if (_dataGridStateDetails != null) {
_refreshFilter(_dataGridStateDetails!());
}
}
}
}