Reputation: 13
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?
Upvotes: 1
Views: 1394
Reputation: 1078
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.
Upvotes: 2