Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rc-table

react-component4.9mMIT7.50.2TypeScript support: included

table ui component for react

react, react-table, table, component, ui

readme

rc-table

React table component with useful functions.

NPM version dumi build status Test coverage npm download bundle size

install

rc-table

Development

npm install
npm start

Example

https://table-react-component.vercel.app/

Usage

import Table from 'rc-table';

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name',
    width: 100,
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
    width: 100,
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address',
    width: 200,
  },
  {
    title: 'Operations',
    dataIndex: '',
    key: 'operations',
    render: () => <a href="#">Delete</a>,
  },
];

const data = [
  { name: 'Jack', age: 28, address: 'some where', key: '1' },
  { name: 'Rose', age: 36, address: 'some where', key: '2' },
];

React.render(<Table columns={columns} data={data} />, mountNode);

API

Properties

Name Type Default Description
tableLayout auto | fixed auto | fixed for any columns is fixed or ellipsis or header is fixed https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout
prefixCls String rc-table
className String | additional className
id String | identifier of the container div
useFixedHeader Boolean false whether use separator table for header. better set width for columns
scroll Object {x: false, y: false} whether table can be scroll in x/y direction, x or y can be a number that indicated the width and height of table body
expandable Object | Config expand props
expandable.defaultExpandAllRows Boolean false Expand All Rows initially
expandable.defaultExpandedRowKeys String[] [] initial expanded rows keys
expandable.expandedRowKeys String[] | current expanded rows keys
expandable.expandedRowRender Function(recode, index, indent, expanded):ReactNode | Content render to expanded row
expandable.expandedRowClassName string | (recode, index, indent) => string | get expanded row's className
expandable.expandRowByClick boolean | Support expand by click row
expandable.expandIconColumnIndex Number 0 The index of expandIcon which column will be inserted when expandIconAsCell is false
expandable.expandIcon props => ReactNode | Customize expand icon
expandable.indentSize Number 15 indentSize for every level of data.i.children, better using with column.width specified
expandable.rowExpandable (record) => boolean | Config row support expandable
expandable.onExpand Function(expanded, record) | function to call when click expand icon
expandable.onExpandedRowsChange Function(expandedRows) | function to call when the expanded rows change
expandable.fixed String | Boolean - this expand icon will be fixed when table scroll horizontally: true or left or right and expandIconColumnIndex need to stay first or last
rowKey string or Function(record, index):string 'key' If rowKey is string, record[rowKey] will be used as key. If rowKey is function, the return value of rowKey(record, index) will be use as key.
rowClassName string or Function(record, index, indent):string | get row's className
rowRef Function(record, index, indent):string | get row's ref key
data Object[] | data record array to be rendered
onRow Function(record, index) | Set custom props per each row.
onHeaderRow Function(record, index) | Set custom props per each header row.
showHeader Boolean true whether table head is shown
hidden Boolean false Hidden column.
title Function(currentData) | table title render function
footer Function(currentData) | table footer render function
emptyText React.Node or Function No Data Display text when data is empty
columns Object[] | The columns config of table, see table below
components Object | Override table elements, see #171 for more details
sticky boolean | {offsetHeader?: number, offsetScroll?: number, getContainer?: () => Window | HTMLElement } false stick header and scroll bar
summary (data: readonly RecordType[]) => React.ReactNode - summary attribute in table component is used to define the summary row.
rowHoverable boolean true Table hover interaction

Column Props

Name Type Default Description
key String | key of this column
className String | className of this column
colSpan Number | thead colSpan of this column
title React Node | title of this column
dataIndex String | display field of the data record
width String | Number | width of the specific proportion calculation according to the width of the columns
minWidth Number | the minimum width of the column, only worked when tableLayout is auto
fixed String | Boolean | this column will be fixed when table scroll horizontally: true or 'left' or 'right'
align String | specify how cell content is aligned
ellipsis Boolean | specify whether cell content be ellipsized
rowScope 'row' | 'rowgroup' | Set scope attribute for all cells in this column
onCell Function(record, index) | Set custom props per each cell.
onHeaderCell Function(record) | Set custom props per each header cell.
render Function(value, row, index) | The render function of cell, has three params: the text of this cell, the record of this row, the index of this row, it's return an object:{ children: value, props: { colSpan: 1, rowSpan:1 } } ==> 'children' is the text of this cell, props is some setting of this cell, eg: 'colspan' set td colspan, 'rowspan' set td rowspan

Summary Props

Table.Summary

Name Type Default Description
key String | key of this summary
fixed boolean | 'top' | 'bottom' - true fixes the summary row at the bottom of the table. top fixes the summary row at the top of the table, while bottom fixes it at the bottom. undefined or false makes the summary row scrollable along with the table.

