diff --git a/docs/row-expand.md b/docs/row-expand.md index 5de4f7b..ce710de 100644 --- a/docs/row-expand.md +++ b/docs/row-expand.md @@ -92,15 +92,16 @@ const expandRow = { ``` ### expandRow.expandColumnRenderer - [Function] -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 }) => ( // .... ) }; diff --git a/packages/react-bootstrap-table2-example/examples/row-expand/custom-expand-column.js b/packages/react-bootstrap-table2-example/examples/row-expand/custom-expand-column.js index b1ed8c1..507bcf2 100644 --- a/packages/react-bootstrap-table2-example/examples/row-expand/custom-expand-column.js +++ b/packages/react-bootstrap-table2-example/examples/row-expand/custom-expand-column.js @@ -34,7 +34,7 @@ const expandRow = { } return +; }, - expandColumnRenderer: ({ expanded, rowKey }) => { + expandColumnRenderer: ({ expanded, rowKey, expandable }) => { if (expanded) { return ( - diff --git a/packages/react-bootstrap-table2-example/examples/row-expand/non-expandable-rows.js b/packages/react-bootstrap-table2-example/examples/row-expand/non-expandable-rows.js index 6d1ef32..44acdf9 100644 --- a/packages/react-bootstrap-table2-example/examples/row-expand/non-expandable-rows.js +++ b/packages/react-bootstrap-table2-example/examples/row-expand/non-expandable-rows.js @@ -25,6 +25,7 @@ const expandRow = {

expandRow.renderer callback will pass the origin row object to you

), + showExpandColumn: true, nonExpandable: [1, 3] }; @@ -50,6 +51,7 @@ const expandRow = {

expandRow.renderer callback will pass the origin row object to you

), + showExpandColumn: true, nonExpandable: [1, 3] }; diff --git a/packages/react-bootstrap-table2/src/contexts/row-expand-context.js b/packages/react-bootstrap-table2/src/contexts/row-expand-context.js index 5a3728b..6ba6b95 100644 --- a/packages/react-bootstrap-table2/src/contexts/row-expand-context.js +++ b/packages/react-bootstrap-table2/src/contexts/row-expand-context.js @@ -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 { { expandColumnRenderer ? expandColumnRenderer({ + expandable, expanded, rowKey - }) : (expanded ? '(-)' : '(+)') + }) : (expandable ? (expanded ? '(-)' : '(+)') : '') } ); diff --git a/packages/react-bootstrap-table2/src/row/aggregate-row.js b/packages/react-bootstrap-table2/src/row/aggregate-row.js index 32c997a..dfba8b5 100644 --- a/packages/react-bootstrap-table2/src/row/aggregate-row.js +++ b/packages/react-bootstrap-table2/src/row/aggregate-row.js @@ -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