Skip to content

Commit 5999c48

Browse files
committed
fix #1451
1 parent 59678fa commit 5999c48

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/BootstrapTable.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ class BootstrapTable extends Component {
441441
expandParentClass={ this.props.options.expandParentClass }
442442
columns={ columns }
443443
trClassName={ this.props.trClassName }
444+
trStyle={ this.props.trStyle }
444445
striped={ this.props.striped }
445446
bordered={ this.props.bordered }
446447
hover={ this.props.hover }
@@ -1478,6 +1479,7 @@ BootstrapTable.propTypes = {
14781479
strictSearch: PropTypes.bool,
14791480
columnFilter: PropTypes.bool,
14801481
trClassName: PropTypes.any,
1482+
trStyle: PropTypes.any,
14811483
tableStyle: PropTypes.object,
14821484
containerStyle: PropTypes.object,
14831485
headerStyle: PropTypes.object,
@@ -1640,6 +1642,7 @@ BootstrapTable.defaultProps = {
16401642
multiColumnSort: 1,
16411643
columnFilter: false,
16421644
trClassName: '',
1645+
trStyle: undefined,
16431646
tableStyle: undefined,
16441647
containerStyle: undefined,
16451648
headerStyle: undefined,

src/TableBody.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TableBody extends Component {
1616
}
1717

1818
render() {
19-
const { cellEdit, beforeShowError, x, y, keyBoardNav } = this.props;
19+
const { cellEdit, beforeShowError, x, y, keyBoardNav, trStyle } = this.props;
2020
const tableClasses = classSet('table', {
2121
'table-striped': this.props.striped,
2222
'table-bordered': this.props.bordered,
@@ -168,7 +168,8 @@ class TableBody extends Component {
168168
onRowMouseOut={ this.handleRowMouseOut }
169169
onSelectRow={ this.handleSelectRow }
170170
onExpandRow={ this.handleClickCell }
171-
unselectableRow={ disable }>
171+
unselectableRow={ disable }
172+
style={ trStyle }>
172173
{ this.props.expandColumnOptions.expandColumnVisible &&
173174
this.props.expandColumnOptions.expandColumnBeforeSelectColumn &&
174175
expandedRowColumn }
@@ -204,7 +205,7 @@ class TableBody extends Component {
204205
+ ((isSelectRowDefined && !this.props.selectRow.hideSelectColumn) ? 1 : 0)
205206
+ (this.props.expandColumnOptions.expandColumnVisible ? 1 : 0);
206207
tableRows = [
207-
<TableRow key='##table-empty##'>
208+
<TableRow key='##table-empty##' style={ trStyle }>
208209
<td data-toggle='collapse'
209210
colSpan={ colSpan }
210211
className='react-bs-table-no-data'>

src/TableRow.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class TableRow extends Component {
7373

7474
render() {
7575
this.clickNum = 0;
76-
const { selectRow, row, isSelected, className } = this.props;
76+
const { selectRow, row, isSelected, className, index } = this.props;
77+
let { style } = this.props;
7778
let backgroundColor = null;
7879
let selectRowClass = null;
7980

@@ -85,8 +86,17 @@ class TableRow extends Component {
8586
selectRow.className(row, isSelected) : ( isSelected ? selectRow.className : null);
8687
}
8788

89+
if (Utils.isFunction(style)) {
90+
style = style(row, index);
91+
} else {
92+
style = { ...style } || {};
93+
}
94+
// the bgcolor of row selection always overwrite the bgcolor defined by global.
95+
if (style && backgroundColor && isSelected) {
96+
style.backgroundColor = backgroundColor;
97+
}
8898
const trCss = {
89-
style: { backgroundColor },
99+
style: { ...style },
90100
className: classSet(selectRowClass, className)
91101
};
92102

@@ -102,6 +112,7 @@ class TableRow extends Component {
102112
TableRow.propTypes = {
103113
index: PropTypes.number,
104114
row: PropTypes.any,
115+
style: PropTypes.any,
105116
isSelected: PropTypes.bool,
106117
enableCellEdit: PropTypes.bool,
107118
onRowClick: PropTypes.func,

0 commit comments

Comments
 (0)