Skip to content

Commit 061ffa5

Browse files
author
rajaramg
committed
added showExpandAllHeaderColumn to show/hide header column
1 parent 344308f commit 061ffa5

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

css/react-bootstrap-table.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ td.react-bs-table-expand-cell {
261261
cursor: pointer;
262262
}
263263

264-
th.react-bs-table-expand-cell {
264+
th.react-bs-table-expand-cell > div {
265265
cursor: pointer;
266266
}
267267

examples/js/expandRow/custom-expand-indicator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export default class ExpandRow extends React.Component {
9393
render() {
9494
const options = {
9595
expandRowBgColor: 'rgb(242, 255, 163)',
96-
expandAllChilds: false
96+
expandAllChilds: false,
97+
showExpandAllHeaderColumn: true
9798
};
9899
return (
99100
<BootstrapTable data={ products }

src/BootstrapTable.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ class BootstrapTable extends Component {
480480
expandedColumnHeaderComponent={ expandColumnOptions.expandedColumnHeaderComponent }
481481
expandAllChilds={ this.state.expandAllChilds }
482482
toggleExpandAllChilds={ this.toggleExpandAllChilds }
483+
showExpandAllHeaderColumn={ this.props.options.showExpandAllHeaderColumn }
483484
expandColumnBeforeSelectColumn={ expandColumnOptions.expandColumnBeforeSelectColumn }>
484485
{ this.props.children }
485486
</TableHeader>
@@ -1727,7 +1728,8 @@ BootstrapTable.propTypes = {
17271728
printToolBar: PropTypes.bool,
17281729
insertFailIndicator: PropTypes.string,
17291730
noAutoBOM: PropTypes.bool,
1730-
expandAllChilds: PropTypes.bool
1731+
expandAllChilds: PropTypes.bool,
1732+
showExpandAllHeaderColumn: PropTypes.bool
17311733
}),
17321734
fetchInfo: PropTypes.shape({
17331735
dataTotalSize: PropTypes.number
@@ -1897,7 +1899,8 @@ BootstrapTable.defaultProps = {
18971899
printToolBar: true,
18981900
insertFailIndicator: Const.INSERT_FAIL_INDICATOR,
18991901
noAutoBOM: true,
1900-
expandAllChilds: false
1902+
expandAllChilds: false,
1903+
showExpandAllHeaderColumn: false
19011904
},
19021905
fetchInfo: {
19031906
dataTotalSize: 0

src/ExpandRowHeaderColumn.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ class ExpandRowHeaderColumn extends Component {
1313
}
1414

1515
render() {
16-
const { expandedColumnHeaderComponent, expandAllChilds } = this.props;
17-
const defaultExpandedHeaderComponent = (expandAllChilds ? '(-)' : '(+)' );
16+
const {
17+
expandedColumnHeaderComponent,
18+
expandAllChilds,
19+
showExpandAllHeaderColumn
20+
} = this.props;
21+
const expandedHeaderComponent = (expandAllChilds ? '(-)' : '(+)' );
1822
const ExpandedColumnHeaderComponent = expandedColumnHeaderComponent;
1923

2024
return (
2125
<th rowSpan={ this.props.rowCount } style={ { textAlign: 'center' } }
2226
className='react-bs-table-expand-cell'
23-
data-is-only-head={ false } onClick={ this.toggleExpandAllChilds }>
24-
{ this.props.expandedColumnHeaderComponent ?
25-
<ExpandedColumnHeaderComponent
26-
expandAllChilds={ this.props.expandAllChilds } /> : defaultExpandedHeaderComponent }
27+
data-is-only-head={ false }>
28+
{ showExpandAllHeaderColumn && <div onClick={ this.toggleExpandAllChilds }>
29+
{ expandedColumnHeaderComponent ?
30+
<ExpandedColumnHeaderComponent
31+
expandAllChilds={ this.props.expandAllChilds } /> : expandedHeaderComponent }
32+
</div> }
2733
</th>
2834
);
2935
}
@@ -32,6 +38,7 @@ ExpandRowHeaderColumn.propTypes = {
3238
expandedColumnHeaderComponent: PropTypes.func,
3339
rowCount: PropTypes.number,
3440
expandAllChilds: PropTypes.bool,
35-
toggleExpandAllChilds: PropTypes.func
41+
toggleExpandAllChilds: PropTypes.func,
42+
showExpandAllHeaderColumn: PropTypes.bool
3643
};
3744
export default ExpandRowHeaderColumn;

src/TableHeader.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class TableHeader extends Component {
3939

4040
render() {
4141
const { sortIndicator, sortList, onSort, reset, version, condensed, bordered,
42-
expandedColumnHeaderComponent, expandAllChilds, toggleExpandAllChilds } = this.props;
42+
expandedColumnHeaderComponent, expandAllChilds, toggleExpandAllChilds,
43+
showExpandAllHeaderColumn } = this.props;
4344
const containerClasses = classSet(
4445
'react-bs-container-header',
4546
'table-header-wrapper',
@@ -68,7 +69,8 @@ class TableHeader extends Component {
6869
<ExpandRowHeaderColumn key='expandCol' rowCount={ rowCount + 1 }
6970
expandedColumnHeaderComponent={ expandedColumnHeaderComponent }
7071
expandAllChilds={ expandAllChilds }
71-
toggleExpandAllChilds={ toggleExpandAllChilds }/>
72+
toggleExpandAllChilds={ toggleExpandAllChilds }
73+
showExpandAllHeaderColumn={ showExpandAllHeaderColumn }/>
7274
], [
7375
this.renderSelectRowHeader(rowCount + 1, rowKey++)
7476
], [
@@ -77,7 +79,8 @@ class TableHeader extends Component {
7779
<ExpandRowHeaderColumn key='expandCol' rowCount={ rowCount + 1 }
7880
expandedColumnHeaderComponent={ expandedColumnHeaderComponent }
7981
expandAllChilds={ expandAllChilds }
80-
toggleExpandAllChilds={ toggleExpandAllChilds }/>
82+
toggleExpandAllChilds={ toggleExpandAllChilds }
83+
showExpandAllHeaderColumn={ showExpandAllHeaderColumn }/>
8184
]);
8285

8386
React.Children.forEach(this.props.children, (elm) => {
@@ -177,7 +180,8 @@ TableHeader.propTypes = {
177180
expandColumnBeforeSelectColumn: PropTypes.bool,
178181
version: PropTypes.string,
179182
expandAllChilds: PropTypes.bool,
180-
toggleExpandAllChilds: PropTypes.func
183+
toggleExpandAllChilds: PropTypes.func,
184+
showExpandAllHeaderColumn: PropTypes.bool
181185
};
182186

183187
export default TableHeader;

0 commit comments

Comments
 (0)