-
Notifications
You must be signed in to change notification settings - Fork 430
Expand file tree
/
Copy pathheader.js
More file actions
123 lines (109 loc) · 3.23 KB
/
header.js
File metadata and controls
123 lines (109 loc) · 3.23 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* eslint react/require-default-props: 0 */
import React from 'react';
import PropTypes from 'prop-types';
import HeaderCell from './header-cell';
import SelectionHeaderCell from './row-selection/selection-header-cell';
import ExpandHeaderCell from './row-expand/expand-header-cell';
import withHeaderSelection from './row-selection/selection-header-cell-consumer';
import withHeaderExpansion from './row-expand/expand-header-cell-consumer';
import Const from './const';
const Header = (props) => {
const {
className,
columns,
onSort,
onFilter,
sortField,
sortOrder,
selectRow,
expandRow,
currFilters,
onExternalFilter,
filterPosition,
globalSortCaret,
wrapperClasses,
preHeaderRow,
postHeaderRow
} = props;
let SelectionHeaderCellComp = () => null;
let ExpansionHeaderCellComp = () => null;
if (expandRow.showExpandColumn) {
ExpansionHeaderCellComp = withHeaderExpansion(ExpandHeaderCell);
}
if (selectRow) {
SelectionHeaderCellComp = withHeaderSelection(SelectionHeaderCell);
}
const isRenderFunctionColumnInLeft = (
position = Const.INDICATOR_POSITION_LEFT
) => position === Const.INDICATOR_POSITION_LEFT;
const childrens = [
columns.map((column, i) => {
const currSort = column.dataField === sortField;
const isLastSorting = column.dataField === sortField;
return (
<HeaderCell
index={ i }
key={ column.dataField }
column={ column }
onSort={ onSort }
sorting={ currSort }
sortOrder={ sortOrder }
globalSortCaret={ globalSortCaret }
isLastSorting={ isLastSorting }
onFilter={ onFilter }
currFilters={ currFilters }
onExternalFilter={ onExternalFilter }
filterPosition={ filterPosition }
/>);
})
];
if (!selectRow.hideSelectColumn) {
if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
childrens.unshift(<SelectionHeaderCellComp key="selection" />);
} else {
childrens.push(<SelectionHeaderCellComp key="selection" />);
}
}
if (expandRow.showExpandColumn) {
if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
childrens.unshift(<ExpansionHeaderCellComp key="expansion" />);
} else {
childrens.push(<ExpansionHeaderCellComp key="expansion" />);
}
}
return (
<thead className={ wrapperClasses }>
{preHeaderRow}
<tr className={ className }>
{ childrens }
</tr>
{postHeaderRow}
</thead>
);
};
Header.propTypes = {
columns: PropTypes.array.isRequired,
onSort: PropTypes.func,
onFilter: PropTypes.func,
sortField: PropTypes.string,
sortOrder: PropTypes.string,
selectRow: PropTypes.object,
currFilters: PropTypes.object,
onExternalFilter: PropTypes.func,
globalSortCaret: PropTypes.func,
className: PropTypes.string,
wrapperClasses: PropTypes.string,
expandRow: PropTypes.object,
filterPosition: PropTypes.oneOf([
Const.FILTERS_POSITION_TOP,
Const.FILTERS_POSITION_INLINE,
Const.FILTERS_POSITION_BOTTOM
]),
preHeaderRow: PropTypes.node,
postHeaderRow: PropTypes.node
};
Header.defaultProps = {
preHeaderRow: null,
postHeaderRow: null
};
export default Header;