Skip to content

SyncfusionExamples/How-to-update-the-data-pager-with-proper-page-count-when-applying-programmatic-filtering-in-Flutter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to update the data pager with proper page count when applying programmatic filtering in Flutter DataTable (SfDataGrid)?

In this article, we will show you how to update the data pager with the proper page count when applying programmatic filtering in Flutter DataGrid.

Initialize the SfDataGrid and SfDataPager widgets with all required properties, begin by declaring them and specifying their respective properties. Additionally, ensure to update the DataPager’ s page count whenever filtering is applied to or removed from the rows. This update should reflect the pageCount value based on the length of the DataGridSource.effectiveRows.

  // To update the DataPager's page count while filtering the rows.
  void _updatePageCount() {
    final rowsCount = employeeDataSource.filterConditions.isNotEmpty
        ? employeeDataSource.effectiveRows.length
        : employeeDataSource._employeeRows.length;
    pageCount = (rowsCount / _rowsPerPage).ceil().toDouble();
  }


  Widget searchField() {
    return SizedBox(
      width: 200,
      height: 50,
      child: TextField(
        controller: searchController,
        onChanged: (value) {
          employeeDataSource.clearFilters(columnName: 'name');
          if (value.isNotEmpty&&
              _pageEmployee.any((employee) =>
                  employee.name.toLowerCase() == value.toLowerCase()) ) {
            employeeDataSource.addFilter(
                'name',
                FilterCondition(
                    type: FilterType.contains,
                    filterBehavior: FilterBehavior.stringDataType,
                    value: value));
          }
          WidgetsBinding.instance.addPostFrameCallback((_) {
            setState(() {
              // Need to update the page count.
              _updatePageCount();
            });
          });
          employeeDataSource.updateDataGriDataSource();
        },
        decoration: const InputDecoration(
          hintText: "serach",
        ),
      ),
    );
  }

You can download the example from GitHub.

About

How to update the data pager with proper page count when applying programmatic filtering in Flutter

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •