-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
gridColDef.ts
188 lines (180 loc) · 5.19 KB
/
gridColDef.ts
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import * as React from 'react';
import { GridCellValue } from '../gridCell';
import { GridCellClassNamePropType } from '../gridCellClass';
import { GridColumnHeaderClassNamePropType } from '../gridColumnHeaderClass';
import { GridFilterOperator } from '../gridFilterOperator';
import {
GridCellParams,
GridValueFormatterParams,
GridValueGetterParams,
} from '../params/gridCellParams';
import { GridColumnHeaderParams } from '../params/gridColumnHeaderParams';
import { GridComparatorFn } from '../gridSortModel';
import { GridColType, GridNativeColTypes } from './gridColType';
/**
* Alignment used in position elements in Cells.
*/
export type GridAlignment = 'left' | 'right' | 'center';
/**
* Column Definition interface.
*/
export interface GridColDef {
/**
* The column identifier. It's used to map with [[GridRowData]] values.
*/
field: string;
/**
* The title of the column rendered in the column header cell.
*/
headerName?: string;
/**
* The description of the column rendered as tooltip if the column header name is not fully displayed.
*/
description?: string;
/**
* Set the width of the column.
* @default 100
*/
width?: number;
/**
* If set, it indicates that a column has fluid width. Range [0, ∞).
*/
flex?: number;
/**
* Sets the minimum width of a column.
* @default 50
*/
minWidth?: number;
/**
* If `true`, hide the column.
* @default false
*/
hide?: boolean;
/**
* If `true`, the column is sortable.
* @default true
*/
sortable?: boolean;
/**
* If `true`, the column is resizable.
* @default true
*/
resizable?: boolean;
/**
* If `true`, the cells of the column are editable.
* @default false
*/
editable?: boolean;
/**
* A comparator function used to sort rows.
*/
sortComparator?: GridComparatorFn;
/**
* Type allows to merge this object with a default definition [[GridColDef]].
* @default 'string'
*/
type?: GridColType;
/**
* To be used in combination with `type: 'singleSelect'`. This is an array of the possible cell values and labels.
*/
valueOptions?: Array<string | number | { value: any; label: string }>;
/**
* Allows to align the column values in cells.
*/
align?: GridAlignment;
/**
* Function that allows to get a specific data instead of field to render in the cell.
* @param params
*/
valueGetter?: (params: GridValueGetterParams) => GridCellValue;
/**
* Function that allows to apply a formatter before rendering its value.
* @param {GridValueFormatterParams} params Object containing parameters for the formatter.
* @returns {GridCellValue} The formatted value.
*/
valueFormatter?: (params: GridValueFormatterParams) => GridCellValue;
/**
* Function that takes the user-entered value and converts it to a value used internally.
* @param {GridCellValue} value The user-entered value.
* @param {GridCellParams} params The params when called before saving the value.
* @returns {GridCellValue} The converted value to use internally.
*/
valueParser?: (value: GridCellValue, params?: GridCellParams) => GridCellValue;
/**
* Class name that will be added in cells for that column.
*/
cellClassName?: GridCellClassNamePropType;
/**
* Allows to override the component rendered as cell for this column.
* @param params
*/
renderCell?: (params: GridCellParams) => React.ReactNode;
/**
* Allows to override the component rendered in edit cell mode for this column.
* @param params
*/
renderEditCell?: (params: GridCellParams) => React.ReactNode;
/**
* Class name that will be added in the column header cell.
*/
headerClassName?: GridColumnHeaderClassNamePropType;
/**
* Allows to render a component in the column header cell.
* @param params
*/
renderHeader?: (params: GridColumnHeaderParams) => React.ReactNode;
/**
* Header cell element alignment.
*/
headerAlign?: GridAlignment;
/**
* Toggle the visibility of the sort icons.
* @default false
*/
hideSortIcons?: boolean;
/**
* If `true`, the column menu is disabled for this column.
* @default false
*/
disableColumnMenu?: boolean;
/**
* If `true`, the column is filterable.
* @default true
*/
filterable?: boolean;
/**
* Allows setting the filter operators for this column.
*/
filterOperators?: GridFilterOperator[];
/**
* If `true`, this column cannot be reordered.
* @default false
*/
disableReorder?: boolean;
/**
* If `true`, this column will not be included in exports.
* @default false
*/
disableExport?: boolean;
}
export interface GridColumnProp extends Omit<GridColDef, 'filterOperators'> {
filterOperators?: GridFilterOperator[] | string;
}
export type GridColumns = GridColDef[];
export type GridColTypeDef = Omit<GridColDef, 'field'> & { extendType?: GridNativeColTypes };
/**
* Meta Info about columns.
*/
export interface GridColumnsMeta {
totalWidth: number;
positions: number[];
}
export type GridColumnLookup = { [field: string]: GridColDef };
export interface GridInternalColumns {
all: string[];
lookup: GridColumnLookup;
}
export const getInitialGridColumnsState = (): GridInternalColumns => ({
all: [],
lookup: {},
});