Coder Social home page Coder Social logo

zhouruikevin / data_table_2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maxim-saplin/data_table_2

0.0 0.0 0.0 5.74 MB

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

Home Page: https://pub.dev/packages/data_table_2

License: BSD 3-Clause "New" or "Revised" License

Kotlin 0.03% Swift 0.28% Objective-C 0.01% Dart 88.98% HTML 0.81% CMake 3.64% C++ 5.91% C 0.34%

data_table_2's Introduction

In-place substitute for Flutter's stock DataTable and PaginatedDataTable widgets with fixed/sticky header/top row (footer/paginator for PaginatedDataTable) and a few extra features. 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/data grids and missed the sticky headers (or vertical border, 'no rows' placeholder 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.

image

- please check the example folder which recreates the Flutter Gallery's Data Table sample (with PgaintedDataTable and DataSource) as well as has a few more samples. There's also a DataGrid Sample in separate repo.

Extra Features

  • Sticky headers and paginator (when using PabinatedDataTable2)
  • Vertiacally 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 horizontaly, 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 decendant 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
    • You can limit the minimal width of the control and scroll it horizontaly 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 overscroll
    • 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 with Flexible and SingleScrollView widgets to allow widget 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)
  • 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.)

Usage

  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 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.

data_table_2's People

Contributors

maxim-saplin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.