Ask Your Question
1

How to arrange columns in a Flutter datatable?

asked 2022-06-07 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-10-29 05:00:00 +0000

qstack gravatar image

To arrange the columns in a Flutter datatable, you can use the columns property and provide a list of DataColumn widgets. Each DataColumn widget represents a column in the table and has properties such as label, numeric, tooltip, etc. You can rearrange the columns by changing the order of the DataColumn widgets in the list. Here's an example:

DataTable(
  columns: [
    DataColumn(label: Text('Name')),
    DataColumn(label: Text('Age'), numeric: true),
    DataColumn(label: Text('Email')),
  ],
  rows: [
    DataRow(cells: [
      DataCell(Text('John')),
      DataCell(Text('24')),
      DataCell(Text('john@example.com')),
    ]),
    DataRow(cells: [
      DataCell(Text('Jane')),
      DataCell(Text('32')),
      DataCell(Text('jane@example.com')),
    ]),
  ],
);

In this example, the columns are arranged in the order Name, Age, Email. To change the order to Age, Name, Email, you can simply switch the order of the DataColumn widgets:

DataTable(
  columns: [
    DataColumn(label: Text('Age'), numeric: true),
    DataColumn(label: Text('Name')),
    DataColumn(label: Text('Email')),
  ],
  rows: [
    DataRow(cells: [
      DataCell(Text('24')),
      DataCell(Text('John')),
      DataCell(Text('john@example.com')),
    ]),
    DataRow(cells: [
      DataCell(Text('32')),
      DataCell(Text('Jane')),
      DataCell(Text('jane@example.com')),
    ]),
  ],
);
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-06-07 11:00:00 +0000

Seen: 13 times

Last updated: Oct 29 '22