简体   繁体   中英

Flutter: PaginatedDataTable doesn't go back to the first page after the number of rows changed

I am using PaginatedDataTable in my web app, app user could search rows by providing keywords.

The problem is: before searching if the PaginatedDataTable is on the second, third page or other pages rather than the first page after the searching and setstate is invoked, I have to go to the first page to view the output which is very inconvenient.

Is there any way to make PaginatedDataTable to go the first page after the number of rows changed?

I was able to finally solve this problem by passing a unique Key to the PaginatedDataTable instance.

class MyDataTable extends StatelessWidget {
  
  const MyDataTable({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InteractiveViewer(
      child: PaginatedDataTable(
        key: key,
        columns: getColumnHeadersForOwners(),
        source: getDataSource(),
        header: Container(),
        rowsPerPage: 4,
      ),
    );
  }
}

and in the root Widget where you're calling this class:

...
...
child: MyDataTable(key: UniqueKey())
...

I recommend checking out Flutter's short video which explains why we use Key s if you're not familiar with them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM