Skip to content

Commit 136dec9

Browse files
committed
fix #1108
1 parent 87158e0 commit 136dec9

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/BootstrapTable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ BootstrapTable.propTypes = {
12701270
Const.ROW_SELECT_MULTI
12711271
]),
12721272
customComponent: PropTypes.func,
1273-
bgColor: PropTypes.string,
1273+
bgColor: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]),
12741274
selected: PropTypes.array,
12751275
onSelect: PropTypes.func,
12761276
onSelectAll: PropTypes.func,

src/TableBody.js

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class TableBody extends Component {
153153
}
154154
const result = [ <TableRow isSelected={ selected } key={ key } className={ trClassName }
155155
index={ r }
156+
row={ data }
156157
selectRow={ isSelectRowDefined ? this.props.selectRow : undefined }
157158
enableCellEdit={ cellEdit.mode !== Const.CELL_EDIT_NONE }
158159
onRowClick={ this.handleRowClick }

src/TableRow.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint no-nested-ternary: 0 */
12
import classSet from 'classnames';
23
import React, { Component, PropTypes } from 'react';
34

@@ -71,12 +72,18 @@ class TableRow extends Component {
7172

7273
render() {
7374
this.clickNum = 0;
75+
const { selectRow, row, isSelected } = this.props;
76+
let backgroundColor = null;
77+
78+
if (selectRow) {
79+
backgroundColor = typeof selectRow.bgColor === 'function' ?
80+
selectRow.bgColor(row, isSelected) : ( isSelected ? selectRow.bgColor : null);
81+
}
82+
7483
const trCss = {
75-
style: {
76-
backgroundColor: this.props.isSelected ? this.props.selectRow.bgColor : null
77-
},
84+
style: { backgroundColor },
7885
className: classSet(
79-
this.props.isSelected ? this.props.selectRow.className : null,
86+
isSelected ? selectRow.className : null,
8087
this.props.className
8188
)
8289
};
@@ -92,6 +99,7 @@ class TableRow extends Component {
9299
}
93100
TableRow.propTypes = {
94101
index: PropTypes.number,
102+
row: PropTypes.any,
95103
isSelected: PropTypes.bool,
96104
enableCellEdit: PropTypes.bool,
97105
onRowClick: PropTypes.func,

0 commit comments

Comments
 (0)