首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改PaginatedDataTable上的列宽?

如何更改PaginatedDataTable上的列宽?
EN

Stack Overflow用户
提问于 2018-01-13 01:04:02
回答 3查看 8.2K关注 0票数 11

现在,列之间有如此多的空间,即使我有一个4个字符的标题和1到3个用于排名的数字值,这就好像我可以在每一列中容纳4倍。

我尝试使用较小的字体,但分隔符保持不变。

下面是我用来设置PaginatedDataTable的代码。我在表格/行/单元格/等中找不到任何参数,看起来会影响宽度。这个空间看起来是自动的,但完全没有必要。谢谢。

代码语言:javascript
复制
Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(title: const Text('Tour Rankings')),
        body:
        new ListView(
            padding: const EdgeInsets.all(5.0),
            children: <Widget>[
              new PaginatedDataTable(
                  header: const Text('Current Rankings'),
                  rowsPerPage: _rowsPerPage,
                  onRowsPerPageChanged: (int value) { setState(() { _rowsPerPage = value; }); },
                  sortColumnIndex: _sortColumnIndex,
                  sortAscending: _sortAscending,
                  columns: <DataColumn>[
                    new DataColumn(
                        label: new Text('Rank', style: new TextStyle(fontSize: 8.0)),
                        numeric: true,
                        onSort: (int columnIndex, bool ascending) => _sort<num>((Player d) => d.rank, columnIndex, ascending)
                    ),
                    new DataColumn(
                        label: new Text('Prev', style: new TextStyle(fontSize: 8.0)),
                        numeric: true,
                        onSort: (int columnIndex, bool ascending) => _sort<num>((Player d) => d.prevRank, columnIndex, ascending)
                    ),...
EN

回答 3

Stack Overflow用户

发布于 2020-09-22 00:04:41

flutter中有一个分页数据表的属性为columnSpacing。根据材料设计规范,该值默认为56.0。

您可以根据需要更改该值,以更改列内容之间的水平边距。

代码语言:javascript
复制
              PaginatedDataTable(
                showCheckboxColumn: false,
                columnSpacing: 10.0,
                header: Center(
                  child: Text("Statement"),
                ),
                columns: [
                  DataColumn(label: Text("Date")),
                  DataColumn(label: Text("Particular")),
                  DataColumn(label: Text("Debit")),
                  DataColumn(label: Text("Credit")),
                  DataColumn(label: Text("Detail")),
                ],
                source: YourDataSource(),
              ),

它应该看起来像这样:

票数 4
EN

Stack Overflow用户

发布于 2020-04-07 11:02:12

this diff之后,您可以设置horizontalMargincolumnSpacing来实现自定义列宽。

代码语言:javascript
复制
  /// The horizontal margin between the edges of the table and the content
  /// in the first and last cells of each row.
  ///
  /// When a checkbox is displayed, it is also the margin between the checkbox
  /// the content in the first data column.
  ///
  /// This value defaults to 24.0 to adhere to the Material Design specifications.
  final double horizontalMargin;

  /// The horizontal margin between the contents of each data column.
  ///
  /// This value defaults to 56.0 to adhere to the Material Design specifications.
  final double columnSpacing;
票数 0
EN

Stack Overflow用户

发布于 2018-09-14 15:01:49

我在flutter PaginatedDataTable布局的灵活性方面也遇到了同样的问题。我的解决方案是使用布局变量扩展DataTable的构造函数:

代码语言:javascript
复制
FlexibleDataTable({
    Key key,
    @required this.columns,
    this.sortColumnIndex,
    this.sortAscending = true,
    this.onSelectAll,
    this.headingRowHeight = 56.0,
    this.dataRowHeight = 48.0,
    this.tablePadding = 24.0,
    this.columnSpacing = 56.0,
    this.sortArrowPadding = 2.0,
    this.headingFontSize = 12.0,
    @required this.rows,
  }

当然,我必须实现FlexiblePaginatedDatatable才能使用FlexibleDataTable:

代码语言:javascript
复制
new SingleChildScrollView(
    scrollDirection: Axis.horizontal,
    child: new FlexibleDataTable(
        key: _tableKey,
        columns: widget.columns,
        sortColumnIndex: widget.sortColumnIndex,
        sortAscending: widget.sortAscending,
        onSelectAll: widget.onSelectAll,
        columnSpacing: 20.0,
        dataRowHeight: 40.0,
        rows: _getRows(_firstRowIndex, widget.rowsPerPage)
    )
),

Flutter团队应该在DataTable和PaginatedDataTable的官方版本中包含这个功能,这样其他人就不需要为这些琐碎的东西实现特别的版本。这个问题是存在的,我们将看到它何时会被解决。https://github.com/flutter/flutter/issues/12775

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48230872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档