expandable_datatable 0.0.8

SDKflutter
Platformandroidioswindowslinuxmacosweb

A flutter package for viewing and editing data in a table view with expandable rows.

ExpandableDataTable

ExpandableDataTable is a Flutter library for dealing with displaying and editing data in tabular view.

Features

  • Row sorting
  • Flexible column sizes
  • Expandable rows
  • Row pagination
  • Editable rows
  • Customizable edit dialogs
  • Customizable pagination widget
  • Customizable expansion content
  • Styling rows and header columns

ExpandableDataTable Parameters:

NameDescription
headersHeader list of data columns
rowsList of the data rows
pageSizeNumber of rows to be used on a single page
visibleColumnCountNumber of columns to show in the headers
multipleExpansionFlag indicating that multiple expansions are enabled for rows
isEditableFlag indicating whether the rows are editable
onRowChangedThe callback that is called when a row is changed with edit dialog
onPageChangedThe callback that is called when the page changed with pagination widget
renderEditDialogRender function that builds a custom edit dialog widget
renderCustomPaginationRender function that builds a custom pagination widget
renderExpansionContentRender function that builds custom expansion container for all rows

ExpandableThemeData Parameters:

NameDescription
headerTextStyleText style of header row
rowTextStyleText style of all rows
contentPaddingPadding for all header and data rows
headerTextMaxLinesMaximum number of lines for header text to span
rowTextMaxLinesMaximum number of lines for row text to span
rowTextOverflowVisual overflow of the row's cell text
expandedTextStyleText style of expansion content
headerColorBackground color of header row
headerSortIconColorColor of the header sort arrow icon
headerHeightHeight of the header widget
expandedBorderColorExpansion border color
rowColorBackground color of rows
evenRowColorBackground color of the even indexed rows
oddRowColorBackground color of the odd indexed rows
rowBorderBorder style of all rows
editIconIcon image showing editing feature
expansionIconIcon image expanding expansion content
paginationSizeSize of the default pagination widget
paginationTextStyleTextStyle of the page numbers for default pagination widget
paginationSelectedTextColorColor of the selected cell's page number for default pagination widget
paginationUnselectedTextColorColor of the unselected cells' page number for default pagination widget
paginationSelectedFillColorBackground fill color of the selected cell for default pagination widget
paginationBorderColorBorder color for default pagination widget
paginationBorderRadiusBorder radius value for default pagination widget
paginationBorderWidthBorder width value for default pagination widget

Usage

  1. To use this package, add expandable_datatable as a dependency in your pubspec.yaml file.

  2. Import the package

import ‘package:expandable_datatable/expandable_datatable.dart’;
  1. Create data to use in the data table

Create the list of the headers to be used in data table with types. Header list should be in a prioritized order, all columns have a flex value that all cells inside that column will be used.

  List<ExpandableColumn<dynamic>> headers = [
    ExpandableColumn<int>(columnTitle: "ID", columnFlex: 1),
    ExpandableColumn<String>(columnTitle: "First name", columnFlex: 2),
    ExpandableColumn<String>(columnTitle: "Last name", columnFlex: 2),
    ExpandableColumn<String>(columnTitle: "Maiden name", columnFlex: 2),
    ExpandableColumn<int>(columnTitle: "Age", columnFlex: 1),
    ExpandableColumn<String>(columnTitle: "Gender", columnFlex: 2),
    ExpandableColumn<String>(columnTitle: "Email", columnFlex: 4),
  ];

Create the list of the rows to be used in data table. All row list elements must contain all columns for lists.

  List<ExpandableRow> rows = userList.map<ExpandableRow>((e) {
    return ExpandableRow(cells: [
      ExpandableCell<int>(columnTitle: "ID", value: e.id),
      ExpandableCell<String>(columnTitle: "First name", value: e.firstName),
      ExpandableCell<String>(columnTitle: "Last name", value: e.lastName),
      ExpandableCell<String>(columnTitle: "Maiden name", value: e.maidenName),
      ExpandableCell<int>(columnTitle: "Age", value: e.age),
      ExpandableCell<String>(columnTitle: "Gender", value: e.gender),
      ExpandableCell<String>(columnTitle: "Email", value: e.email),
    ]);
  }).toList();
  1. Code
  void createDataSource() {...}

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Expandable Datatable Example"),
      ),
      body: ExpandableTheme(
        data: ExpandableThemeData(
          context,
          rowBorder: const BorderSide(color: Colors.amber),
          expandedBorderColor: Colors.transparent,
          paginationSize: 48,
        ),
        child: ExpandableDataTable(
          rows: rows,
          headers: headers,
          visibleColumnCount: 4,
        ),
      ),
    );
  }

Screenshots

Sorting the rows

Sort Screenshot

Expansion feature

Expansion Screenshot

Edit rows dialog (Customizable)

Editing Screenshot

Styling

Styling Screenshot

License

MIT