1 | # rc-table
|
2 |
|
3 | React table component with useful functions.
|
4 |
|
5 | [![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][codecov-image]][codecov-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
|
6 |
|
7 | [npm-image]: http://img.shields.io/npm/v/rc-table.svg?style=flat-square
|
8 | [npm-url]: http://npmjs.org/package/rc-table
|
9 | [github-actions-image]: https://github.com/react-component/table/workflows/CI/badge.svg
|
10 | [github-actions-url]: https://github.com/react-component/table/actions
|
11 | [coveralls-image]: https://img.shields.io/coveralls/react-component/table.svg?style=flat-square
|
12 | [coveralls-url]: https://coveralls.io/r/react-component/table?branch=master
|
13 | [codecov-image]: https://img.shields.io/codecov/c/github/react-component/table/master.svg?style=flat-square
|
14 | [codecov-url]: https://codecov.io/gh/react-component/table/branch/master
|
15 | [david-url]: https://david-dm.org/react-component/table
|
16 | [david-image]: https://david-dm.org/react-component/table/status.svg?style=flat-square
|
17 | [david-dev-url]: https://david-dm.org/react-component/table?type=dev
|
18 | [david-dev-image]: https://david-dm.org/react-component/table/dev-status.svg?style=flat-square
|
19 | [download-image]: https://img.shields.io/npm/dm/rc-table.svg?style=flat-square
|
20 | [download-url]: https://npmjs.org/package/rc-table
|
21 | [bundlephobia-url]: https://bundlephobia.com/result?p=rc-table
|
22 | [bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-table
|
23 |
|
24 | ## install
|
25 |
|
26 | [![rc-table](https://nodei.co/npm/rc-table.png)](https://npmjs.org/package/rc-table)
|
27 |
|
28 | ## Development
|
29 |
|
30 | ```
|
31 | npm install
|
32 | npm start
|
33 | ```
|
34 |
|
35 | ## Example
|
36 |
|
37 | https://table-react-component.vercel.app/
|
38 |
|
39 | ## Usage
|
40 |
|
41 | ```js
|
42 | import Table from 'rc-table';
|
43 |
|
44 | const columns = [
|
45 | {
|
46 | title: 'Name',
|
47 | dataIndex: 'name',
|
48 | key: 'name',
|
49 | width: 100,
|
50 | },
|
51 | {
|
52 | title: 'Age',
|
53 | dataIndex: 'age',
|
54 | key: 'age',
|
55 | width: 100,
|
56 | },
|
57 | {
|
58 | title: 'Address',
|
59 | dataIndex: 'address',
|
60 | key: 'address',
|
61 | width: 200,
|
62 | },
|
63 | {
|
64 | title: 'Operations',
|
65 | dataIndex: '',
|
66 | key: 'operations',
|
67 | render: () => <a href="#">Delete</a>,
|
68 | },
|
69 | ];
|
70 |
|
71 | const data = [
|
72 | { name: 'Jack', age: 28, address: 'some where', key: '1' },
|
73 | { name: 'Rose', age: 36, address: 'some where', key: '2' },
|
74 | ];
|
75 |
|
76 | React.render(<Table columns={columns} data={data} />, mountNode);
|
77 | ```
|
78 |
|
79 | ## API
|
80 |
|
81 | ### Properties
|
82 |
|
83 | | Name | Type | Default | Description |
|
84 | | --- | --- | --- | --- |
|
85 | | 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 |
|
86 | | prefixCls | String | rc-table | |
|
87 | | className | String | | additional className |
|
88 | | id | String | | identifier of the container div |
|
89 | | useFixedHeader | Boolean | false | whether use separator table for header. better set width for columns |
|
90 | | 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 |
|
91 | | expandable | Object | | Config expand props |
|
92 | | expandable.defaultExpandAllRows | Boolean | false | Expand All Rows initially |
|
93 | | expandable.defaultExpandedRowKeys | String[] | [] | initial expanded rows keys |
|
94 | | expandable.expandedRowKeys | String[] | | current expanded rows keys |
|
95 | | expandable.expandedRowRender | Function(recode, index, indent, expanded):ReactNode | | Content render to expanded row |
|
96 | | expandable.expandedRowClassName | Function(recode, index, indent):string | | get expanded row's className |
|
97 | | expandable.expandRowByClick | boolean | | Support expand by click row |
|
98 | | expandable.expandIconColumnIndex | Number | 0 | The index of expandIcon which column will be inserted when expandIconAsCell is false |
|
99 | | expandable.expandIcon | props => ReactNode | | Customize expand icon |
|
100 | | expandable.indentSize | Number | 15 | indentSize for every level of data.i.children, better using with column.width specified |
|
101 | | expandable.rowExpandable | (record) => boolean | | Config row support expandable |
|
102 | | expandable.onExpand | Function(expanded, record) | | function to call when click expand icon |
|
103 | | expandable.onExpandedRowsChange | Function(expandedRows) | | function to call when the expanded rows change |
|
104 | | 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 |
|
105 | | 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. |
|
106 | | rowClassName | string or Function(record, index, indent):string | | get row's className |
|
107 | | rowRef | Function(record, index, indent):string | | get row's ref key |
|
108 | | data | Object[] | | data record array to be rendered |
|
109 | | onRow | Function(record, index) | | Set custom props per each row. |
|
110 | | onHeaderRow | Function(record, index) | | Set custom props per each header row. |
|
111 | | showHeader | Boolean | true | whether table head is shown |
|
112 | | hidden | Boolean | `false` | Hidden column. |
|
113 | | title | Function(currentData) | | table title render function |
|
114 | | footer | Function(currentData) | | table footer render function |
|
115 | | emptyText | React.Node or Function | `No Data` | Display text when data is empty |
|
116 | | columns | Object[] | | The columns config of table, see table below |
|
117 | | components | Object | | Override table elements, see [#171](https://github.com/react-component/table/pull/171) for more details |
|
118 | | sticky | boolean \| {offsetHeader?: number, offsetScroll?: number, getContainer?: () => Window \| HTMLElement } | false | stick header and scroll bar |
|
119 | | summary | (data: readonly RecordType[]) => React.ReactNode | - | `summary` attribute in `table` component is used to define the summary row. |
|
120 | | rowHoverable | boolean | true | Table hover interaction |
|
121 |
|
122 | ## Column Props
|
123 |
|
124 | | Name | Type | Default | Description |
|
125 | | --- | --- | --- | --- |
|
126 | | key | String | | key of this column |
|
127 | | className | String | | className of this column |
|
128 | | colSpan | Number | | thead colSpan of this column |
|
129 | | title | React Node | | title of this column |
|
130 | | dataIndex | String | | display field of the data record |
|
131 | | width | String \| Number | | width of the specific proportion calculation according to the width of the columns |
|
132 | | minWidth | Number | | the minimum width of the column, only worked when tableLayout is auto |
|
133 | | fixed | String \| Boolean | | this column will be fixed when table scroll horizontally: true or 'left' or 'right' |
|
134 | | align | String | | specify how cell content is aligned |
|
135 | | ellipsis | Boolean | | specify whether cell content be ellipsized |
|
136 | | rowScope | 'row' \| 'rowgroup' | | Set scope attribute for all cells in this column |
|
137 | | onCell | Function(record, index) | | Set custom props per each cell. |
|
138 | | onHeaderCell | Function(record) | | Set custom props per each header cell. |
|
139 | | 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 |
|
140 |
|
141 | ## Summary Props
|
142 |
|
143 | ### Table.Summary
|
144 |
|
145 | | Name | Type | Default | Description |
|
146 | | --- | --- | --- | --- |
|
147 | | key | String | | key of this summary |
|
148 | | 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. |
|
149 |
|
150 | ### Table.Summary.Row
|
151 |
|
152 | | Name | Type | Default | Description |
|
153 | | --- | --- | --- | --- |
|
154 | | key | String | | key of this summary |
|
155 | | className | String | - | className of this summary row |
|
156 | | style | React.CSSProperties | - | style of this summary row |
|
157 | | 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. |
|
158 |
|
159 | ## License
|
160 |
|
161 | rc-table is released under the MIT license.
|