Flutter,如何在 PaginatedDataTable 中以编程方式更改页面?
Flutter, How can I change page programmaticly in PaginatedDataTable?
我有一个 PaginatedDataTable 和搜索栏,它工作得很好,但是当我搜索时,我的 DataTable 不会进入第一页。当我单击第一页时,它会转到第一页,并且会显示我的新过滤列表。如何在 dataTable 中以编程方式更改页面?
这是我的分页数据表
PaginatedDataTable paginatedDataTable = PaginatedDataTable(
actions: [
AnimatedSearchBar(
width: 300,
textController: _searchController,
onSuffixTap: () {
setState(() {
_searchController.text = "";
});
}),
widget.showDialog == null
? SizedBox()
: AddUpdateButton(
buttonType: ButtonTypes.add,
onPressed: widget.showDialog,
)
],
initialFirstRowIndex: firstRowIndex,
source: dts,
rowsPerPage: _rowsPerPage,
header: Text(
widget.title,
style: CustomTextStyle.mblackBoldTextStyle,
),
sortColumnIndex: _sortColumnIndex,
sortAscending: _sortAscending,
availableRowsPerPage: [
_defaultRowsPerPage,
_defaultRowsPerPage * 2,
_defaultRowsPerPage * 5,
_defaultRowsPerPage * 10
],
showCheckboxColumn: false,
dataRowHeight: widget.dataRowHeight,
showFirstLastButtons: true,
onRowsPerPageChanged: (r) {
setState(() {
_rowsPerPage = r;
});
},
columns: widget.headerList.map((e) {
return DataColumn(
label: Text(e.name.toUpperCase()),
onSort: (int columnIndex, bool ascending) {
if (e.sort) {
return _sort(
(T d) => d.getProp(e.propName), columnIndex, ascending);
}
});
}).toList(),
);
我创建了一个密钥
final key = new GlobalKey<PaginatedDataTableState>();
给键 PaginatedDataTable
PaginatedDataTable(
key: key
...)
我使用这个功能
key.currentState.pageTo(0);
您可以查看此问题以了解使用键状态:
我有一个 PaginatedDataTable 和搜索栏,它工作得很好,但是当我搜索时,我的 DataTable 不会进入第一页。当我单击第一页时,它会转到第一页,并且会显示我的新过滤列表。如何在 dataTable 中以编程方式更改页面?
这是我的分页数据表
PaginatedDataTable paginatedDataTable = PaginatedDataTable(
actions: [
AnimatedSearchBar(
width: 300,
textController: _searchController,
onSuffixTap: () {
setState(() {
_searchController.text = "";
});
}),
widget.showDialog == null
? SizedBox()
: AddUpdateButton(
buttonType: ButtonTypes.add,
onPressed: widget.showDialog,
)
],
initialFirstRowIndex: firstRowIndex,
source: dts,
rowsPerPage: _rowsPerPage,
header: Text(
widget.title,
style: CustomTextStyle.mblackBoldTextStyle,
),
sortColumnIndex: _sortColumnIndex,
sortAscending: _sortAscending,
availableRowsPerPage: [
_defaultRowsPerPage,
_defaultRowsPerPage * 2,
_defaultRowsPerPage * 5,
_defaultRowsPerPage * 10
],
showCheckboxColumn: false,
dataRowHeight: widget.dataRowHeight,
showFirstLastButtons: true,
onRowsPerPageChanged: (r) {
setState(() {
_rowsPerPage = r;
});
},
columns: widget.headerList.map((e) {
return DataColumn(
label: Text(e.name.toUpperCase()),
onSort: (int columnIndex, bool ascending) {
if (e.sort) {
return _sort(
(T d) => d.getProp(e.propName), columnIndex, ascending);
}
});
}).toList(),
);
我创建了一个密钥
final key = new GlobalKey<PaginatedDataTableState>();
给键 PaginatedDataTable
PaginatedDataTable(
key: key
...)
我使用这个功能
key.currentState.pageTo(0);
您可以查看此问题以了解使用键状态: