• Stars
    star
    170
  • Rank 222,323 (Top 5 %)
  • Language
    Dart
  • License
    BSD 3-Clause "New...
  • Created over 3 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

In-place substitute for Flutter's DataTable and PaginatedDataTable with fixed/sticky header and extra features

Pub Version GitHub Tests Codecov

! Don't put the widgets inside unbounded parents. You don't need scrollables anymore (e.g. SingleChildScrollView) - widgets handle scrolling by theirselves. If you need a widget inside a Column(), wrap it into Expanded() or Flexible().

In-place substitute for Flutter's stock DataTable and PaginatedDataTable widgets with fixed/sticky header/top rows and left columns. A few useful features missing in the originals were added.

DataTable2 and PaginatedDataTable2 widgets are based on the sources of Flutter's originals, mimic the API and provide seamless integration.

If you've been using (or considered using) standard Flutter's widgets for displaying tables or data grids and missed the sticky headers (or vertical borders, 'No rows' placeholder, straightforward async data source API etc.) - you've come to the right place. No need to learn yet another API of a new control, just stick to well described DataTable and PaginatedDataTable.

LIVE DEMO

image

Please check the example folder which demonstrates various features of the widgets. There's also a DataGrid Sample in separate repo which is based on DataTable2.

Extra Features

  • Sticky headers and paginator (when using PaginatedDataTable2)
    • The number of sticky rows is defined by DataTable2.fixedTopRows
    • Sticky left columns DataTable2.fixedLeftColumns
  • Vertically scrollable main area (with data rows)
    • autoRowsToHeight property on PaginatedDataTable2 allows to auto calculate page size depending on how much rows fit the height and makes vertical scrolling unnecessary
  • All columns are fixed width, table automatically stretches horizontally, individual column's width is determined as (Width)/(Number of Columns)
    • Should you want to adjust sizes of columns, you can replace DataColumn definitions with DataColumn2 (which is a descendant of DataColumn). The class provides size property which can be set to one of 3 relative sizes (S, M and L)
    • Width ratios between Small and Medium, Large and Medium columns are defined by smRatio and lmRatio params
    • fixedWidth parameter allows to define absolute value for column width
    • You can limit the minimal width of the control and scroll it horizontally if the viewport is narrower (by setting minWidth property) which is useful in portrait orientations with multiple columns not fitting the screen
    • You can add bottom margin (by setting bottomMargin property) to allow slight over-scroll
    • Fixed width columns are faster than default implementation of DataTable which does 2 passes to determine contents size and justify column widths
  • Data rows are wrapped in Flexible and SingleScrollView widgets to allow widget to fill parent container and be scrollable
    • Vertical scroller is exposed via table's scrollController property. See example 'DataTable2 - Scroll-up' which shows 'up' button when scrolling down and allows to jump to the top of the table
    • PaginatedDataTable2.fit property controls whether the paginator sticks to the bottom and leaves a gap to data rows above
  • There's DataRow2 alternative to stock DataRow which provides row level tap events (including right clicks)
    • PaginatedDataTable2.renderEmptyRowsInTheEnd property changes the default Flutter way of rendering pages with empty rows
    • DataRow2.specificRowHeight allows overriding default height for any row
  • Overriding sort arrows via sortArrowIcon and sortArrowAnimationDuration properties
  • empty property which allows defining a placeholder widget to be displayed when data source is empty
  • border allows drawing inner and outer vertical and horizontal borders (e.g. outlining individual cells) - stock widgets only allow drawing horizontal row splitters
  • PaginatorController allows to externally control PaginatedDataTable2 state (e.g. switch pages, change page size etc.)
  • Experimental AsynPaginatedDataTable2 widget built for asynchronous scenarios (such a requesting data from a web service) relying on AsyncDataTableSource returning rows in a Future

Usage

NOTE:* don't put the widgets into any unconstrained parents with infinite width or height (e.g. scrollables such as SingleChildScrollView, Column etc.). The widgets are designed to stretch and fill all available space within parent and have a number of own scrollables inside to address fixed rows/columns feature. Putting it inside unconstrained parent break widgets.

  1. Add reference to pubspec.yaml.

  2. Import:

import 'package:data_table_2/data_table_2.dart';
  1. Code:
import 'package:data_table_2/data_table_2.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

/// Example without a datasource
class DataTable2SimpleDemo extends StatelessWidget {
  const DataTable2SimpleDemo();

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16),
      child: DataTable2(
          columnSpacing: 12,
          horizontalMargin: 12,
          minWidth: 600,
          columns: [
            DataColumn2(
              label: Text('Column A'),
              size: ColumnSize.L,
            ),
            DataColumn(
              label: Text('Column B'),
            ),
            DataColumn(
              label: Text('Column C'),
            ),
            DataColumn(
              label: Text('Column D'),
            ),
            DataColumn(
              label: Text('Column NUMBERS'),
              numeric: true,
            ),
          ],
          rows: List<DataRow>.generate(
              100,
              (index) => DataRow(cells: [
                    DataCell(Text('A' * (10 - index % 10))),
                    DataCell(Text('B' * (10 - (index + 5) % 10))),
                    DataCell(Text('C' * (15 - (index + 5) % 10))),
                    DataCell(Text('D' * (15 - (index + 10) % 10))),
                    DataCell(Text(((index + 0.1) * 25.4).toString()))
                  ]))),
    );
  }
}

