diff --git a/README.md b/README.md
index 9067b174e..bb6c0d7ba 100644
--- a/README.md
+++ b/README.md
@@ -122,6 +122,18 @@ React.render(
, mountNode);
|
get row's className |
+
+ | bodyCellClassName |
+ Function(record, index):string |
+ |
+ used to compute a table body cell's className |
+
+
+ | headerCellClassName |
+ Function(headerCellConfig):string |
+ |
+ used to compute a header cell's className based on the config data for that column header. |
+
| rowRef |
Function(record, index, indent):string |
diff --git a/src/Table.jsx b/src/Table.jsx
index ff33276b0..7bac8a7d6 100644
--- a/src/Table.jsx
+++ b/src/Table.jsx
@@ -20,6 +20,8 @@ const Table = React.createClass({
bodyStyle: PropTypes.object,
style: PropTypes.object,
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
+ bodyCellClassName: PropTypes.func,
+ headerCellClassName: PropTypes.func,
rowClassName: PropTypes.func,
expandedRowClassName: PropTypes.func,
childrenColumnName: PropTypes.string,
@@ -47,6 +49,8 @@ const Table = React.createClass({
defaultExpandAllRows: false,
defaultExpandedRowKeys: [],
rowKey: 'key',
+ bodyCellClassName: () => '',
+ headerCellClassName: () => '',
rowClassName: () => '',
expandedRowClassName: () => '',
onExpand() {},
@@ -193,7 +197,7 @@ const Table = React.createClass({
},
getHeader(columns, fixed) {
- const { showHeader, expandIconAsCell, prefixCls } = this.props;
+ const { headerCellClassName, showHeader, expandIconAsCell, prefixCls } = this.props;
const rows = this.getHeaderRows(columns);
if (expandIconAsCell && fixed !== 'right') {
@@ -209,6 +213,7 @@ const Table = React.createClass({
return showHeader ? (
{indentText}
diff --git a/src/TableHeader.jsx b/src/TableHeader.jsx
index 4a6ca8ddb..5ae21e4b2 100644
--- a/src/TableHeader.jsx
+++ b/src/TableHeader.jsx
@@ -6,18 +6,27 @@ export default React.createClass({
prefixCls: PropTypes.string,
rowStyle: PropTypes.object,
rows: PropTypes.array,
+ headerCellClassName: PropTypes.func,
},
shouldComponentUpdate(nextProps) {
return !shallowequal(nextProps, this.props);
},
render() {
- const { prefixCls, rowStyle, rows } = this.props;
+ const { headerCellClassName, prefixCls, rowStyle, rows } = this.props;
return (
{
rows.map((row, index) => (
- {row.map((cellProps, i) => | )}
+ {
+ row.map((cellProps, i) => {
+ const thClassName = headerCellClassName(cellProps);
+ let className = cellProps.className;
+ className = thClassName ? `${className} ${thClassName}`.trim() : className;
+ cellProps.className = className;
+ return ;
+ })
+ }
|
))
}
diff --git a/src/TableRow.jsx b/src/TableRow.jsx
index 4473a65f6..17eb87d39 100644
--- a/src/TableRow.jsx
+++ b/src/TableRow.jsx
@@ -23,6 +23,7 @@ const TableRow = React.createClass({
expandable: PropTypes.any,
onExpand: PropTypes.func,
needIndentSpaced: PropTypes.bool,
+ bodyCellClassName: PropTypes.func,
className: PropTypes.string,
indent: PropTypes.number,
indentSize: PropTypes.number,
@@ -36,6 +37,7 @@ const TableRow = React.createClass({
onRowClick() {},
onRowDoubleClick() {},
onDestroy() {},
+ bodyCellClassName: () => {},
expandIconColumnIndex: 0,
expandRowByClick: false,
onHover() {},
@@ -100,7 +102,7 @@ const TableRow = React.createClass({
render() {
const {
- prefixCls, columns, record, height, visible, index,
+ prefixCls, columns, bodyCellClassName, record, height, visible, index,
expandIconColumnIndex, expandIconAsCell, expanded, expandRowByClick,
expandable, onExpand, needIndentSpaced, indent, indentSize,
} = this.props;
@@ -125,10 +127,11 @@ const TableRow = React.createClass({
);
for (let i = 0; i < columns.length; i++) {
+ const tdClassName = bodyCellClassName(record, index);
if (expandIconAsCell && i === 0) {
cells.push(
{expandIcon}
@@ -140,6 +143,7 @@ const TableRow = React.createClass({
cells.push(
|