Table.Summary.Row

Name Type Default Description
key String | key of this summary
className String - className of this summary row
style React.CSSProperties - style of this summary row
onClick (e?: React.MouseEvent<HTMLElement>) => void - The onClick attribute in Table.Summary.Row component can be used to set a click event handler for the summary row.

License

rc-table is released under the MIT license.

changelog

Changelog

7.13.3

2021-03-18

  • fix: table header broken when scroll do not have the data. #595

7.13.2

2021-03-11

  • fix: Let width go when scroll do not have the data. #594

7.13.1

2021-01-28

  • fix: Cannot read property 'scrollLeft' of null.

7.12.4

2021-01-27

  • feat: use ReadonlyArray in props. #574

7.12.3

2020-12-25

  • chore: bump rc-resize-observer.
  • chore: Fix table warning. #566

7.12.2

2020-12-12

  • fix: resolve no date header width when sticky. #564

7.12.1

2020-12-08

  • chore: fix build css lost.

7.12.0

2020-12-08

  • docs: use dumi. #558

7.11.3

2020-11-25

  • fix: ping left right in rtl. #556

Middle check in releases.


6.9.0 / 2019-10-18

  • Rewrite in typescript
  • Fix scroll={{ x: 'max-content' }} not working.

6.8.0 / 2019-09-03

6.7.0 / 2019-07-22

  • Show icon if using expandIcon even if expandRowByClick is set

6.6.0 / 2019-06-04

  • Fixed Table header extra vertial scrollbar style.

6.5.0 / 2019-04-20

  • Add internal interface for col definition.

6.4.0 / 2018-10-15

  • Render data- and aria- props #227
  • onCell add row index #222
  • Add expandIcon #236

6.3.1 / 2018-08-02

  • Revert 112346 since too many edge cases.

6.3.0 / 2018-08-02

  • Fixed header will read cell width from body.

6.2.0 / 2018-05-09

  • Add expanded as the fourth parameter to expandedRowRender.

6.0.0 / 2017-11-14

  • Refactor.
  • Allow override default examples.
  • Add Table[onRow] and column[onCell].
  • Add column[align].

5.6.0 / 2017-08-27

  • Better empty data style for fixed-columns Table.

5.5.0 / 2017-08-17

  • Add onRowContextMenu

5.4.0 / 2017-05-23

  • Add onRowMouseEnter, onRowMouseLeave.

5.3.0 / 2017-04-06

  • emptyText support React.Node

5.0.0 / 2016-09-07

  • Remove props columnsPageSize and columnsPageRange, use fixed columns instead.
  • Add prop onRowDoubleClick.
  • Improve perfermance when expand row.

4.6.0 / 2016-08-29

Add prop emptyText.

4.5.3 / 2016-08-24

#76

4.5.2 / 2016-08-23

Add indent as third argument to rowClassName rowRef expandRowClassName

4.5.1 / 2016-08-19

Add original event param for onRowClick

4.5.0 / 2016-08-17

Add expandRowByClicky prop, allow expanding the row by clicking it.

4.4.7 / 2016-08-16

Fix https://github.com/ant-design/ant-design/issues/2729

4.4.6 / 2016-08-05

Fix https://github.com/ant-design/ant-design/issues/2625

4.4.2 / 2016-08-01

  • Improve row and cell render perfermance.

4.4.1 / 2016-07-24

  • Fix row expand of key 0 record. (ant-design/ant-design#2471)

4.4.0 / 2016-07-19

  • Add title prop demo
  • Add getBodyWrapper prop demo
  • Use maxHeight for fixed-header Table #65

4.3.0 / 2016-06-20

  • support rowKey="uid"

4.2.0 / 2016-06-16

  • Header can be scroll in fixed-columns Table

4.1.0 / 2016-06-01

  • Support nested string of dataIndex
  • Fix fixed Table with expand row

4.0.0 / 2016-04-18

  • Support fixed columns
  • Add scroll prop
  • Add defaultExpandAllRows prop
  • Add onExpand prop
  • Add rowRef prop

3.11.0 / 2016-02-25

  • Add prop showHeader
  • support render footer via footer={() => <div>xxx</div>}

3.10.0 / 2016-02-22

  • Add prop expandIconColumnIndex

3.9.0 / 2016-01-19

  • support pinned and paging columns.

3.8.0

  • Add onRowClick

3.7.0

  • Add childenIndent

3.6.0 / 2015-11-11

  • add defaultExpandedRowKeys/expandedRowKeys/onExpandedRowsChange prop

3.5.0 / 2015-11-03

  • Add colSpan and rowSpan support

3.3.0 / 2015-10-27

  • support react 0.14

3.2.0 / 2015-09-09

  • add expandIconAsCell prop