2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
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,
|
2015-06-04 10:11:18 +02:00
|
|
|
displayName: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.string,
|
|
|
|
React.PropTypes.element
|
|
|
|
]).isRequired,
|
2015-05-21 14:51:15 +02:00
|
|
|
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,
|
2015-07-01 10:53:40 +02:00
|
|
|
orderBy: React.PropTypes.string,
|
|
|
|
className: 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 (
|
2015-06-05 11:06:36 +02:00
|
|
|
<th
|
2015-07-01 10:53:40 +02:00
|
|
|
className={'ascribe-table-header-column ' + this.props.className}
|
2015-05-21 14:51:15 +02:00
|
|
|
onClick={this.changeOrder}>
|
|
|
|
<span>{this.props.displayName} <TableHeaderItemCarret orderAsc={this.props.orderAsc} /></span>
|
2015-06-04 17:21:38 +02:00
|
|
|
</th>
|
2015-05-21 14:51:15 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
2015-06-05 11:06:36 +02:00
|
|
|
<th
|
2015-07-01 10:53:40 +02:00
|
|
|
className={'ascribe-table-header-column ' + this.props.className}
|
2015-05-21 14:51:15 +02:00
|
|
|
onClick={this.changeOrder}>
|
|
|
|
<span>{this.props.displayName}</span>
|
2015-06-04 17:21:38 +02:00
|
|
|
</th>
|
2015-05-21 14:51:15 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return (
|
2015-07-01 10:53:40 +02:00
|
|
|
<th className={'ascribe-table-header-column ' + this.props.className}>
|
2015-05-21 14:51:15 +02:00
|
|
|
<span>
|
|
|
|
{this.props.displayName}
|
|
|
|
</span>
|
2015-06-04 17:21:38 +02:00
|
|
|
</th>
|
2015-05-21 14:51:15 +02:00
|
|
|
);
|
|
|
|
}
|
2015-05-21 14:03:56 +02:00
|
|
|
}
|
|
|
|
});
|
2015-05-21 14:51:15 +02:00
|
|
|
|
|
|
|
export default TableHeaderItem;
|