Skip to content

Commit 7432902

Browse files
committed
Merge branch 'master' of https://github.com/RxNT/react-bootstrap-table into RxNT-master
2 parents 5b56791 + 061ffa5 commit 7432902

File tree

5 files changed

+109
-12
lines changed

5 files changed

+109
-12
lines changed

css/react-bootstrap-table.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ td.react-bs-table-expand-cell {
261261
cursor: pointer;
262262
}
263263

264+
th.react-bs-table-expand-cell > div {
265+
cursor: pointer;
266+
}
267+
268+
264269
@keyframes shake {
265270
from, to {
266271
transform: translate3d(0, 0, 0);

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,20 @@ export default class ExpandRow extends React.Component {
8181
);
8282
}
8383

84+
expandedColumnHeaderComponent({ expandAllChilds }) {
85+
const content = (expandAllChilds ? '(-)' : '(+)' );
86+
return (
87+
<div>
88+
{ content }
89+
</div>
90+
);
91+
}
92+
8493
render() {
8594
const options = {
86-
expandRowBgColor: 'rgb(242, 255, 163)'
95+
expandRowBgColor: 'rgb(242, 255, 163)',
96+
expandAllChilds: false,
97+
showExpandAllHeaderColumn: true
8798
};
8899
return (
89100
<BootstrapTable data={ products }
@@ -93,7 +104,8 @@ export default class ExpandRow extends React.Component {
93104
expandColumnOptions={ {
94105
expandColumnVisible: true,
95106
expandColumnComponent: this.expandColumnComponent,
96-
columnWidth: 50
107+
columnWidth: 50,
108+
expandedColumnHeaderComponent: this.expandedColumnHeaderComponent
97109
} }
98110
search>
99111
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>

src/BootstrapTable.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,24 @@ class BootstrapTable extends Component {
4444
this._adjustHeaderWidth = this._adjustHeaderWidth.bind(this);
4545
this._adjustHeight = this._adjustHeight.bind(this);
4646
this._adjustTable = this._adjustTable.bind(this);
47+
this.toggleExpandAllChilds = this.toggleExpandAllChilds.bind(this);
48+
49+
let expandedKeys = [];
50+
if (this.props.options.expandAllChilds !== null &&
51+
this.props.options.expandAllChilds !== undefined && this.props.options.expandAllChilds) {
52+
expandedKeys = this.store.getAllRowkey();
53+
} else if (this.props.options.expanding !== undefined && this.props.options.expanding !== null) {
54+
expandedKeys = this.props.options.expanding;
55+
}
4756

4857
this.state = {
4958
data: this.getTableData(),
5059
currPage: currPage,
51-
expanding: this.props.options.expanding || [],
60+
expanding: expandedKeys,
5261
sizePerPage: this.props.options.sizePerPage || Const.SIZE_PER_PAGE_LIST[0],
5362
selectedRowKeys: this.store.getSelectedRowKeys(),
5463
reset: false,
64+
expandAllChilds: this.props.options.expandAllChilds,
5565
x: this.props.keyBoardNav ? 0 : -1,
5666
y: this.props.keyBoardNav ? 0 : -1
5767
};
@@ -477,6 +487,10 @@ class BootstrapTable extends Component {
477487
reset={ this.state.reset }
478488
expandColumnVisible={ expandColumnOptions.expandColumnVisible }
479489
expandColumnComponent={ expandColumnOptions.expandColumnComponent }
490+
expandedColumnHeaderComponent={ expandColumnOptions.expandedColumnHeaderComponent }
491+
expandAllChilds={ this.state.expandAllChilds }
492+
toggleExpandAllChilds={ this.toggleExpandAllChilds }
493+
showExpandAllHeaderColumn={ this.props.options.showExpandAllHeaderColumn }
480494
expandColumnBeforeSelectColumn={ expandColumnOptions.expandColumnBeforeSelectColumn }>
481495
{ this.props.children }
482496
</TableHeader>
@@ -627,6 +641,28 @@ class BootstrapTable extends Component {
627641
});
628642
}
629643

644+
toggleExpandAllChilds() {
645+
const { expandAllChilds } = this.state;
646+
const compScope = this;
647+
if (expandAllChilds) {
648+
this.setState(() => {
649+
return {
650+
expanding: [],
651+
expandAllChilds: !expandAllChilds,
652+
reset: false
653+
};
654+
});
655+
} else {
656+
this.setState(() => {
657+
return {
658+
expanding: compScope.store.getAllRowkey(),
659+
expandAllChilds: !expandAllChilds,
660+
reset: false
661+
};
662+
});
663+
}
664+
}
665+
630666
handlePaginationData = (page, sizePerPage) => {
631667
const { onPageChange, pageStartIndex } = this.props.options;
632668
const emptyTable = this.store.isEmpty();
@@ -1704,7 +1740,9 @@ BootstrapTable.propTypes = {
17041740
beforeShowError: PropTypes.func,
17051741
printToolBar: PropTypes.bool,
17061742
insertFailIndicator: PropTypes.string,
1707-
noAutoBOM: PropTypes.bool
1743+
noAutoBOM: PropTypes.bool,
1744+
expandAllChilds: PropTypes.bool,
1745+
showExpandAllHeaderColumn: PropTypes.bool
17081746
}),
17091747
fetchInfo: PropTypes.shape({
17101748
dataTotalSize: PropTypes.number
@@ -1724,6 +1762,7 @@ BootstrapTable.propTypes = {
17241762
columnWidth: PropTypes.oneOfType([ PropTypes.number, PropTypes.string ]),
17251763
expandColumnVisible: PropTypes.bool,
17261764
expandColumnComponent: PropTypes.func,
1765+
expandedColumnHeaderComponent: PropTypes.func,
17271766
expandColumnBeforeSelectColumn: PropTypes.bool
17281767
}),
17291768
footer: PropTypes.bool
@@ -1737,6 +1776,7 @@ BootstrapTable.defaultProps = {
17371776
expandColumnOptions: {
17381777
expandColumnVisible: false,
17391778
expandColumnComponent: undefined,
1779+
expandedColumnHeaderComponent: undefined,
17401780
expandColumnBeforeSelectColumn: true
17411781
},
17421782
height: '100%',
@@ -1872,7 +1912,9 @@ BootstrapTable.defaultProps = {
18721912
beforeShowError: undefined,
18731913
printToolBar: true,
18741914
insertFailIndicator: Const.INSERT_FAIL_INDICATOR,
1875-
noAutoBOM: true
1915+
noAutoBOM: true,
1916+
expandAllChilds: false,
1917+
showExpandAllHeaderColumn: false
18761918
},
18771919
fetchInfo: {
18781920
dataTotalSize: 0

src/ExpandRowHeaderColumn.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,42 @@ import PropTypes from 'prop-types';
33

44
class ExpandRowHeaderColumn extends Component {
55

6+
constructor(props) {
7+
super(props);
8+
this.toggleExpandAllChilds = this.toggleExpandAllChilds.bind(this);
9+
}
10+
11+
toggleExpandAllChilds() {
12+
this.props.toggleExpandAllChilds();
13+
}
14+
615
render() {
16+
const {
17+
expandedColumnHeaderComponent,
18+
expandAllChilds,
19+
showExpandAllHeaderColumn
20+
} = this.props;
21+
const expandedHeaderComponent = (expandAllChilds ? '(-)' : '(+)' );
22+
const ExpandedColumnHeaderComponent = expandedColumnHeaderComponent;
23+
724
return (
825
<th rowSpan={ this.props.rowCount } style={ { textAlign: 'center' } }
926
className='react-bs-table-expand-cell'
1027
data-is-only-head={ false }>
11-
{ this.props.children }
28+
{ showExpandAllHeaderColumn && <div onClick={ this.toggleExpandAllChilds }>
29+
{ expandedColumnHeaderComponent ?
30+
<ExpandedColumnHeaderComponent
31+
expandAllChilds={ this.props.expandAllChilds } /> : expandedHeaderComponent }
32+
</div> }
1233
</th>
1334
);
1435
}
1536
}
1637
ExpandRowHeaderColumn.propTypes = {
17-
children: PropTypes.node,
18-
rowCount: PropTypes.number
38+
expandedColumnHeaderComponent: PropTypes.func,
39+
rowCount: PropTypes.number,
40+
expandAllChilds: PropTypes.bool,
41+
toggleExpandAllChilds: PropTypes.func,
42+
showExpandAllHeaderColumn: PropTypes.bool
1943
};
2044
export default ExpandRowHeaderColumn;

src/TableHeader.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ function getSortOrder(sortList, field, enableSort) {
3838
class TableHeader extends Component {
3939

4040
render() {
41-
const { sortIndicator, sortList, onSort, reset, version, condensed, bordered } = this.props;
41+
const { sortIndicator, sortList, onSort, reset, version, condensed, bordered,
42+
expandedColumnHeaderComponent, expandAllChilds, toggleExpandAllChilds,
43+
showExpandAllHeaderColumn } = this.props;
4244
const containerClasses = classSet(
4345
'react-bs-container-header',
4446
'table-header-wrapper',
@@ -64,13 +66,21 @@ class TableHeader extends Component {
6466
rows[0].push( [
6567
this.props.expandColumnVisible &&
6668
this.props.expandColumnBeforeSelectColumn &&
67-
<ExpandRowHeaderColumn key='expandCol' rowCount={ rowCount + 1 }/>
69+
<ExpandRowHeaderColumn key='expandCol' rowCount={ rowCount + 1 }
70+
expandedColumnHeaderComponent={ expandedColumnHeaderComponent }
71+
expandAllChilds={ expandAllChilds }
72+
toggleExpandAllChilds={ toggleExpandAllChilds }
73+
showExpandAllHeaderColumn={ showExpandAllHeaderColumn }/>
6874
], [
6975
this.renderSelectRowHeader(rowCount + 1, rowKey++)
7076
], [
7177
this.props.expandColumnVisible &&
7278
!this.props.expandColumnBeforeSelectColumn &&
73-
<ExpandRowHeaderColumn key='expandCol' rowCount={ rowCount + 1 }/>
79+
<ExpandRowHeaderColumn key='expandCol' rowCount={ rowCount + 1 }
80+
expandedColumnHeaderComponent={ expandedColumnHeaderComponent }
81+
expandAllChilds={ expandAllChilds }
82+
toggleExpandAllChilds={ toggleExpandAllChilds }
83+
showExpandAllHeaderColumn={ showExpandAllHeaderColumn }/>
7484
]);
7585

7686
React.Children.forEach(this.props.children, (elm) => {
@@ -169,8 +179,12 @@ TableHeader.propTypes = {
169179
reset: PropTypes.bool,
170180
expandColumnVisible: PropTypes.bool,
171181
expandColumnComponent: PropTypes.func,
182+
expandedColumnHeaderComponent: PropTypes.func,
172183
expandColumnBeforeSelectColumn: PropTypes.bool,
173-
version: PropTypes.string
184+
version: PropTypes.string,
185+
expandAllChilds: PropTypes.bool,
186+
toggleExpandAllChilds: PropTypes.func,
187+
showExpandAllHeaderColumn: PropTypes.bool
174188
};
175189

176190
export default TableHeader;

0 commit comments

Comments
 (0)