-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtable-heading.js
More file actions
75 lines (63 loc) · 2.28 KB
/
table-heading.js
File metadata and controls
75 lines (63 loc) · 2.28 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react';
import ColumnHelper from './utils/column-helper';
import { getStyleProperties } from './utils/styleHelper';
class TableHeading extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {};
}
shouldComponentUpdate(nextProps) {
//TODO: Verify that this is correct
return this.props.columns !== nextProps.columns;
}
getColumnTitle(column) {
const { columnTitles, renderProperties } = this.props;
const { columnProperties } = renderProperties;
const initial = columnTitles[column] || column;
if(columnProperties[column] && columnProperties[column].hasOwnProperty('displayName')) {
return columnProperties[column];
}
return initial;
}
render() {
let { headingClick, headingHover } = this.props.events;
const { TableHeadingCell, renderProperties, columns, pageProperties } = this.props;
const { columnProperties, ignoredColumns } = renderProperties;
const { style, className } = getStyleProperties(this.props, 'tableHeading');
const headings = columns.map(column => {
let columnProperty = ColumnHelper.getColumnPropertyObject(columnProperties, column);
const showColumn = ColumnHelper.isColumnVisible(column, {
columnProperties: columnProperties,
ignoredColumns: ignoredColumns
});
const sortAscending = pageProperties && pageProperties.sortAscending;
const sorted = pageProperties && pageProperties.sortColumns.indexOf(column) > -1;
const title = this.getColumnTitle(column);
let component = null;
if(showColumn) {
component = (<TableHeadingCell
key={column}
column={column}
sorted={sorted}
sortAscending={sortAscending}
settings={this.props.settings}
styles={this.props.styles}
headingClick={headingClick}
headingHover={headingHover}
icons={this.props.styles.icons}
title={title}
{...columnProperty}
{...this.props}/>);
}
return component;
});
return this.props.columns.length > 0 ? (
<thead style={style} className={className}>
<tr>
{headings}
</tr>
</thead>
) : null;
}
}
export default TableHeading;