2015-05-20 11:16:42 +02:00
|
|
|
import React from 'react';
|
2015-05-22 16:51:08 +02:00
|
|
|
import ReactAddons from 'react/addons';
|
2015-05-20 11:16:42 +02:00
|
|
|
|
2015-05-20 14:48:57 +02:00
|
|
|
import TableHeader from './table_header';
|
2015-05-22 16:51:08 +02:00
|
|
|
import TableColumnContentModel from '../../models/table_column_content_model';
|
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-05-22 16:51:08 +02:00
|
|
|
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)),
|
2015-05-22 18:41:15 +02:00
|
|
|
changeOrder: React.PropTypes.func // turn isRequired on again after editions order implemented
|
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() {
|
|
|
|
var that = this;
|
2015-05-26 13:14:35 +02:00
|
|
|
return ReactAddons.Children.map(this.props.children, (child, i) => {
|
|
|
|
return ReactAddons.addons.cloneWithProps(child, {
|
|
|
|
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-05-20 14:48:57 +02:00
|
|
|
if(this.props.itemList && this.props.itemList.length > 0) {
|
|
|
|
return (
|
2015-05-20 17:32:06 +02:00
|
|
|
<div className="ascribe-table">
|
2015-05-26 14:09:15 +02:00
|
|
|
<TableHeader columnList={this.props.columnList}
|
|
|
|
itemList={this.props.itemList}
|
|
|
|
fetchList={this.props.fetchList}
|
|
|
|
changeOrder={this.props.changeOrder}
|
|
|
|
orderAsc={this.props.orderAsc}
|
|
|
|
orderBy={this.props.orderBy} />
|
2015-05-22 16:51:08 +02:00
|
|
|
{this.renderChildren()}
|
2015-05-20 14:48:57 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<p>Loading</p>
|
|
|
|
);
|
|
|
|
}
|
2015-05-20 11:16:42 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-20 12:00:16 +02:00
|
|
|
export default Table;
|