-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
gridColDef.ts
277 lines (267 loc) · 8.79 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import * as React from 'react';
import { GridCellClassNamePropType } from '../gridCellClass';
import { GridColumnHeaderClassNamePropType } from '../gridColumnHeaderClass';
import { GridFilterOperator } from '../gridFilterOperator';
import {
GridCellParams,
GridRenderCellParams,
GridRenderEditCellParams,
GridValueFormatterParams,
GridValueGetterParams,
GridValueSetterParams,
GridPreProcessEditCellProps,
} from '../params/gridCellParams';
import { GridColumnHeaderParams } from '../params/gridColumnHeaderParams';
import { GridComparatorFn, GridSortDirection } from '../gridSortModel';
import { GridColType, GridNativeColTypes } from './gridColType';
import { GridRowParams } from '../params/gridRowParams';
import { GridValueOptionsParams } from '../params/gridValueOptionsParams';
import { GridActionsCellItemProps } from '../../components/cell/GridActionsCellItem';
import { GridEditCellProps } from '../gridEditRowModel';
import type { GridValidRowModel } from '../gridRows';
/**
* Alignment used in position elements in Cells.
*/
export type GridAlignment = 'left' | 'right' | 'center';
export type ValueOptions = string | number | { value: any; label: string };
/**
* Value that can be used as a key for grouping rows
*/
export type GridKeyValue = string | number | boolean;
/**
* Column Definition interface.
*/
export interface GridColDef<R extends GridValidRowModel = any, V = any, F = V> {
/**
* The column identifier. It's used to map with [[GridRowModel]] 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;
/**
* Sets the maximum width of a column.
* @default Infinity
*/
maxWidth?: number;
/**
* If `true`, hide the column.
* @deprecated Use the `columnVisibility` prop instead.
* @default false
*/
hide?: boolean;
/**
* If `false`, removes the buttons for hiding this column.
* @default true
*/
hideable?: boolean;
/**
* If `true`, the column is sortable.
* @default true
*/
sortable?: boolean;
/**
* The order of the sorting sequence.
*/
sortingOrder?: GridSortDirection[];
/**
* If `true`, the column is resizable.
* @default true
*/
resizable?: boolean;
/**
* If `true`, the cells of the column are editable.
* @default false
*/
editable?: boolean;
/**
* If `true`, the rows can be grouped based on this column values (pro-plan only).
* @default true
*/
groupable?: boolean;
/**
* If `false`, the menu items for column pinning menu will not be rendered.
* Only available in DataGridPro.
* @default true
*/
pinnable?: boolean;
/**
* A comparator function used to sort rows.
*/
sortComparator?: GridComparatorFn<V>;
/**
* 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 (or a function returning an array) of the possible cell values and labels.
*/
valueOptions?: Array<ValueOptions> | ((params: GridValueOptionsParams<R>) => Array<ValueOptions>);
/**
* 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.
* @template R, V
* @param {GridValueGetterParams<any, R>} params Object containing parameters for the getter.
* @returns {V} The cell value.
*/
valueGetter?: (params: GridValueGetterParams<any, R>) => V;
/**
* Function that allows to customize how the entered value is stored in the row.
* It only works with cell/row editing.
* @template R, V
* @param {GridValueSetterParams<R, V>} params Object containing parameters for the setter.
* @returns {R} The row with the updated field.
*/
valueSetter?: (params: GridValueSetterParams<R, V>) => R;
/**
* Function that allows to apply a formatter before rendering its value.
* @template V, F
* @param {GridValueFormatterParams<V>} params Object containing parameters for the formatter.
* @returns {F} The formatted value.
*/
valueFormatter?: (params: GridValueFormatterParams<V>) => F;
/**
* Function that takes the user-entered value and converts it to a value used internally.
* @template R, V, F
* @param {F | undefined} value The user-entered value.
* @param {GridCellParams<V, R, F>} params The params when called before saving the value.
* @returns {V} The converted value to use internally.
*/
valueParser?: (value: F | undefined, params?: GridCellParams<V, R, F>) => V;
/**
* Class name that will be added in cells for that column.
*/
cellClassName?: GridCellClassNamePropType;
/**
* Allows to override the component rendered as cell for this column.
* @template R, V, F
* @param {GridRenderCellParams<V, R, F>} params Object containing parameters for the renderer.
* @returns {React.ReactNode} The element to be rendered.
*/
renderCell?: (params: GridRenderCellParams<V, R, F>) => React.ReactNode;
/**
* Allows to override the component rendered in edit cell mode for this column.
* @param {GridRenderEditCellParams} params Object containing parameters for the renderer.
* @returns {React.ReactNode} The element to be rendered.
*/
renderEditCell?: (params: GridRenderEditCellParams<V>) => React.ReactNode;
/**
* Callback fired when the edit props of the cell changes.
* It allows to process the props that saved into the state.
* @param {GridPreProcessEditCellProps} params Object containing parameters of the cell being edited.
* @returns {GridEditCellProps | Promise<GridEditCellProps>} The new edit cell props.
*/
preProcessEditCellProps?: (
params: GridPreProcessEditCellProps,
) => GridEditCellProps | Promise<GridEditCellProps>;
/**
* Class name that will be added in the column header cell.
*/
headerClassName?: GridColumnHeaderClassNamePropType;
/**
* Allows to render a component in the column header cell.
* @template V, R, F
* @param {GridColumnHeaderParams<V, R, F>} params Object containing parameters for the renderer.
* @returns {React.ReactNode} The element to be rendered.
*/
renderHeader?: (params: GridColumnHeaderParams<V, R, F>) => 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<R, V, F>[];
/**
* 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;
/**
* Number of columns a cell should span.
* @default 1
*/
colSpan?: number | ((params: GridCellParams<V, R, F>) => number | undefined);
}
export interface GridActionsColDef extends GridColDef {
/**
* Type allows to merge this object with a default definition [[GridColDef]].
* @default 'actions'
*/
type: 'actions';
/**
* Function that returns the actions to be shown.
* @param {GridRowParams} params The params for each row.
* @returns {React.ReactElement<GridActionsCellItemProps>[]} An array of [[GridActionsCell]] elements.
*/
getActions: (params: GridRowParams) => React.ReactElement<GridActionsCellItemProps>[];
}
export type GridEnrichedColDef<R extends GridValidRowModel = any, V = any, F = V> =
| GridColDef<R, V, F>
| GridActionsColDef;
export type GridColumns<R extends GridValidRowModel = any> = GridEnrichedColDef<R>[];
export type GridColTypeDef<V = any, F = V> = Omit<GridColDef<V, any, F>, 'field'> & {
extendType?: GridNativeColTypes;
};
export type GridStateColDef<R extends GridValidRowModel = any, V = any, F = V> = GridEnrichedColDef<
R,
V,
F
> & {
computedWidth: number;
/**
* If `true`, it means that at least one of the dimension's property of this column has been modified since the last time the column prop has changed.
*/
hasBeenResized?: boolean;
};
/**
* Meta Info about columns.
*/
export interface GridColumnsMeta {
totalWidth: number;
positions: number[];
}