This commit is contained in:
AllenFang 2018-12-20 23:20:12 +08:00
parent 9d2a6a1b23
commit bc4697bf95
3 changed files with 9 additions and 5 deletions

View File

@ -92,13 +92,15 @@ const expandRow = {
``` ```
### <a name='expandColumnRenderer'>expandRow.expandColumnRenderer - [Function]</a> ### <a name='expandColumnRenderer'>expandRow.expandColumnRenderer - [Function]</a>
Provide a callback function which allow you to custom the expand indicator. This callback only have one argument which is an object and contain one property `expanded` which indicate if current row is expanded Provide a callback function which allow you to custom the expand indicator. This callback only have one argument which is an object and contain two properties:
* `expanded`: Indicate if current row is expanded or not
* `rowKey`: Current row key
```js ```js
const expandRow = { const expandRow = {
renderer: (row) => ... renderer: (row) => ...
expandColumnRenderer: ({ expanded }) => ( expandColumnRenderer: ({ expanded, rowKey }) => (
// .... // ....
) )
}; };

View File

@ -1,4 +1,5 @@
/* eslint react/prop-types: 0 */ /* eslint react/prop-types: 0 */
/* eslint no-unused-vars: 0 */
import React from 'react'; import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next'; import BootstrapTable from 'react-bootstrap-table-next';
@ -33,7 +34,7 @@ const expandRow = {
} }
return <b>+</b>; return <b>+</b>;
}, },
expandColumnRenderer: ({ expanded }) => { expandColumnRenderer: ({ expanded, rowKey }) => {
if (expanded) { if (expanded) {
return ( return (
<b>-</b> <b>-</b>

View File

@ -38,7 +38,7 @@ export default class ExpandCell extends Component {
} }
render() { render() {
const { expanded, expandColumnRenderer, tabIndex } = this.props; const { expanded, expandColumnRenderer, tabIndex, rowKey } = this.props;
const attrs = {}; const attrs = {};
if (tabIndex !== -1) attrs.tabIndex = tabIndex; if (tabIndex !== -1) attrs.tabIndex = tabIndex;
@ -46,7 +46,8 @@ export default class ExpandCell extends Component {
<td onClick={ this.handleClick } { ...attrs }> <td onClick={ this.handleClick } { ...attrs }>
{ {
expandColumnRenderer ? expandColumnRenderer({ expandColumnRenderer ? expandColumnRenderer({
expanded expanded,
rowKey
}) : (expanded ? '(-)' : '(+)') }) : (expanded ? '(-)' : '(+)')
} }
</td> </td>