If you're already using the standard widgets you can reference the package and add '2' to the names of stock widgets (making them DataTable2 or PaginatedDataTable2) and that is it.

Know issues/limitations/caveats

  • There's no capability to size data table cells to fit contents. Column width's adapt to available width (either to parent width or minWidth), data rows width are predefined by constructor params. Content that doesn't fit a cell gets clipped
    • dataRowMinHeight and dataRowMaxHeight from the stock data table are also not supported
  • There're no expanding/collapsing rows (drill-down scenarios), manually moving or resizing columns or rows, merging cells (i.e. HTML's colspan, rowspan)
  • When fixing left columns, hovering over a row won't highlight entire row (should there be any tap handlers standard behavior is hovering a row changes it background)
  • Touch scrolling not working/jumping under mobile device emulation in Chrome (#100)
  • Cell and row tap events block DataRow.onSelectChanged event handler
  • In order to get checkbox column visible it is necessary to have DataTable2.showCheckboxColumn set to true AND there must be some rows with onSelectChanged event handler being not null
  • Paginated table's by default add empty rows should the page be larger than the number of available rows, can be changed via renderEmptyRowsInTheEnd
  • Golden tests can fail on Linux due to rendered images being different from the ones created on macOS and stored in the repo, PR @157

More Repositories

1

CrossPlatformDiskTest

Windows, macOS and Android storage (HDD, SSD, RAM) speed testing/performance benchmarking app
C#
416
star
2

NetCoreStorageSpeedTest

Console Application (tested on Windows, MacOS and Linux/Ubuntu) and a cross-platform Class Library (C#, .NET Standard 2.1) for measuring read/write speeds of disks/storage devices.
C#
47
star
3

ipfs_gateway_research

Testing and ranking by speed public IPFS HTTP gateways
Dart
35
star
4

dikt

Off-line dictionary with simplistic UI. Optimized for one-hand on with mobile phones. Cross-platform, tailored desktop as well
Dart
30
star
5

flutter_python_starter

Bundling Python code with Flutter Desktop apps as self-contained binary, interop with Python self-hosted gRPC service
Dart
29
star
6

BulkConverterToHeic

macOS bulk image converter (JPG, PNG, BMP) to HEIC/HEIF with metadata preservation
Shell
25
star
7

cptX

Use ChatGPT as your copilot at VSCode
Dart
22
star
8

flutter_web_spa_sample

Trying out Flutter for desktop Web app development as an alternative to SPA frameworks (such as React and Angular) by recreating one of the pages of an existing CV Management web app
Dart
21
star
9

xOPS-App

xOPS: Cross-Platform CPU Benchmark & Stress Testing
C#
15
star
10

isolate_pool_2

Just like a thread pool, but with isolates
Dart
5
star
11

TimeSeries-Xamarin

ASCII time series chart for Xamarin.Forms
C#
5
star
12

mandelbrot

Microbenchmark testing Python, Numba, Mojo, Dart, C/gcc, Rust, Go, JavaScript, C#, Java, Kotlin, Pascal, Ruby, Haskell performance in Mandelbrot set generation
Dart
5
star
13

ikvpack

Indexed Key Value pack (ikvpack) allows saving to a file (native platforms) or IndexedDB (Web) key/value collection (Map<String, String>) sorted by key. It is optimized for fast lazy loads (reading only keys), values are compressed and are fetched/decompressed only when requested. Keys are indexed (i.e. one can access them by index rather than iterate as it is implemented in typical dictionaries).
Dart
5
star
14

dopetest_flutter

Flutter/Dart UI generation performance test (layout, rendering, collections)
Dart
4
star
15

ambilytics

Google Analytics for all Flutter platfroms (Android, iOS, macOS, Web, Windows and Linux)
Dart
4
star
16

dikt_converter

Bulk dictionary converter from various formats (e.g. Lingvo/DSL, StarDict etc.) to 'dikt app' supported formats (JSON and binary DIKT)
ASL
3
star
17

xOPS-Console

C#
2
star
18

cpdt_results

Benchmark results of storage performance for various Android, macOS and Windows devices
JavaScript
2
star
19

dopetest_xamarin

Xamarin.Forms UI generation performance test (layout, rendering, collections)
C#
2
star
20

py_chat_ui

A simplistic UI for Azure/OpenAI chat API implemented in Python and Streamlit !!! It has token counter !!!
Python
2
star
21

dopetest_react

JavaScript
1
star
22

dopetest_html

HTML/JS UI generation performance test (layout, rendering, collections, DOM manipulation)
HTML
1
star
23

GA-RealtimeReport-PWA

JavaScript
1
star
24

test_popup_android

Opening Android app in popup view (free-form window) when receiving ACTION_PROCESS_TEXT intent
Kotlin
1
star
25

openai_prompt_runner

Minimal harness for automated mass executions of prompts against OpenAI or Azure endpoints
Dart
1
star
26

AsciiTimeSeries

C# class that renders a numerical collection (double) to a string which displayed with monospace font will be a time series chart
C#
1
star
27

branchless_dart

Testing barnchless optimizations with Dart programming languages
Dart
1
star
28

flutter_python_streaming

A PoC based on Flutter-Pyhton starter kit that uses more advanced gRPC features
Dart
1
star