Skip to content

Commit 53841f3

Browse files
committed
fix #1370
1 parent f6bece0 commit 53841f3

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/BootstrapTable.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ class BootstrapTable extends Component {
418418
expandableRow={ this.props.expandableRow }
419419
expandRowBgColor={ this.props.options.expandRowBgColor }
420420
expandBy={ this.props.options.expandBy || Const.EXPAND_BY_ROW }
421+
expandBodyClass={ this.props.options.expandBodyClass }
422+
expandParentClass={ this.props.options.expandParentClass }
421423
columns={ columns }
422424
trClassName={ this.props.trClassName }
423425
striped={ this.props.striped }
@@ -1479,6 +1481,8 @@ BootstrapTable.propTypes = {
14791481
expanding: PropTypes.array,
14801482
onExpand: PropTypes.func,
14811483
onlyOneExpanding: PropTypes.bool,
1484+
expandBodyClass: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]),
1485+
expandParentClass: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]),
14821486
beforeShowError: PropTypes.func,
14831487
printToolBar: PropTypes.bool
14841488
}),
@@ -1627,6 +1631,8 @@ BootstrapTable.defaultProps = {
16271631
expanding: [],
16281632
onExpand: undefined,
16291633
onlyOneExpanding: false,
1634+
expandBodyClass: null,
1635+
expandParentClass: null,
16301636
beforeShowError: undefined,
16311637
printToolBar: true
16321638
},

src/ExpandComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ExpandComponent extends Component {
1111
style: {
1212
backgroundColor: this.props.bgColor
1313
},
14-
className: classSet(className)
14+
className: this.props.hidden ? null : classSet(className)
1515
};
1616
return (
1717
<tr hidden={ this.props.hidden } width={ this.props.width } { ...trCss }>

src/TableBody.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,19 @@ class TableBody extends Component {
147147
this.props.expanding.indexOf(key) > -1,
148148
ExpandColumnCustomComponent, r, data
149149
);
150+
const haveExpandContent = this.props.expandableRow && this.props.expandableRow(data);
151+
const isExpanding = haveExpandContent && this.props.expanding.indexOf(key) > -1;
152+
150153
// add by bluespring for className customize
151154
let trClassName = this.props.trClassName;
152155
if (isFun(this.props.trClassName)) {
153156
trClassName = this.props.trClassName(data, r);
154157
}
158+
if (isExpanding && this.props.expandParentClass) {
159+
trClassName += isFun(this.props.expandParentClass) ?
160+
this.props.expandParentClass(data, r) :
161+
this.props.expandParentClass;
162+
}
155163
const result = [ <TableRow isSelected={ selected } key={ key } className={ trClassName }
156164
index={ r }
157165
row={ data }
@@ -174,14 +182,17 @@ class TableBody extends Component {
174182
{ tableColumns }
175183
</TableRow> ];
176184

177-
if (this.props.expandableRow && this.props.expandableRow(data)) {
185+
if (haveExpandContent) {
186+
const expandBodyClass = isFun(this.props.expandBodyClass) ?
187+
this.props.expandBodyClass(data, r) :
188+
this.props.expandBodyClass;
178189
result.push(
179190
<ExpandComponent
180191
key={ key + '-expand' }
181192
row={ data }
182-
className={ trClassName }
193+
className={ expandBodyClass }
183194
bgColor={ this.props.expandRowBgColor || this.props.selectRow.bgColor || undefined }
184-
hidden={ !(this.props.expanding.indexOf(key) > -1) }
195+
hidden={ !isExpanding }
185196
colSpan={ expandColSpan }
186197
width={ "100%" }>
187198
{ this.props.expandComponent(data) }
@@ -502,6 +513,8 @@ TableBody.propTypes = {
502513
expandBy: PropTypes.string,
503514
expanding: PropTypes.array,
504515
onExpand: PropTypes.func,
516+
expandBodyClass: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]),
517+
expandParentClass: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]),
505518
onlyOneExpanding: PropTypes.bool,
506519
beforeShowError: PropTypes.func,
507520
keyBoardNav: PropTypes.oneOfType([ PropTypes.bool, PropTypes.object ]),

0 commit comments

Comments
 (0)