2015-05-21 14:03:56 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
2015-05-21 14:51:15 +02:00
|
|
|
import TableHeaderItemCarret from './table_header_item_carret';
|
2015-05-21 14:03:56 +02:00
|
|
|
|
|
|
|
let TableHeaderItem = React.createClass({
|
2015-05-21 14:51:15 +02:00
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
columnClasses: React.PropTypes.string.isRequired,
|
|
|
|
displayName: React.PropTypes.string.isRequired,
|
|
|
|
columnName: React.PropTypes.string.isRequired,
|
2015-05-26 14:05:34 +02:00
|
|
|
canBeOrdered: React.PropTypes.bool,
|
|
|
|
changeOrder: React.PropTypes.func,
|
|
|
|
orderAsc: React.PropTypes.bool,
|
|
|
|
orderBy: React.PropTypes.string
|
2015-05-21 14:51:15 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
changeOrder() {
|
2015-05-22 13:58:09 +02:00
|
|
|
this.props.changeOrder(this.props.columnName, !this.props.orderAsc);
|
2015-05-21 14:51:15 +02:00
|
|
|
},
|
|
|
|
|
2015-05-21 14:03:56 +02:00
|
|
|
render() {
|
2015-05-26 14:05:34 +02:00
|
|
|
if(this.props.canBeOrdered && this.props.changeOrder && this.props.orderAsc != null && this.props.orderBy) {
|
2015-05-21 14:51:15 +02:00
|
|
|
if(this.props.columnName === this.props.orderBy) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={this.props.columnClasses + ' ascribe-table-header-column'}
|
|
|
|
onClick={this.changeOrder}>
|
|
|
|
<span>{this.props.displayName} <TableHeaderItemCarret orderAsc={this.props.orderAsc} /></span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={this.props.columnClasses + ' ascribe-table-header-column'}
|
|
|
|
onClick={this.changeOrder}>
|
|
|
|
<span>{this.props.displayName}</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<div className={this.props.columnClasses + ' ascribe-table-header-column'}>
|
|
|
|
<span>
|
|
|
|
{this.props.displayName}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2015-05-21 14:03:56 +02:00
|
|
|
}
|
|
|
|
});
|
2015-05-21 14:51:15 +02:00
|
|
|
|
|
|
|
export default TableHeaderItem;
|