【问题标题】:Flutter, How can I change page programmaticly in PaginatedDataTable?Flutter,如何在 PaginatedDataTable 中以编程方式更改页面?
【发布时间】:2021-11-08 18:02:00
【问题描述】:

我有一个分页数据表和搜索栏,它工作得很好,但是当我搜索我的数据表时,我的数据表不会进入第一页。当我单击第一页时,它会显示第一页并显示我的新过滤列表。如何在 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(),
  );

【问题讨论】:

  • 试试PaginatedDataTableState.pageTo()方法
  • 谢谢我以同样的方式解决了@pskink

标签: flutter dart flutter-layout flutter-web paginateddatatable


【解决方案1】:

我创建了一个密钥

final key = new GlobalKey<PaginatedDataTableState>();

给键分页数据表

 PaginatedDataTable(
        key: key
        ...)

我使用这个功能

key.currentState.pageTo(0);

您可以查看此问题以了解使用密钥状态: Link

【讨论】:

    猜你喜欢
    • 2023-01-23
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 2015-09-30
    • 1970-01-01
    • 2017-07-28
    • 2012-08-31
    • 2023-04-02
    相关资源
    最近更新 更多