1 | # rc-table
|
2 |
|
3 | React table component.
|
4 |
|
5 | [![NPM version][npm-image]][npm-url]
|
6 | [![build status][travis-image]][travis-url]
|
7 | [![Test coverage][codecov-image]][codecov-url]
|
8 | [![gemnasium deps][gemnasium-image]][gemnasium-url]
|
9 | [![npm download][download-image]][download-url]
|
10 |
|
11 | [npm-image]: http://img.shields.io/npm/v/rc-table.svg?style=flat-square
|
12 | [npm-url]: http://npmjs.org/package/rc-table
|
13 | [travis-image]: https://img.shields.io/travis/react-component/table.svg?style=flat-square
|
14 | [travis-url]: https://travis-ci.org/react-component/table
|
15 | [codecov-image]: https://img.shields.io/codecov/c/github/react-component/table/master.svg?style=flat-square
|
16 | [codecov-url]: https://codecov.io/gh/react-component/table/branch/master
|
17 | [gemnasium-image]: http://img.shields.io/gemnasium/react-component/table.svg?style=flat-square
|
18 | [gemnasium-url]: https://gemnasium.com/react-component/table
|
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 |
|
22 | ## install
|
23 |
|
24 | [](https://npmjs.org/package/rc-table)
|
25 |
|
26 | ## Development
|
27 |
|
28 | ```
|
29 | npm install
|
30 | npm start
|
31 | ```
|
32 |
|
33 | ## Example
|
34 |
|
35 | http://react-component.github.io/table/examples/
|
36 |
|
37 | ## Usage
|
38 |
|
39 | ```js
|
40 | import Table from 'rc-table';
|
41 |
|
42 | const columns = [{
|
43 | title: 'Name', dataIndex: 'name', key:'name', width: 100,
|
44 | }, {
|
45 | title: 'Age', dataIndex: 'age', key:'age', width: 100,
|
46 | }, {
|
47 | title: 'Address', dataIndex: 'address', key:'address', width: 200,
|
48 | }, {
|
49 | title: 'Operations', dataIndex: '', key:'operations', render: () => <a href="#">Delete</a>,
|
50 | }];
|
51 |
|
52 | const data = [
|
53 | { name: 'Jack', age: 28, address: 'some where', key:'1' },
|
54 | { name: 'Rose', age: 36, address: 'some where', key:'2' },
|
55 | ];
|
56 |
|
57 | React.render(<Table columns={columns} data={data} />, mountNode);
|
58 | ```
|
59 |
|
60 | ## API
|
61 |
|
62 | ### Properties
|
63 |
|
64 | <table class="table table-bordered table-striped">
|
65 | <thead>
|
66 | <tr>
|
67 | <th style="width: 100px;">Name</th>
|
68 | <th style="width: 50px;">Type</th>
|
69 | <th>Default</th>
|
70 | <th>Description</th>
|
71 | </tr>
|
72 | </thead>
|
73 | <tbody>
|
74 | <tr>
|
75 | <td>prefixCls</td>
|
76 | <td>String</td>
|
77 | <td>rc-table</td>
|
78 | <td></td>
|
79 | </tr>
|
80 | <tr>
|
81 | <td>className</td>
|
82 | <td>String</td>
|
83 | <td></td>
|
84 | <td>additional className</td>
|
85 | </tr>
|
86 | <tr>
|
87 | <td>id</td>
|
88 | <td>String</td>
|
89 | <td></td>
|
90 | <td>identifier of the container div</td>
|
91 | </tr>
|
92 | <tr>
|
93 | <td>useFixedHeader</td>
|
94 | <td>Boolean</td>
|
95 | <td>false</td>
|
96 | <td>whether use separator table for header. better set width for columns</td>
|
97 | </tr>
|
98 | <tr>
|
99 | <td>scroll</td>
|
100 | <td>Object</td>
|
101 | <td>{x: false, y: false}</td>
|
102 | <td>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</td>
|
103 | </tr>
|
104 | <tr>
|
105 | <td>expandIconAsCell</td>
|
106 | <td>Boolean</td>
|
107 | <td>false</td>
|
108 | <td>whether render expandIcon as a cell</td>
|
109 | </tr>
|
110 | <tr>
|
111 | <td>expandIconColumnIndex</td>
|
112 | <td>Number</td>
|
113 | <td>0</td>
|
114 | <td>The index of expandIcon which column will be inserted when expandIconAsCell is false</td>
|
115 | </tr>
|
116 | <tr>
|
117 | <td>rowKey</td>
|
118 | <td>string or Function(record):string</td>
|
119 | <td>'key'</td>
|
120 | <td>
|
121 | If rowKey is string, `record[rowKey]` will be used as key.
|
122 | If rowKey is function, the return value of `rowKey(record)` will be use as key.
|
123 | </td>
|
124 | </tr>
|
125 | <tr>
|
126 | <td>rowClassName</td>
|
127 | <td>string or Function(record, index, indent):string</td>
|
128 | <td></td>
|
129 | <td>get row's className</td>
|
130 | </tr>
|
131 | <tr>
|
132 | <td>rowRef</td>
|
133 | <td>Function(record, index, indent):string</td>
|
134 | <td></td>
|
135 | <td>get row's ref key</td>
|
136 | </tr>
|
137 | <tr>
|
138 | <td>defaultExpandedRowKeys</td>
|
139 | <td>String[]</td>
|
140 | <td>[]</td>
|
141 | <td>initial expanded rows keys</td>
|
142 | </tr>
|
143 | <tr>
|
144 | <td>expandedRowKeys</td>
|
145 | <td>String[]</td>
|
146 | <td></td>
|
147 | <td>current expanded rows keys</td>
|
148 | </tr>
|
149 | <tr>
|
150 | <td>defaultExpandAllRows</td>
|
151 | <td>Boolean</td>
|
152 | <td>false</td>
|
153 | <td>Expand All Rows initially</td>
|
154 | </tr>
|
155 | <tr>
|
156 | <td>onExpandedRowsChange</td>
|
157 | <td>Function(expandedRows)</td>
|
158 | <td>save the expanded rows in the internal state</td>
|
159 | <td>function to call when the expanded rows change</td>
|
160 | </tr>
|
161 | <tr>
|
162 | <td>onExpand</td>
|
163 | <td>Function(expanded, record)</td>
|
164 | <td></td>
|
165 | <td>function to call when click expand icon</td>
|
166 | </tr>
|
167 | <tr>
|
168 | <td>expandedRowClassName</td>
|
169 | <td>Function(recode, index, indent):string</td>
|
170 | <td></td>
|
171 | <td>get expanded row's className</td>
|
172 | </tr>
|
173 | <tr>
|
174 | <td>expandedRowRender</td>
|
175 | <td>Function(recode, index, indent, expanded):ReactNode</td>
|
176 | <td></td>
|
177 | <td>Content render to expanded row</td>
|
178 | </tr>
|
179 | <tr>
|
180 | <td>data</td>
|
181 | <td>Object[]</td>
|
182 | <td></td>
|
183 | <td>data record array to be rendered</td>
|
184 | </tr>
|
185 | <tr>
|
186 | <td>indentSize</td>
|
187 | <td>Number</td>
|
188 | <td>15</td>
|
189 | <td>indentSize for every level of data.i.children, better using with column.width specified</td>
|
190 | </tr>
|
191 | <tr>
|
192 | <td>onRowClick[deprecated]</td>
|
193 | <td>Function(record, index)</td>
|
194 | <td></td>
|
195 | <td>handle rowClick action, index means the index of current row among fatherElement[childrenColumnName]</td>
|
196 | </tr>
|
197 | <tr>
|
198 | <td>onRowDoubleClick[deprecated]</td>
|
199 | <td>Function(record, index)</td>
|
200 | <td></td>
|
201 | <td>handle rowDoubleClick action, index means the index of current row among fatherElement[childrenColumnName]</td>
|
202 | </tr>
|
203 | <tr>
|
204 | <td>onRowMouseEnter[deprecated]</td>
|
205 | <td>Function(record, index)</td>
|
206 | <td></td>
|
207 | <td>handle onRowMouseEnter action, index means the index of current row among fatherElement[childrenColumnName]</td>
|
208 | </tr>
|
209 | <tr>
|
210 | <td>onRowMouseLeave[deprecated]</td>
|
211 | <td>Function(record, index)</td>
|
212 | <td></td>
|
213 | <td>handle onRowMouseLeave action, index means the index of current row among fatherElement[childrenColumnName]</td>
|
214 | </tr>
|
215 | <tr>
|
216 | <td>onRow</td>
|
217 | <td>Function(record, index)</td>
|
218 | <td></td>
|
219 | <td>Set custom props per each row.</td>
|
220 | </tr>
|
221 | <tr>
|
222 | <td>onHeaderRow</td>
|
223 | <td>Function(record, index)</td>
|
224 | <td></td>
|
225 | <td>Set custom props per each header row.</td>
|
226 | </tr>
|
227 | <tr>
|
228 | <td>showHeader</td>
|
229 | <td>Boolean</td>
|
230 | <td>true</td>
|
231 | <td>whether table head is shown</td>
|
232 | </tr>
|
233 | <tr>
|
234 | <td>title</td>
|
235 | <td>Function(currentData)</td>
|
236 | <td></td>
|
237 | <td>table title render function</td>
|
238 | </tr>
|
239 | <tr>
|
240 | <td>footer</td>
|
241 | <td>Function(currentData)</td>
|
242 | <td></td>
|
243 | <td>table footer render function</td>
|
244 | </tr>
|
245 | <tr>
|
246 | <td>getBodyWrapper[deprecated]</td>
|
247 | <td>Function(body)</td>
|
248 | <td></td>
|
249 | <td>get wrapper of tbody, [demo](http://react-component.github.io/table/examples/animation.html)</td>
|
250 | </tr>
|
251 | <tr>
|
252 | <td>emptyText</td>
|
253 | <td>React.Node or Function</td>
|
254 | <td>`No Data`</td>
|
255 | <td>Display text when data is empty</td>
|
256 | </tr>
|
257 | <tr>
|
258 | <td>columns</td>
|
259 | <td>Object[]<Object></td>
|
260 | <td></td>
|
261 | <td>
|
262 | The columns config of table, see table below
|
263 | </td>
|
264 | </tr>
|
265 | <tr>
|
266 | <td>components</td>
|
267 | <td>Object</td>
|
268 | <td></td>
|
269 | <td>
|
270 | Override table elements, see [#171](https://github.com/react-component/table/pull/171) for more details
|
271 | </td>
|
272 | </tr>
|
273 | </tbody>
|
274 | </table>
|
275 |
|
276 | ## Column Props
|
277 |
|
278 | <table>
|
279 | <thead>
|
280 | <tr>
|
281 | <th style="width: 100px;">Name</th>
|
282 | <th style="width: 50px;">Type</th>
|
283 | <th>Default</th>
|
284 | <th>Description</th>
|
285 | </tr>
|
286 | </thead>
|
287 | <tbody>
|
288 | <tr>
|
289 | <td>key</td>
|
290 | <td>String</td>
|
291 | <td></td>
|
292 | <td>key of this column</td>
|
293 | </tr>
|
294 | <tr>
|
295 | <td>className</td>
|
296 | <td>String</td>
|
297 | <td></td>
|
298 | <td>className of this column</td>
|
299 | </tr>
|
300 | <tr>
|
301 | <td>colSpan</td>
|
302 | <td>Number</td>
|
303 | <td></td>
|
304 | <td>thead colSpan of this column</td>
|
305 | </tr>
|
306 | <tr>
|
307 | <td>title</td>
|
308 | <td>React Node</td>
|
309 | <td></td>
|
310 | <td>title of this column</td>
|
311 | </tr>
|
312 | <tr>
|
313 | <td>dataIndex</td>
|
314 | <td>String</td>
|
315 | <td></td>
|
316 | <td>display field of the data record</td>
|
317 | </tr>
|
318 | <tr>
|
319 | <td>width</td>
|
320 | <td>String|Number</td>
|
321 | <td></td>
|
322 | <td>width of the specific proportion calculation according to the width of the columns</td>
|
323 | </tr>
|
324 | <tr>
|
325 | <td>fixed</td>
|
326 | <td>String|Boolean</td>
|
327 | <td></td>
|
328 | <td>this column will be fixed when table scroll horizontally: true or 'left' or 'right'</td>
|
329 | </tr>
|
330 | <tr>
|
331 | <td>align</td>
|
332 | <td>String</td>
|
333 | <td></td>
|
334 | <td>specify how content is aligned</td>
|
335 | </tr>
|
336 | <tr>
|
337 | <td>onCell</td>
|
338 | <td>Function(record, index)</td>
|
339 | <td></td>
|
340 | <td>Set custom props per each cell.</td>
|
341 | </tr>
|
342 | <tr>
|
343 | <td>onHeaderCell</td>
|
344 | <td>Function(record)</td>
|
345 | <td></td>
|
346 | <td>Set custom props per each header cell.</td>
|
347 | </tr>
|
348 | <tr>
|
349 | <td>render</td>
|
350 | <td>Function(value, row, index)</td>
|
351 | <td></td>
|
352 | <td>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</td>
|
353 | </tr>
|
354 | <tr>
|
355 | <td>onCellClick[deprecated]</td>
|
356 | <td>Function(row, event)</td>
|
357 | <td></td>
|
358 | <td>Called when column's cell is clicked</td>
|
359 | </tr>
|
360 | </tbody>
|
361 | </table>
|
362 |
|
363 | ## License
|
364 |
|
365 | rc-table is released under the MIT license.
|