-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableHeader.js
More file actions
59 lines (48 loc) · 1.3 KB
/
TableHeader.js
File metadata and controls
59 lines (48 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict'
import { Component, PropTypes } from 'react'
import classnames from 'classnames'
class TableHeader extends Component {
static displayName = 'TableHeader'
static propTypes = {
content: PropTypes.any,
header: PropTypes.any,
hidden: PropTypes.bool,
name: PropTypes.string.isRequired,
onSort: PropTypes.func,
sort: PropTypes.object,
sortAble: PropTypes.bool,
width: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string
])
}
static defaultProps = {
hidden: false
}
state = {
asc: 0
}
onSort () {
let asc = this.state.asc === 0 ? 1 : 0
this.setState({ asc })
this.props.onSort(this.props.name, asc)
}
render () {
let sort = [],
onSort = null,
style = {}
if (this.props.sortAble) {
sort.push(<i key="up" className={classnames("arrow-up", {active: this.props.name === this.props.sort.name && this.state.asc === 1})} />)
sort.push(<i key="down" className={classnames("arrow-down", {active: this.props.name === this.props.sort.name && this.state.asc === 0})} />)
onSort = this.onSort.bind(this)
style = { cursor: 'pointer' }
}
return (
<th style={style} onClick={onSort}>
{this.props.header}
{sort}
</th>
)
}
}
export default TableHeader