Articles in this section

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

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",
        ),
      ),
    );
  }

View the GitHub sample here.

Conclusion

I hope you enjoyed learning about how to update the data pager with proper page count when applying programmatic filtering in Flutter DataTable.

You can refer to our Flutter DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied