DataPagerController class Null safety

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>[
      GridNumericColumn(mappingName: 'id', headerText: 'ID'),
      GridTextColumn(mappingName: 'name', headerText: 'Name'),
      GridTextColumn(mappingName: 'designation', headerText: 'Designation'),
      GridNumericColumn(mappingName: 'salary', headerText: '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. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
selectedPageIndex int
An index of the currently selected page.
read / write

Methods

addListener(_DataPagerControlListener listener) → void
inherited
dispose() → void
@mustCallSuper, 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 non-existent 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