forked from bvaughn/react-virtualized
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlexColumn.js
More file actions
142 lines (120 loc) · 3.68 KB
/
FlexColumn.js
File metadata and controls
142 lines (120 loc) · 3.68 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/** @flow */
import React, { Component, PropTypes } from 'react'
import SortIndicator from './SortIndicator'
/**
* Default cell renderer that displays an attribute as a simple string
* You should override the column's cellRenderer if your data is some other type of object.
*/
export function defaultCellRenderer (
cellData: any,
cellDataKey: string,
rowData: any,
rowIndex: number,
columnData: any
): string {
if (cellData === null || cellData === undefined) {
return ''
} else {
return String(cellData)
}
}
/**
* Default accessor for returning a cell value for a given attribute.
* This function expects to operate on either a vanilla Object or an Immutable Map.
* You should override the column's cellDataGetter if your data is some other type of object.
*/
export function defaultCellDataGetter (
dataKey: string,
rowData: any,
columnData: any
) {
if (rowData.get instanceof Function) {
return rowData.get(dataKey)
} else {
return rowData[dataKey]
}
}
/**
* Default table header renderer.
*/
export function defaultHeaderRenderer ({
columnData,
dataKey,
disableSort,
label,
sortBy,
sortDirection
}) {
const showSortIndicator = sortBy === dataKey
const children = [
<div
className='FlexTable__headerTruncatedText'
key='label'
title={label}
>
{label}
</div>
]
if (showSortIndicator) {
children.push(
<SortIndicator
key='SortIndicator'
sortDirection={sortDirection}
/>
)
}
return children
}
/**
* Describes the header and cell contents of a table column.
*/
export default class Column extends Component {
static defaultProps = {
cellDataGetter: defaultCellDataGetter,
cellRenderer: defaultCellRenderer,
flexGrow: 0,
flexShrink: 1,
headerRenderer: defaultHeaderRenderer
}
static propTypes = {
/** Optional aria-label value to set on the column header */
'aria-label': PropTypes.string,
/** Optional CSS class to apply to cell */
cellClassName: PropTypes.string,
/**
* Callback responsible for returning a cell's data, given its :dataKey
* (dataKey: string, rowData: any): any
*/
cellDataGetter: PropTypes.func,
/**
* Callback responsible for rendering a cell's contents.
* (cellData: any, cellDataKey: string, rowData: any, rowIndex: number, columnData: any): element
*/
cellRenderer: PropTypes.func,
/** Optional additional data passed to this column's :cellDataGetter */
columnData: PropTypes.object,
/** Uniquely identifies the row-data attribute correspnding to this cell */
dataKey: PropTypes.any.isRequired,
/** If sort is enabled for the table at large, disable it for this column */
disableSort: PropTypes.bool,
/** Flex grow style; defaults to 0 */
flexGrow: PropTypes.number,
/** Flex shrink style; defaults to 1 */
flexShrink: PropTypes.number,
/** Optional CSS class to apply to this column's header */
headerClassName: PropTypes.string,
/**
* Optional callback responsible for rendering a column header contents.
* ({ columnData: object, dataKey: string, disableSort: boolean, label: string, sortBy: string, sortDirection: string }): PropTypes.node
*/
headerRenderer: PropTypes.func.isRequired,
/** Header label for this column */
label: PropTypes.string,
/** Maximum width of column; this property will only be used if :flexGrow is > 0. */
maxWidth: PropTypes.number,
/** Minimum width of column. */
minWidth: PropTypes.number,
/** Flex basis (width) for this column; This value can grow or shrink based on :flexGrow and :flexShrink properties. */
width: PropTypes.number.isRequired
}
}