DataPagerController class

A controller for SfDataPager.

The following code initializes the data source and controller.

PaginatedDataGridSource dataGridSource = PaginatedDataGridSource();
DataPagerController dataPagerController = DataPagerController();
finalList<Employee>paginatedDataTable=<Employee>[];

The following code example shows how to initialize the SfDataPager with SfDataGrid


@override
Widget build(BuildContext context) {
 return Scaffold(
  appBar: AppBar(
   title: const Text('Syncfusion Flutter DataGrid'),
  ),
  body: Column(
   children: [
    SfDataGrid(
     source: _ dataGridSource,
     columns: <GridColumn>[
      GridColumn(columnName: 'id', label: Container(child: Text('ID'))),
      GridColumn(columnName: 'name', label: Container(child: Text('Name'))),
      GridColumn(columnName: 'designation', label: Container(child: Text('Designation'))),
      GridColumn(columnName: 'salary', label: Container(child: Text('Salary'))),
     ],
    ),
    SfDataPager(
     pageCount: paginatedDataTable.length / rowsPerPage,
     visibleItemsCount: 5,
     delegate: dataGridSource,
         controller:dataPagerController
    ),
    TextButton(
      child:Text('Next'),
      onPressed:{
        dataPagerController.nextPage();
      },
    )
   ],
  ),
 );
}

The following code example shows how to initialize the DataGridSource to SfDataGrid

class PaginatedDataGridSource extends DataGridSource {
  finalList<Employee> _paginatedData=<Employee>[];

  int StartRowIndex= 0, endRowIndex = 0, rowsPerPage = 20;

  @override
  List<DataGridRow> get rows => _paginatedData
      .map<DataGridRow>((dataRow) => DataGridRow(cells: [
            DataGridCell<int>(columnName: 'id', value: dataRow.id),
            DataGridCell<String>(columnName: 'name', value: dataRow.name),
            DataGridCell<String>(
                columnName: 'designation', value: dataRow.designation),
            DataGridCell<int>(columnName: 'salary', value: dataRow.salary),
          ]))
      .toList();

  @override
  DataGridRowAdapter? buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map<Widget>((dataCell) {
          return Text(dataCell.value.toString());
        }).toList());
  }

@override
Future<bool> handlePageChange(int oldPageIndex, int newPageIndex) async {
   startRowIndex = newPageIndex * rowsPerPage;
   endRowIndex = startRowsIndex + rowsPerPage;
 _paginatedData = paginatedDataTable
   .getRange(startRowIndex, endRowIndex)
   .toList(growable: false);
 notifyDataSourceListeners();
 return true;
}

See also:

SfDataPager - which is the widget this object controls.

Constructors

DataPagerController()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selectedPageIndex int
An index of the currently selected page.
getter/setter pair

Methods

addListener(_DataPagerControlListener listener) → void
inherited
dispose() → void
inherited
firstPage() → void
Moves the currently selected page to first page.
lastPage() → void
Moves the currently selected page to last page.
nextPage() → void
Moves the currently selected page to next page.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
previousPage() → void
Moves the currently selected page to previous page.
removeListener(_DataPagerControlListener listener) → void
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited