Skip to content

Commit d4691d3

Browse files
committed
refine expand all
1 parent 7432902 commit d4691d3

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed

src/BootstrapTable.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class BootstrapTable extends Component {
6161
sizePerPage: this.props.options.sizePerPage || Const.SIZE_PER_PAGE_LIST[0],
6262
selectedRowKeys: this.store.getSelectedRowKeys(),
6363
reset: false,
64-
expandAllChilds: this.props.options.expandAllChilds,
6564
x: this.props.keyBoardNav ? 0 : -1,
6665
y: this.props.keyBoardNav ? 0 : -1
6766
};
@@ -488,9 +487,9 @@ class BootstrapTable extends Component {
488487
expandColumnVisible={ expandColumnOptions.expandColumnVisible }
489488
expandColumnComponent={ expandColumnOptions.expandColumnComponent }
490489
expandedColumnHeaderComponent={ expandColumnOptions.expandedColumnHeaderComponent }
491-
expandAllChilds={ this.state.expandAllChilds }
490+
noAnyExpand={ this.state.expanding.length === 0 }
491+
expandAll={ this.props.options.expandAll }
492492
toggleExpandAllChilds={ this.toggleExpandAllChilds }
493-
showExpandAllHeaderColumn={ this.props.options.showExpandAllHeaderColumn }
494493
expandColumnBeforeSelectColumn={ expandColumnOptions.expandColumnBeforeSelectColumn }>
495494
{ this.props.children }
496495
</TableHeader>
@@ -642,21 +641,18 @@ class BootstrapTable extends Component {
642641
}
643642

644643
toggleExpandAllChilds() {
645-
const { expandAllChilds } = this.state;
646-
const compScope = this;
647-
if (expandAllChilds) {
644+
const { expanding } = this.state;
645+
if (expanding.length > 0) {
648646
this.setState(() => {
649647
return {
650648
expanding: [],
651-
expandAllChilds: !expandAllChilds,
652649
reset: false
653650
};
654651
});
655652
} else {
656653
this.setState(() => {
657654
return {
658-
expanding: compScope.store.getAllRowkey(),
659-
expandAllChilds: !expandAllChilds,
655+
expanding: this.store.getAllRowkey(),
660656
reset: false
661657
};
662658
});
@@ -1741,8 +1737,7 @@ BootstrapTable.propTypes = {
17411737
printToolBar: PropTypes.bool,
17421738
insertFailIndicator: PropTypes.string,
17431739
noAutoBOM: PropTypes.bool,
1744-
expandAllChilds: PropTypes.bool,
1745-
showExpandAllHeaderColumn: PropTypes.bool
1740+
expandAll: PropTypes.bool
17461741
}),
17471742
fetchInfo: PropTypes.shape({
17481743
dataTotalSize: PropTypes.number
@@ -1913,8 +1908,7 @@ BootstrapTable.defaultProps = {
19131908
printToolBar: true,
19141909
insertFailIndicator: Const.INSERT_FAIL_INDICATOR,
19151910
noAutoBOM: true,
1916-
expandAllChilds: false,
1917-
showExpandAllHeaderColumn: false
1911+
expandAll: false
19181912
},
19191913
fetchInfo: {
19201914
dataTotalSize: 0

src/ExpandRowHeaderColumn.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,34 @@ class ExpandRowHeaderColumn extends Component {
1515
render() {
1616
const {
1717
expandedColumnHeaderComponent,
18-
expandAllChilds,
19-
showExpandAllHeaderColumn
18+
noAnyExpand,
19+
expandAll
2020
} = this.props;
21-
const expandedHeaderComponent = (expandAllChilds ? '(-)' : '(+)' );
21+
const expandedHeaderComponent = noAnyExpand ?
22+
<span className='fa fa-plus glyphicon glyphicon-plus'></span> :
23+
<span className='fa fa-minus glyphicon glyphicon-minus'></span>;
2224
const ExpandedColumnHeaderComponent = expandedColumnHeaderComponent;
2325

2426
return (
2527
<th rowSpan={ this.props.rowCount } style={ { textAlign: 'center' } }
2628
className='react-bs-table-expand-cell'
2729
data-is-only-head={ false }>
28-
{ showExpandAllHeaderColumn && <div onClick={ this.toggleExpandAllChilds }>
30+
{
31+
expandAll ? <div onClick={ this.toggleExpandAllChilds }>
2932
{ expandedColumnHeaderComponent ?
3033
<ExpandedColumnHeaderComponent
31-
expandAllChilds={ this.props.expandAllChilds } /> : expandedHeaderComponent }
32-
</div> }
34+
anyExpand={ !noAnyExpand } /> : expandedHeaderComponent }
35+
</div> : null
36+
}
3337
</th>
3438
);
3539
}
3640
}
3741
ExpandRowHeaderColumn.propTypes = {
3842
expandedColumnHeaderComponent: PropTypes.func,
3943
rowCount: PropTypes.number,
40-
expandAllChilds: PropTypes.bool,
41-
toggleExpandAllChilds: PropTypes.func,
42-
showExpandAllHeaderColumn: PropTypes.bool
44+
noAnyExpand: PropTypes.bool,
45+
expandAll: PropTypes.bool,
46+
toggleExpandAllChilds: PropTypes.func
4347
};
4448
export default ExpandRowHeaderColumn;

src/TableHeader.js

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

4040
render() {
4141
const { sortIndicator, sortList, onSort, reset, version, condensed, bordered,
42-
expandedColumnHeaderComponent, expandAllChilds, toggleExpandAllChilds,
43-
showExpandAllHeaderColumn } = this.props;
42+
expandedColumnHeaderComponent, noAnyExpand, toggleExpandAllChilds, expandAll
43+
} = this.props;
4444
const containerClasses = classSet(
4545
'react-bs-container-header',
4646
'table-header-wrapper',
@@ -68,19 +68,19 @@ class TableHeader extends Component {
6868
this.props.expandColumnBeforeSelectColumn &&
6969
<ExpandRowHeaderColumn key='expandCol' rowCount={ rowCount + 1 }
7070
expandedColumnHeaderComponent={ expandedColumnHeaderComponent }
71-
expandAllChilds={ expandAllChilds }
72-
toggleExpandAllChilds={ toggleExpandAllChilds }
73-
showExpandAllHeaderColumn={ showExpandAllHeaderColumn }/>
71+
noAnyExpand={ noAnyExpand }
72+
expandAll={ expandAll }
73+
toggleExpandAllChilds={ toggleExpandAllChilds }/>
7474
], [
7575
this.renderSelectRowHeader(rowCount + 1, rowKey++)
7676
], [
7777
this.props.expandColumnVisible &&
7878
!this.props.expandColumnBeforeSelectColumn &&
7979
<ExpandRowHeaderColumn key='expandCol' rowCount={ rowCount + 1 }
8080
expandedColumnHeaderComponent={ expandedColumnHeaderComponent }
81-
expandAllChilds={ expandAllChilds }
82-
toggleExpandAllChilds={ toggleExpandAllChilds }
83-
showExpandAllHeaderColumn={ showExpandAllHeaderColumn }/>
81+
noAnyExpand={ noAnyExpand }
82+
expandAll={ expandAll }
83+
toggleExpandAllChilds={ toggleExpandAllChilds }/>
8484
]);
8585

8686
React.Children.forEach(this.props.children, (elm) => {
@@ -182,9 +182,9 @@ TableHeader.propTypes = {
182182
expandedColumnHeaderComponent: PropTypes.func,
183183
expandColumnBeforeSelectColumn: PropTypes.bool,
184184
version: PropTypes.string,
185-
expandAllChilds: PropTypes.bool,
186-
toggleExpandAllChilds: PropTypes.func,
187-
showExpandAllHeaderColumn: PropTypes.bool
185+
noAnyExpand: PropTypes.bool,
186+
expandAll: PropTypes.bool,
187+
toggleExpandAllChilds: PropTypes.func
188188
};
189189

190190
export default TableHeader;

0 commit comments

Comments
 (0)