data_table_2는 Flutter의 내장 DataTable 및 PaginatedDataTable에 대한 즉시 대체 가능한 패키지입니다. 고정 또는 스틱 헤더, 개선된 스크롤 동작 및 추가 사용자 정의 옵션을 통해 테이블 기능을 강화합니다. 대규모 데이터 세트에서 더 나은 사용성을 위해 설계되었으며, 성능을 유지하면서 열 크기 조절 및 정렬과 같은 기능을 제공합니다. 구조화된 데이터 표시와 함께 강화된 상호작용성과 시각적 명확성을 필요로 하는 앱에 이상적입니다.
사용 사례
스티키 헤더를 사용하여 대규모 데이터셋 표시
웹 및 모바일 앱에서 반응형 테이블 만들기
표준 DataTable을 향상된 기능으로 교체
정렬 및 크기 조절이 가능한 열을 사용하여 관리 패널 구축하기
부드러운 스크롤링을 사용한 페이징 데이터 뷰 구현
주요 기능
스티키/고정 헤더
열 크기 조정 지원
개선된 스크롤 성능
내장된 정렬 및 필터링
사용자 정의 스타일 및 레이아웃
DataTable 및 PaginatedDataTable 사용 사례를 모두 지원합니다
적합한 대상
고급 테이블 기능이 필요한 개발자
광범위한 표 형식 데이터를 포함하는 앱
크로스 플랫폼 테이블 구현
UI 중심의 대시보드 및 관리 인터페이스
사용자 정의 코드 없이 스티키 헤더가 필요한 프로젝트
고려 사항
표준 DataTable에서 마이그레이션 필요
핵심 위젯에 비해 문서가 제한적
패키지 크기가 약간 증가할 수 있습니다
매우 간단한 정적 테이블에는 적합하지 않습니다
고급 테이블 동작이 필요한 경우에 가장 적합합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
! 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.
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
Vertical and horizontal scroll visibility via isVerticalScrollBarVisible and isHorizontalScrollBarVisible
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, custom arrow builder with sortArrowBuilder
Customizing checkboxes in DataTable2 via headingCheckboxTheme, datarowCheckboxTheme and checkboxAlignment
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.
Add reference to pubspec.yaml (v3+ also requires material_ui):
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.
Breaking change in 3.0.0: Material widgets and types (DataColumn, DataRow, DataTable, etc.) now come from the standalone material_ui package instead of package:flutter/material.dart. Add material_ui to your dependencies and update Material imports. Public types in this package extend Material classes from material_ui, so mixing SDK Material imports with data_table_2 3.x can cause type identity mismatches.
If your app uses localized Material widgets (e.g. paginator labels), replace flutter_localizations Material delegates with material_ui:
Do not import both package:flutter_localizations/flutter_localizations.dart and package:material_ui/material_ui.dart without hide/as prefixes — GlobalMaterialLocalizations is defined in both and will cause ambiguous-import errors.
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 (https://github.com/maxim-saplin/data_table_2/issues/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