Hide expand indicator if row is not expandable and prevent it from being expanded

This commit is contained in:
Vincent Degroote 2018-12-05 10:50:52 +01:00
parent 5a6b7e122d
commit f175fd4186
4 changed files with 1362 additions and 2 deletions

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,
nonExpandable: PropTypes.array.isRequired,
onRowExpand: PropTypes.func.isRequired,
expandColumnRenderer: PropTypes.func,
rowIndex: PropTypes.number,
@ -38,8 +39,9 @@ export default class ExpandCell extends Component {
}
render() {
const { expanded, expandColumnRenderer, tabIndex } = this.props;
const { expanded, nonExpandable, expandColumnRenderer, tabIndex } = this.props;
const attrs = {};
const isExpandable = !nonExpandable.includes(this.props.rowKey);
if (tabIndex !== -1) attrs.tabIndex = tabIndex;
return (
@ -47,7 +49,7 @@ export default class ExpandCell extends Component {
{
expandColumnRenderer ? expandColumnRenderer({
expanded
}) : (expanded ? '(-)' : '(+)')
}) : (isExpandable ? (expanded ? '(-)' : '(+)') : '')
}
</td>
);

1352
yarn.lock

File diff suppressed because it is too large Load Diff