We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Add column filter after setState

Hello there, 

i use your SFDataGrid and have the following problem.

When a filter is added to a column by the user, I store all the filters in a map variable. Now when I do an action and go back to the grid with setState I want the filter to be set again. I use the following function to set the filter.

 void loadFilder() {
    if (widget.gridFilter.isNotEmpty) {
      widget.gridFilter.forEach((key, value) {
        for (var element in value) {
          gridDataSource.addFilter(key, element);

 The problem now is that the filter is set in the column header, but the data is not filtered. If I sort any column then the filter will be applied. Do you have an idea?

1 Reply

TP Tamilarasan Paranthaman Syncfusion Team February 3, 2023 09:53 AM UTC

Hi Mario, 

Based on the information you have provided, we have been unable to reproduce the issue you have described. We have conducted tests using a sample in which we save the filter conditions in the onFilterChanged callback to a map collection, and then load those conditions in the initState method when returning to the DataGrid page. Please check the following sample and code snippet for references. 

 Map<String, List<FilterCondition>> filterConditions = {};



  void initState() {


    employees = populateData();

    _employeeDataSource = EmployeeDataSource(employees);




  void loadFilter() {

    if (filterConditions.isNotEmpty) {

      for (var key in filterConditions.keys) {

        for (var filtercondition in filterConditions[key]!) {

          _employeeDataSource.addFilter(key, filtercondition);







  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(title: const Text('Flutter DataGrid')),

      body: SfDataGrid(

          allowFiltering: true,

          source: _employeeDataSource,

          onFilterChanged: (details) {

            filterConditions[details.column.columnName] =



          columnWidthMode: ColumnWidthMode.fill,

          columns: getColumns),



Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample955221099  

If you are still encountering the issue, we would appreciate it if you could modify the sample we provided to create a reproducible example of the issue and provide us with the steps needed to reproduce the issue. This will help us investigate the issue further and provide a solution as soon as possible.



Live Chat Icon For mobile
Up arrow icon