mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
Hide expand indicator if row is not expandable and prevent it from being expanded
This commit is contained in:
parent
5a6b7e122d
commit
f175fd4186
@ -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]
|
||||
};
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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>
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user