2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-20 11:16:42 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
2015-05-20 14:48:57 +02:00
|
|
|
import TableHeader from './table_header';
|
2015-06-04 13:48:07 +02:00
|
|
|
import { ColumnModel } from './models/table_models';
|
2015-05-21 16:02:42 +02:00
|
|
|
|
2015-05-20 16:44:45 +02:00
|
|
|
|
2015-05-20 11:16:42 +02:00
|
|
|
let Table = React.createClass({
|
2015-05-22 14:15:12 +02:00
|
|
|
|
2015-05-20 14:48:57 +02:00
|
|
|
propTypes: {
|
2015-06-04 13:48:07 +02:00
|
|
|
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(ColumnModel)),
|
2015-06-04 09:16:30 +02:00
|
|
|
changeOrder: React.PropTypes.func,
|
|
|
|
orderBy: React.PropTypes.string,
|
|
|
|
orderAsc: React.PropTypes.bool,
|
2015-06-05 11:06:36 +02:00
|
|
|
className: React.PropTypes.string,
|
2015-06-05 11:32:10 +02:00
|
|
|
children: React.PropTypes.array,
|
2015-06-05 11:06:36 +02:00
|
|
|
itemList: React.PropTypes.array
|
2015-05-20 14:48:57 +02:00
|
|
|
},
|
2015-05-22 14:15:12 +02:00
|
|
|
|
2015-05-22 16:51:08 +02:00
|
|
|
renderChildren() {
|
2016-01-25 14:15:36 +01:00
|
|
|
return React.Children.map(this.props.children, (child, i) => {
|
|
|
|
return React.cloneElement(child, {
|
2015-05-26 13:14:35 +02:00
|
|
|
columnList: this.props.columnList,
|
|
|
|
columnContent: this.props.itemList[i],
|
|
|
|
key: i
|
|
|
|
});
|
2015-05-22 16:51:08 +02:00
|
|
|
});
|
|
|
|
},
|
2015-05-22 18:43:15 +02:00
|
|
|
|
2015-05-22 16:51:08 +02:00
|
|
|
render() {
|
2015-06-01 11:51:03 +02:00
|
|
|
return (
|
2015-06-04 17:21:38 +02:00
|
|
|
<table className={'table ' + this.props.className}>
|
2015-06-05 11:06:36 +02:00
|
|
|
<TableHeader
|
2015-06-04 09:16:30 +02:00
|
|
|
columnList={this.props.columnList}
|
|
|
|
itemList={this.props.itemList}
|
|
|
|
changeOrder={this.props.changeOrder}
|
|
|
|
orderAsc={this.props.orderAsc}
|
2015-06-01 11:51:03 +02:00
|
|
|
orderBy={this.props.orderBy} />
|
2015-06-04 17:21:38 +02:00
|
|
|
<tbody>
|
2015-05-22 16:51:08 +02:00
|
|
|
{this.renderChildren()}
|
2015-06-04 17:21:38 +02:00
|
|
|
</tbody>
|
|
|
|
</table>
|
2015-06-01 11:51:03 +02:00
|
|
|
);
|
2015-05-20 11:16:42 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-20 12:00:16 +02:00
|
|
|
export default Table;
|