diff --git a/assets/index.less b/assets/index.less index d9c10fe5b..0d3ca1c73 100644 --- a/assets/index.less +++ b/assets/index.less @@ -38,6 +38,15 @@ box-sizing: border-box; } + .@{tablePrefixCls}-title { + padding: 16px 8px; + border-top: 1px solid #e9e9e9; + } + + .@{tablePrefixCls}-content { + position: relative; + } + .@{tablePrefixCls}-footer { padding: 16px 8px; border-bottom: 1px solid #e9e9e9; diff --git a/examples/title.html b/examples/title.html new file mode 100644 index 000000000..e69de29bb diff --git a/examples/title.js b/examples/title.js new file mode 100644 index 000000000..27c728966 --- /dev/null +++ b/examples/title.js @@ -0,0 +1,32 @@ +/* eslint-disable no-console,func-names,react/no-multi-comp */ +const React = require('react'); +const ReactDOM = require('react-dom'); +const Table = require('rc-table'); +require('rc-table/assets/index.less'); + +const columns = [ + {title: '表头1', dataIndex: 'a', key: 'a', width: 100}, + {id: '123', title: '表头2', dataIndex: 'b', key: 'b', width: 100}, + {title: '表头3', dataIndex: 'c', key: 'c', width: 200}, + { + title: '操作', dataIndex: '', key: 'd', render: function() { + return 操作; + }, + }, +]; + +const data = [{a: '123', key: '1'}, {a: 'cdd', b: 'edd', key: '2'}, {a: '1333', c: 'eee', d: 2, key: '3'}]; + +const title = (currentData) => { + return
Title: {currentData.length} items
; +}; + +ReactDOM.render( +
+

simple table

+ + , + document.getElementById('__react-content') +); diff --git a/src/Table.jsx b/src/Table.jsx index 1d5cd64a8..af5a57b81 100644 --- a/src/Table.jsx +++ b/src/Table.jsx @@ -28,6 +28,7 @@ const Table = React.createClass({ columnsPageSize: PropTypes.number, expandIconColumnIndex: PropTypes.number, showHeader: PropTypes.bool, + title: PropTypes.func, footer: PropTypes.func, scroll: PropTypes.object, rowRef: PropTypes.func, @@ -464,6 +465,15 @@ const Table = React.createClass({ return {headTable}{BodyTable}; }, + getTitle() { + const { title, prefixCls } = this.props; + return title ? ( +
+ {title(this.state.data)} +
+ ) : null; + }, + getFooter() { const { footer, prefixCls } = this.props; return footer ? ( @@ -656,18 +666,21 @@ const Table = React.createClass({ return (
- {this.isAnyColumnsLeftFixed() && -
- {this.getLeftFixedTable()} -
} -
- {this.getTable()} - {this.getFooter()} + {this.getTitle()} +
+ {this.isAnyColumnsLeftFixed() && +
+ {this.getLeftFixedTable()} +
} +
+ {this.getTable()} + {this.getFooter()} +
+ {this.isAnyColumnsRightFixed() && +
+ {this.getRightFixedTable()} +
}
- {this.isAnyColumnsRightFixed() && -
- {this.getRightFixedTable()} -
}
); },