Merge branch 'vinzentt-fix-nonExpandable-indicator-and-behaviour' into develop

This commit is contained in:
AllenFang 2018-12-20 23:52:42 +08:00
commit d84dc46ff1
6 changed files with 18 additions and 6 deletions

View File

@ -92,15 +92,16 @@ const expandRow = {
```
### <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 two properties:
* `expanded`: Indicate if current row is expanded or not
Provide a callback function which allow you to custom the expand indicator. This callback only have one argument which is an object and contain these properties:
* `expanded`: If current row is expanded or not
* `rowKey`: Current row key
* `expandable`: If currnet row is expandable or not
```js
const expandRow = {
renderer: (row) => ...
expandColumnRenderer: ({ expanded, rowKey }) => (
expandColumnRenderer: ({ expanded, rowKey, expandable }) => (
// ....
)
};

View File

@ -34,7 +34,7 @@ const expandRow = {
}
return <b>+</b>;
},
expandColumnRenderer: ({ expanded, rowKey }) => {
expandColumnRenderer: ({ expanded, rowKey, expandable }) => {
if (expanded) {
return (
<b>-</b>

View File

@ -25,6 +25,7 @@ const expandRow = {
<p>expandRow.renderer callback will pass the origin row object to you</p>
</div>
),
showExpandColumn: true,
nonExpandable: [1, 3]
};
@ -50,6 +51,7 @@ const expandRow = {
<p>expandRow.renderer callback will pass the origin row object to you</p>
</div>
),
showExpandColumn: true,
nonExpandable: [1, 3]
};

View File

@ -23,6 +23,9 @@ class RowExpandProvider extends React.Component {
}
handleRowExpand = (rowKey, expanded, rowIndex, e) => {
if (this.props.expandRow.nonExpandable.includes(rowKey)) {
return;
}
const { data, keyField, expandRow: { onExpand, onlyOneExpanding } } = this.props;
let currExpanded = [...this.state.expanded];
@ -73,6 +76,7 @@ class RowExpandProvider extends React.Component {
<RowExpandContext.Provider
value={ {
...this.props.expandRow,
nonExpandable: this.props.expandRow.nonExpandable,
expanded: this.state.expanded,
isAnyExpands: dataOperator.isAnyExpands(data, keyField, this.state.expanded),
onRowExpand: this.handleRowExpand,

View File

@ -10,6 +10,7 @@ export default class ExpandCell extends Component {
static propTypes = {
rowKey: PropTypes.any,
expanded: PropTypes.bool.isRequired,
expandable: PropTypes.bool.isRequired,
onRowExpand: PropTypes.func.isRequired,
expandColumnRenderer: PropTypes.func,
rowIndex: PropTypes.number,
@ -38,7 +39,7 @@ export default class ExpandCell extends Component {
}
render() {
const { expanded, expandColumnRenderer, tabIndex, rowKey } = this.props;
const { expanded, expandable, expandColumnRenderer, tabIndex, rowKey } = this.props;
const attrs = {};
if (tabIndex !== -1) attrs.tabIndex = tabIndex;
@ -46,9 +47,10 @@ export default class ExpandCell extends Component {
<td onClick={ this.handleClick } { ...attrs }>
{
expandColumnRenderer ? expandColumnRenderer({
expandable,
expanded,
rowKey
}) : (expanded ? '(-)' : '(+)')
}) : (expandable ? (expanded ? '(-)' : '(+)') : '')
}
</td>
);

View File

@ -31,6 +31,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
if (
this.props.selected !== nextProps.selected ||
this.props.expanded !== nextProps.expanded ||
this.props.expandable !== nextProps.expandable ||
this.props.selectable !== nextProps.selectable ||
this.shouldUpdatedBySelfProps(nextProps)
) {
@ -54,6 +55,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
selectRow,
expandRow,
expanded,
expandable,
selected,
selectable,
visibleColumnSize,
@ -84,6 +86,7 @@ export default class RowAggregator extends shouldUpdater(eventDelegater(React.Co
rowKey={ key }
rowIndex={ rowIndex }
expanded={ expanded }
expandable={ expandable }
tabIndex={ tabIndexCell ? tabIndexStart++ : -1 }
/>
) : null