[英]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.我在我的 web 应用程序中使用 PaginatedDataTable,应用程序用户可以通过提供关键字来搜索行。
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.问题是:在搜索和调用setstate后,在搜索PaginatedDataTable是否在第二、第三页或其他页面而不是第一页之前,我必须go到第一页查看output,非常不方便。
Is there any way to make PaginatedDataTable to go the first page after the number of rows changed?有什么办法可以让 PaginatedDataTable 到 go 成为行数改变后的第一页?
I was able to finally solve this problem by passing a unique Key
to the PaginatedDataTable
instance.通过将唯一的
Key
传递给PaginatedDataTable
实例,我终于能够解决这个问题。
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:在您调用此 class 的根 Widget 中:
...
...
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.我建议您查看Flutter 的简短视频,该视频解释了我们为什么使用
Key
s,如果您不熟悉它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.