es-grid-template 1.9.59 → 1.9.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/ali-table/ColumnsConfig.d.ts +14 -0
- package/es/ali-table/ColumnsConfig.js +303 -0
- package/es/ali-table/Grid.js +110 -31
- package/es/ali-table/InternalTable.js +1208 -18
- package/es/ali-table/assets/WebsiteBaseTable.js +7 -3
- package/es/ali-table/base-table/calculations.js +23 -22
- package/es/ali-table/base-table/cell/EditCell.d.ts +27 -0
- package/es/ali-table/base-table/cell/EditCell.js +1252 -0
- package/es/ali-table/base-table/cell/HeaderEditCell.d.ts +28 -0
- package/es/ali-table/base-table/cell/HeaderEditCell.js +1252 -0
- package/es/ali-table/base-table/header.js +3 -1
- package/es/ali-table/base-table/html-table.d.ts +4 -4
- package/es/ali-table/base-table/html-table.js +5 -289
- package/es/ali-table/base-table/styles.d.ts +2 -1
- package/es/ali-table/base-table/styles.js +8 -8
- package/es/ali-table/base-table/styles.scss +0 -34
- package/es/ali-table/base-table/table.d.ts +13 -10
- package/es/ali-table/base-table/table.js +23 -45
- package/es/ali-table/base-table/utils.d.ts +4 -7
- package/es/ali-table/base-table/utils.js +5 -8
- package/es/ali-table/interfaces.d.ts +10 -5
- package/es/ali-table/pipeline/features/columnCustom.d.ts +15 -0
- package/es/ali-table/pipeline/features/columnCustom.js +913 -36
- package/es/ali-table/t-body/RenderRow.d.ts +41 -0
- package/es/ali-table/{base-table/html-table-new.js → t-body/RenderRow.js} +15 -161
- package/es/ali-table/utils/constants.d.ts +16 -0
- package/es/ali-table/utils/constants.js +21 -0
- package/es/ali-table/utils/utility.d.ts +12 -0
- package/es/ali-table/utils/utility.js +255 -0
- package/es/grid-component/hooks/constant.js +1 -1
- package/es/grid-component/type.d.ts +14 -0
- package/es/group-component/hook/utils.d.ts +6 -3
- package/es/table-component/ColumnsConfig.d.ts +0 -4
- package/es/table-component/ColumnsConfig.js +1 -1
- package/es/table-component/TableContainer.js +0 -3
- package/es/table-component/TableContainerEdit.js +0 -3
- package/es/table-component/body/TableBodyCell.js +8 -0
- package/es/table-component/hook/utils.d.ts +22 -0
- package/es/table-component/hook/utils.js +204 -5
- package/lib/ali-table/ColumnsConfig.d.ts +14 -0
- package/lib/ali-table/ColumnsConfig.js +313 -0
- package/lib/ali-table/Grid.js +109 -30
- package/lib/ali-table/InternalTable.js +1203 -15
- package/lib/ali-table/assets/WebsiteBaseTable.js +7 -3
- package/lib/ali-table/base-table/calculations.js +23 -22
- package/lib/ali-table/base-table/cell/EditCell.d.ts +27 -0
- package/lib/ali-table/base-table/cell/EditCell.js +1259 -0
- package/lib/ali-table/base-table/cell/HeaderEditCell.d.ts +28 -0
- package/lib/ali-table/base-table/cell/HeaderEditCell.js +1259 -0
- package/lib/ali-table/base-table/header.js +3 -1
- package/lib/ali-table/base-table/html-table.d.ts +4 -4
- package/lib/ali-table/base-table/html-table.js +7 -291
- package/lib/ali-table/base-table/styles.d.ts +2 -1
- package/lib/ali-table/base-table/styles.js +8 -8
- package/lib/ali-table/base-table/styles.scss +0 -34
- package/lib/ali-table/base-table/table.d.ts +13 -10
- package/lib/ali-table/base-table/table.js +22 -42
- package/lib/ali-table/base-table/utils.d.ts +4 -7
- package/lib/ali-table/base-table/utils.js +5 -8
- package/lib/ali-table/interfaces.d.ts +10 -5
- package/lib/ali-table/pipeline/features/columnCustom.d.ts +15 -0
- package/lib/ali-table/pipeline/features/columnCustom.js +926 -53
- package/lib/ali-table/t-body/RenderRow.d.ts +41 -0
- package/lib/ali-table/{base-table/html-table-new.js → t-body/RenderRow.js} +14 -160
- package/lib/ali-table/utils/constants.d.ts +16 -0
- package/lib/ali-table/utils/constants.js +27 -0
- package/lib/ali-table/utils/utility.d.ts +12 -0
- package/lib/ali-table/utils/utility.js +266 -0
- package/lib/grid-component/hooks/constant.js +1 -1
- package/lib/grid-component/type.d.ts +14 -0
- package/lib/group-component/hook/utils.d.ts +3 -0
- package/lib/table-component/ColumnsConfig.d.ts +0 -4
- package/lib/table-component/ColumnsConfig.js +1 -1
- package/lib/table-component/TableContainer.js +0 -3
- package/lib/table-component/TableContainerEdit.js +0 -3
- package/lib/table-component/body/TableBodyCell.js +8 -0
- package/lib/table-component/hook/utils.d.ts +22 -0
- package/lib/table-component/hook/utils.js +221 -4
- package/package.json +1 -1
- package/es/ali-table/base-table/html-table-default.d.ts +0 -20
- package/es/ali-table/base-table/html-table-default.js +0 -224
- package/es/ali-table/base-table/html-table-new.d.ts +0 -20
- package/lib/ali-table/base-table/html-table-default.d.ts +0 -20
- package/lib/ali-table/base-table/html-table-default.js +0 -231
- package/lib/ali-table/base-table/html-table-new.d.ts +0 -20
|
@@ -0,0 +1,1252 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { DatePicker, TimePicker, ColorPicker, Input } from "rc-master-ui";
|
|
4
|
+
import { Divider, Row, Col, Button } from "rc-master-ui";
|
|
5
|
+
import { checkDecimalSeparator, checkThousandSeparator, checkFieldKey, convertArrayWithIndent, convertDateToDayjs, convertLabelToTitle, getDatepickerFormat, isDisable, isEmpty, isNullOrUndefined, customWeekStartEndFormat, convertDayjsToDate, parseBooleanToValue, isColor, genPresets, getFormat, removeVietnameseTones, getDateValueType } from "../../../table-component/hook/utils";
|
|
6
|
+
import classNames from "classnames";
|
|
7
|
+
import { NumericFormat } from "react-numeric-component";
|
|
8
|
+
import dayjs from "dayjs";
|
|
9
|
+
import moment from "moment";
|
|
10
|
+
import { Controller } from "react-hook-form";
|
|
11
|
+
import { Checkbox, Select, TreeSelect } from "rc-master-ui";
|
|
12
|
+
// import { AsyncSelect } from "../components/async-select"
|
|
13
|
+
// import { AsyncTableSelect } from "../components/async-table-select"
|
|
14
|
+
import { cyan, green, red, blue } from '@ant-design/colors';
|
|
15
|
+
// import { EditForm } from "../components/EditForm";
|
|
16
|
+
// import { TableContext } from "../useContext"
|
|
17
|
+
// import type { ColumnSelectTable, ColumnTable, EditType, IFormat } from "../../grid-component/type"
|
|
18
|
+
import { useLocale } from "rc-master-ui/es/locale";
|
|
19
|
+
// import { getTemplate } from "../../grid-component/hooks"
|
|
20
|
+
|
|
21
|
+
import { getTemplate } from "../../../grid-component/hooks";
|
|
22
|
+
import { AsyncTableSelect } from "../../../table-component/components/async-table-select";
|
|
23
|
+
import { AsyncSelect } from "../../../table-component/components/async-select";
|
|
24
|
+
import { EditForm } from "../../../table-component/components/EditForm";
|
|
25
|
+
const {
|
|
26
|
+
SHOW_PARENT
|
|
27
|
+
} = TreeSelect;
|
|
28
|
+
const {
|
|
29
|
+
TextArea
|
|
30
|
+
} = Input;
|
|
31
|
+
const filterTreeNode = (input, treeNode) => {
|
|
32
|
+
const {
|
|
33
|
+
title,
|
|
34
|
+
value
|
|
35
|
+
} = treeNode;
|
|
36
|
+
if (typeof title === "string" || typeof title === 'number') {
|
|
37
|
+
return title.toString().toLowerCase().includes(input.toLowerCase()) || value.toLowerCase().includes(input.toLowerCase());
|
|
38
|
+
}
|
|
39
|
+
return value.toLowerCase().includes(input.toLowerCase());
|
|
40
|
+
};
|
|
41
|
+
const EditCell = props => {
|
|
42
|
+
const {
|
|
43
|
+
dataIndex,
|
|
44
|
+
editType,
|
|
45
|
+
record,
|
|
46
|
+
column,
|
|
47
|
+
indexRow,
|
|
48
|
+
indexCol,
|
|
49
|
+
format,
|
|
50
|
+
control,
|
|
51
|
+
getValues,
|
|
52
|
+
handleCellChange,
|
|
53
|
+
errors,
|
|
54
|
+
tableId,
|
|
55
|
+
startCell,
|
|
56
|
+
rowKey,
|
|
57
|
+
t,
|
|
58
|
+
// handleNextCell,
|
|
59
|
+
handleSubmit,
|
|
60
|
+
onSubmit
|
|
61
|
+
} = props;
|
|
62
|
+
const [tableLocal] = useLocale('Table');
|
|
63
|
+
const datePickerRef = React.useRef(null);
|
|
64
|
+
const dateTimePickerRef = React.useRef(null);
|
|
65
|
+
const timePickerRef = React.useRef(null);
|
|
66
|
+
const colFormat = typeof column?.format === 'function' ? column?.format(record) : column?.format;
|
|
67
|
+
const cellFormat = getFormat(colFormat, format);
|
|
68
|
+
const inputNode = (value, onChange) => {
|
|
69
|
+
const dateFormat = getDatepickerFormat(editType, cellFormat);
|
|
70
|
+
const date = !isEmpty(value) ? convertDateToDayjs(new Date(value), dateFormat) : null;
|
|
71
|
+
const maxDate = convertDateToDayjs(column.maxDate, dateFormat) ?? undefined;
|
|
72
|
+
const minDate = convertDateToDayjs(column.minDate, dateFormat) ?? undefined;
|
|
73
|
+
const formValues = getValues();
|
|
74
|
+
const {
|
|
75
|
+
fieldValue,
|
|
76
|
+
columns: selectColumns,
|
|
77
|
+
isMulti,
|
|
78
|
+
selectMode,
|
|
79
|
+
menuWidth,
|
|
80
|
+
fieldNames,
|
|
81
|
+
toolbarItems,
|
|
82
|
+
filterOption,
|
|
83
|
+
filterKey,
|
|
84
|
+
inputKey,
|
|
85
|
+
toolbarClick,
|
|
86
|
+
loadOptions,
|
|
87
|
+
validateOption,
|
|
88
|
+
options: propsOptions
|
|
89
|
+
} = column.editSelectSettings || {};
|
|
90
|
+
const isInvalid = column.field ? errors[column.field] : false;
|
|
91
|
+
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
const key = record[rowKey];
|
|
94
|
+
const field = column.field ?? '';
|
|
95
|
+
|
|
96
|
+
// const message = errors && column.field && errors[column.field] ? errors[column.field].message : ''
|
|
97
|
+
const message = isInvalid?.message;
|
|
98
|
+
const keySelect = checkFieldKey(column?.editSelectSettings?.fieldKey);
|
|
99
|
+
const selectOptions = typeof propsOptions === 'function' ? propsOptions(record, column.field) : propsOptions;
|
|
100
|
+
const options = validateOption ? validateOption(record, column.field) : selectOptions ?? [];
|
|
101
|
+
const optionsTree = validateOption ? convertArrayWithIndent(validateOption(record, column.field)) : selectOptions ? convertArrayWithIndent(selectOptions) : [];
|
|
102
|
+
|
|
103
|
+
// const focusToken = (token: FormatToken, fmt: string) => {
|
|
104
|
+
// const input: HTMLInputElement | null =
|
|
105
|
+
// timePickerRef.current?.nativeElement?.querySelector('input') ??
|
|
106
|
+
// timePickerRef.current?.input;
|
|
107
|
+
|
|
108
|
+
// if (!input) return;
|
|
109
|
+
|
|
110
|
+
// const start = fmt.indexOf(token);
|
|
111
|
+
// if (start === -1) return;
|
|
112
|
+
|
|
113
|
+
// input.focus();
|
|
114
|
+
|
|
115
|
+
// input.setSelectionRange(start, start + token.length - 1);
|
|
116
|
+
|
|
117
|
+
// requestAnimationFrame(() => {
|
|
118
|
+
// input.setSelectionRange(start, start + token.length);
|
|
119
|
+
// });
|
|
120
|
+
// };
|
|
121
|
+
|
|
122
|
+
switch (editType) {
|
|
123
|
+
case 'date':
|
|
124
|
+
return /*#__PURE__*/React.createElement(DatePicker, {
|
|
125
|
+
ref: datePickerRef,
|
|
126
|
+
format: {
|
|
127
|
+
format: dateFormat,
|
|
128
|
+
type: 'mask'
|
|
129
|
+
},
|
|
130
|
+
autoFocus: column.field === startCell?.colId,
|
|
131
|
+
defaultOpen: column.field === startCell?.colId,
|
|
132
|
+
style: {
|
|
133
|
+
width: '100%',
|
|
134
|
+
height: '100%'
|
|
135
|
+
}
|
|
136
|
+
// value={date}
|
|
137
|
+
,
|
|
138
|
+
defaultValue: date
|
|
139
|
+
// preserveInvalidOnBlur
|
|
140
|
+
,
|
|
141
|
+
|
|
142
|
+
onBlur: () => {
|
|
143
|
+
const formState = getValues();
|
|
144
|
+
const itemState = getValues(dataIndex);
|
|
145
|
+
// @ts-ignore
|
|
146
|
+
const prevState = record[dataIndex];
|
|
147
|
+
const newState = itemState;
|
|
148
|
+
if (newState !== prevState) {
|
|
149
|
+
handleCellChange?.({
|
|
150
|
+
key: key,
|
|
151
|
+
field: column.field,
|
|
152
|
+
record: formState,
|
|
153
|
+
prevState,
|
|
154
|
+
newState,
|
|
155
|
+
option: newState,
|
|
156
|
+
indexCol,
|
|
157
|
+
indexRow,
|
|
158
|
+
type: 'blur'
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : undefined,
|
|
163
|
+
disabled: isDisable(column, record) ?? false,
|
|
164
|
+
maxDate: maxDate,
|
|
165
|
+
minDate: minDate,
|
|
166
|
+
onChange: (newDate, dateString) => {
|
|
167
|
+
const newDateValue = dateString ? moment(convertDayjsToDate(dateString, dateFormat)).format() : null;
|
|
168
|
+
onChange(newDateValue);
|
|
169
|
+
setTimeout(() => {
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
datePickerRef.current?.focus();
|
|
172
|
+
}, 0);
|
|
173
|
+
},
|
|
174
|
+
popupClassName: 'be-popup-container',
|
|
175
|
+
status: isInvalid ? 'error' : undefined,
|
|
176
|
+
"data-tooltip-content": message,
|
|
177
|
+
"data-tooltip-id": `${tableId}-tooltip-error`
|
|
178
|
+
});
|
|
179
|
+
case 'datetime':
|
|
180
|
+
return /*#__PURE__*/React.createElement(DatePicker, {
|
|
181
|
+
ref: dateTimePickerRef,
|
|
182
|
+
format: {
|
|
183
|
+
format: dateFormat,
|
|
184
|
+
type: 'mask'
|
|
185
|
+
},
|
|
186
|
+
style: {
|
|
187
|
+
width: '100%',
|
|
188
|
+
height: '100%'
|
|
189
|
+
},
|
|
190
|
+
showTime: true
|
|
191
|
+
// value={date}
|
|
192
|
+
,
|
|
193
|
+
defaultValue: date,
|
|
194
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : undefined,
|
|
195
|
+
disabled: isDisable(column, record) ?? false,
|
|
196
|
+
maxDate: maxDate,
|
|
197
|
+
minDate: minDate
|
|
198
|
+
// mode="date"
|
|
199
|
+
,
|
|
200
|
+
|
|
201
|
+
popupClassName: 'be-popup-container',
|
|
202
|
+
status: isInvalid ? 'error' : undefined,
|
|
203
|
+
"data-tooltip-content": message,
|
|
204
|
+
"data-tooltip-id": `${tableId}-tooltip-error`,
|
|
205
|
+
autoFocus: column.field === startCell?.colId,
|
|
206
|
+
defaultOpen: column.field === startCell?.colId
|
|
207
|
+
// needConfirm={true}
|
|
208
|
+
,
|
|
209
|
+
|
|
210
|
+
onCalendarChange: (newDate, dateString) => {
|
|
211
|
+
const newDateValue = dateString ? moment(convertDayjsToDate(dateString, dateFormat)).format() : null;
|
|
212
|
+
onChange(newDateValue);
|
|
213
|
+
setTimeout(() => {
|
|
214
|
+
// @ts-ignore
|
|
215
|
+
dateTimePickerRef.current?.focus();
|
|
216
|
+
}, 0);
|
|
217
|
+
},
|
|
218
|
+
onOpenChange: open => {
|
|
219
|
+
if (!open) {
|
|
220
|
+
const formState = getValues();
|
|
221
|
+
const itemState = getValues(dataIndex);
|
|
222
|
+
// @ts-ignore
|
|
223
|
+
const prevState = record[dataIndex];
|
|
224
|
+
const newState = itemState;
|
|
225
|
+
if (prevState !== newState) {
|
|
226
|
+
handleCellChange?.({
|
|
227
|
+
key: key,
|
|
228
|
+
field: column.field ?? column.field,
|
|
229
|
+
record: formState,
|
|
230
|
+
prevState,
|
|
231
|
+
newState,
|
|
232
|
+
option: newState,
|
|
233
|
+
indexCol,
|
|
234
|
+
indexRow,
|
|
235
|
+
type: 'blur'
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
case 'month':
|
|
242
|
+
case 'quarter':
|
|
243
|
+
case 'year':
|
|
244
|
+
const pickerFormat = getDatepickerFormat(editType, cellFormat);
|
|
245
|
+
const maxDateValue1 = !isEmpty(column.maxDate) ? dayjs(column.maxDate, pickerFormat) : undefined;
|
|
246
|
+
const minDateValue1 = !isEmpty(column.minDate) ? dayjs(column.minDate, pickerFormat) : undefined;
|
|
247
|
+
return /*#__PURE__*/React.createElement(DatePicker, {
|
|
248
|
+
id: `col${indexCol}-record${indexRow}`,
|
|
249
|
+
format: {
|
|
250
|
+
format: pickerFormat,
|
|
251
|
+
type: 'mask'
|
|
252
|
+
},
|
|
253
|
+
style: {
|
|
254
|
+
width: '100%',
|
|
255
|
+
height: '100%'
|
|
256
|
+
},
|
|
257
|
+
picker: editType,
|
|
258
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : undefined,
|
|
259
|
+
disabled: isDisable(column, record) ?? false,
|
|
260
|
+
maxDate: maxDateValue1,
|
|
261
|
+
minDate: minDateValue1,
|
|
262
|
+
popupClassName: 'be-popup-container',
|
|
263
|
+
status: isInvalid ? 'error' : undefined,
|
|
264
|
+
"data-tooltip-content": message,
|
|
265
|
+
"data-tooltip-id": `${tableId}-tooltip-error`,
|
|
266
|
+
autoFocus: column.field === startCell?.colId,
|
|
267
|
+
defaultOpen: column.field === startCell?.colId
|
|
268
|
+
});
|
|
269
|
+
case 'week':
|
|
270
|
+
const weekFormat = getDatepickerFormat(editType, cellFormat);
|
|
271
|
+
const maxWeekValue = !isEmpty(column.maxDate) ? dayjs(column.maxDate, weekFormat) : undefined;
|
|
272
|
+
const minWeekValue = !isEmpty(column.minDate) ? dayjs(column.minDate, weekFormat) : undefined;
|
|
273
|
+
return /*#__PURE__*/React.createElement(DatePicker, {
|
|
274
|
+
format: val => customWeekStartEndFormat(val, weekFormat),
|
|
275
|
+
style: {
|
|
276
|
+
width: '100%',
|
|
277
|
+
height: '100%'
|
|
278
|
+
},
|
|
279
|
+
picker: editType,
|
|
280
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : undefined,
|
|
281
|
+
disabled: isDisable(column, record) ?? false,
|
|
282
|
+
maxDate: maxWeekValue,
|
|
283
|
+
minDate: minWeekValue,
|
|
284
|
+
popupClassName: 'be-popup-container',
|
|
285
|
+
status: isInvalid ? 'error' : undefined,
|
|
286
|
+
"data-tooltip-content": message,
|
|
287
|
+
"data-tooltip-id": `${tableId}-tooltip-error`,
|
|
288
|
+
autoFocus: column.field === startCell?.colId,
|
|
289
|
+
defaultOpen: column.field === startCell?.colId
|
|
290
|
+
});
|
|
291
|
+
case 'time':
|
|
292
|
+
const timeFormat = getDatepickerFormat(editType, cellFormat);
|
|
293
|
+
|
|
294
|
+
// chỉ nhận giá trị dạng HH:mm | mm:HH => convert
|
|
295
|
+
|
|
296
|
+
let time = value ?? undefined;
|
|
297
|
+
const typeTime = getDateValueType(value);
|
|
298
|
+
if (typeTime === 'time') {
|
|
299
|
+
time = value ? dayjs(value, timeFormat) : undefined;
|
|
300
|
+
} else {
|
|
301
|
+
const abc = value ? moment(value).format(timeFormat) : undefined;
|
|
302
|
+
time = abc ? dayjs(abc, timeFormat) : undefined;
|
|
303
|
+
}
|
|
304
|
+
const maxTimeValue = !isEmpty(column.maxTime) ? dayjs(column.maxTime).format(timeFormat) : null;
|
|
305
|
+
const minTimeValue = !isEmpty(column.minTime) ? dayjs(column.minTime).format(timeFormat) : null;
|
|
306
|
+
|
|
307
|
+
// @ts-ignore
|
|
308
|
+
// const timeValue = !isEmpty(record[dataIndex]) ? dayjs(record[dataIndex], timeFormat) : null
|
|
309
|
+
const maxTime = maxTimeValue ? dayjs(maxTimeValue, timeFormat) : undefined;
|
|
310
|
+
const minTime = minTimeValue ? dayjs(minTimeValue, timeFormat) : undefined;
|
|
311
|
+
return /*#__PURE__*/React.createElement(TimePicker, {
|
|
312
|
+
ref: timePickerRef,
|
|
313
|
+
format: {
|
|
314
|
+
format: timeFormat,
|
|
315
|
+
type: 'mask'
|
|
316
|
+
},
|
|
317
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : undefined,
|
|
318
|
+
maxDate: maxTime,
|
|
319
|
+
minDate: minTime
|
|
320
|
+
// value={time}
|
|
321
|
+
,
|
|
322
|
+
defaultValue: time,
|
|
323
|
+
disabled: isDisable(column, record) ?? false,
|
|
324
|
+
style: {
|
|
325
|
+
width: '100%',
|
|
326
|
+
height: '100%'
|
|
327
|
+
},
|
|
328
|
+
popupClassName: 'be-popup-container',
|
|
329
|
+
status: isInvalid ? 'error' : undefined,
|
|
330
|
+
"data-tooltip-content": message,
|
|
331
|
+
"data-tooltip-id": `${tableId}-tooltip-error`,
|
|
332
|
+
autoFocus: column.field === startCell?.colId,
|
|
333
|
+
defaultOpen: column.field === startCell?.colId
|
|
334
|
+
|
|
335
|
+
// onChange={(newDate, dateString) => {
|
|
336
|
+
|
|
337
|
+
// if (typeTime === 'time') {
|
|
338
|
+
|
|
339
|
+
// onChange(dateString)
|
|
340
|
+
|
|
341
|
+
// } else {
|
|
342
|
+
|
|
343
|
+
// // const datetime = dayjs(dateString as string, timeFormat, true);
|
|
344
|
+
|
|
345
|
+
// const newVal = newDate ? moment(newDate.toDate()).format() : undefined
|
|
346
|
+
|
|
347
|
+
// // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
|
|
348
|
+
// onChange(newVal)
|
|
349
|
+
|
|
350
|
+
// }
|
|
351
|
+
|
|
352
|
+
// setTimeout(() => {
|
|
353
|
+
// // @ts-ignore
|
|
354
|
+
// dateTimePickerRef.current?.focus()
|
|
355
|
+
// }, 0)
|
|
356
|
+
|
|
357
|
+
// }}
|
|
358
|
+
|
|
359
|
+
// onBlur={() => {
|
|
360
|
+
// const formState = getValues()
|
|
361
|
+
// const itemState = getValues(dataIndex)
|
|
362
|
+
// // @ts-ignore
|
|
363
|
+
// const prevState = record[dataIndex]
|
|
364
|
+
// const newState = itemState
|
|
365
|
+
|
|
366
|
+
// let newValue = newState
|
|
367
|
+
|
|
368
|
+
// if (typeTime === 'time') {
|
|
369
|
+
|
|
370
|
+
// newValue = newState
|
|
371
|
+
|
|
372
|
+
// } else {
|
|
373
|
+
|
|
374
|
+
// const datetime = dayjs(newState as string, timeFormat, true);
|
|
375
|
+
|
|
376
|
+
// const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : undefined
|
|
377
|
+
// onChange(newVal)
|
|
378
|
+
|
|
379
|
+
// newValue = newVal
|
|
380
|
+
|
|
381
|
+
// }
|
|
382
|
+
|
|
383
|
+
// if (prevState !== newState) {
|
|
384
|
+
// handleCellChange?.({
|
|
385
|
+
// key: key as any,
|
|
386
|
+
// field: column.field ?? column.field as any,
|
|
387
|
+
// record: formState,
|
|
388
|
+
// prevState,
|
|
389
|
+
// newState: newValue,
|
|
390
|
+
// option: newValue,
|
|
391
|
+
// indexCol,
|
|
392
|
+
// indexRow,
|
|
393
|
+
// type: 'blur'
|
|
394
|
+
// })
|
|
395
|
+
// }
|
|
396
|
+
// }}
|
|
397
|
+
|
|
398
|
+
// needConfirm={false}
|
|
399
|
+
,
|
|
400
|
+
|
|
401
|
+
onCalendarChange: (newDate, dateString) => {
|
|
402
|
+
// const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
|
|
403
|
+
|
|
404
|
+
// onChange(newDateValue)
|
|
405
|
+
|
|
406
|
+
if (typeTime === 'time') {
|
|
407
|
+
onChange(dateString);
|
|
408
|
+
} else {
|
|
409
|
+
// const datetime = dayjs(dateString as string, timeFormat, true);
|
|
410
|
+
|
|
411
|
+
const newVal = newDate ? moment(newDate.toDate()).format() : undefined;
|
|
412
|
+
|
|
413
|
+
// const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
|
|
414
|
+
onChange(newVal);
|
|
415
|
+
}
|
|
416
|
+
setTimeout(() => {
|
|
417
|
+
// @ts-ignore
|
|
418
|
+
timePickerRef.current?.focus();
|
|
419
|
+
});
|
|
420
|
+
},
|
|
421
|
+
onOpenChange: open => {
|
|
422
|
+
if (!open) {
|
|
423
|
+
const formState = getValues();
|
|
424
|
+
const itemState = getValues(dataIndex);
|
|
425
|
+
// @ts-ignore
|
|
426
|
+
const prevState = record[dataIndex];
|
|
427
|
+
const newState = itemState;
|
|
428
|
+
if (prevState !== newState) {
|
|
429
|
+
handleCellChange?.({
|
|
430
|
+
key: key,
|
|
431
|
+
field: column.field ?? column.field,
|
|
432
|
+
record: formState,
|
|
433
|
+
prevState,
|
|
434
|
+
newState,
|
|
435
|
+
option: newState,
|
|
436
|
+
indexCol,
|
|
437
|
+
indexRow,
|
|
438
|
+
type: 'blur'
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// onKeyDown={(e) => {
|
|
445
|
+
// if (e?.code === "Tab") {
|
|
446
|
+
// handleNextCell?.()
|
|
447
|
+
|
|
448
|
+
// }
|
|
449
|
+
|
|
450
|
+
// }}
|
|
451
|
+
});
|
|
452
|
+
case 'selectTable':
|
|
453
|
+
const rr = selectColumns ?? [];
|
|
454
|
+
const columnsTable = rr.map(colSelect => {
|
|
455
|
+
return {
|
|
456
|
+
title: colSelect.headerTemplate ? colSelect.headerTemplate : t ? t(colSelect.headerText) : colSelect.headerText,
|
|
457
|
+
dataIndex: colSelect.field ?? colSelect.dataIndex,
|
|
458
|
+
key: colSelect.dataIndex,
|
|
459
|
+
render: colSelect.template ? (text, recd, ind) => /*#__PURE__*/React.createElement(React.Fragment, null, colSelect.template?.({
|
|
460
|
+
value: text,
|
|
461
|
+
rowData: recd,
|
|
462
|
+
column: colSelect,
|
|
463
|
+
field: colSelect.field,
|
|
464
|
+
index: ind,
|
|
465
|
+
[colSelect.field]: text
|
|
466
|
+
})) : undefined,
|
|
467
|
+
width: colSelect.width,
|
|
468
|
+
ellipsis: true,
|
|
469
|
+
align: colSelect.textAlign
|
|
470
|
+
};
|
|
471
|
+
});
|
|
472
|
+
let valueSelectTable = formValues[dataIndex];
|
|
473
|
+
if (fieldValue) {
|
|
474
|
+
// @ts-ignore
|
|
475
|
+
valueSelectTable = record[fieldValue] ?? formValues[dataIndex];
|
|
476
|
+
}
|
|
477
|
+
return /*#__PURE__*/React.createElement(AsyncTableSelect, {
|
|
478
|
+
columns: columnsTable,
|
|
479
|
+
options: options,
|
|
480
|
+
defaultOptions: options,
|
|
481
|
+
value: valueSelectTable ?? undefined,
|
|
482
|
+
autoDestroy: true,
|
|
483
|
+
onChange: (val, option) => {
|
|
484
|
+
onChange(val ?? '');
|
|
485
|
+
const formState = getValues();
|
|
486
|
+
const formNewState = {
|
|
487
|
+
...getValues(),
|
|
488
|
+
[dataIndex]: !isNullOrUndefined(formState[dataIndex]) ? formState[dataIndex] : undefined
|
|
489
|
+
};
|
|
490
|
+
// @ts-ignore
|
|
491
|
+
const prevState = record[dataIndex] ?? undefined;
|
|
492
|
+
const newState = val ?? undefined;
|
|
493
|
+
handleCellChange?.({
|
|
494
|
+
key,
|
|
495
|
+
field: column.field ?? column.field,
|
|
496
|
+
record: formNewState,
|
|
497
|
+
prevState,
|
|
498
|
+
newState,
|
|
499
|
+
option: option,
|
|
500
|
+
indexCol,
|
|
501
|
+
indexRow,
|
|
502
|
+
type: 'blur'
|
|
503
|
+
});
|
|
504
|
+
},
|
|
505
|
+
showSearch: true,
|
|
506
|
+
mode: isMulti || selectMode === 'checkbox' ? 'multiple' : undefined,
|
|
507
|
+
valueSelectAble: true,
|
|
508
|
+
selectMode: selectMode,
|
|
509
|
+
style: {
|
|
510
|
+
width: '100%',
|
|
511
|
+
height: '100%'
|
|
512
|
+
},
|
|
513
|
+
defaultOpen: column.field === startCell?.colId,
|
|
514
|
+
autoFocus: column.field === startCell?.colId,
|
|
515
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : tableLocal?.selectPlaceholder,
|
|
516
|
+
allowClear: column.isClearable ?? false,
|
|
517
|
+
maxTagCount: 'responsive',
|
|
518
|
+
rowKey: keySelect,
|
|
519
|
+
popupMatchSelectWidth: menuWidth ? menuWidth + 10 : undefined,
|
|
520
|
+
optionFilterProp: "label",
|
|
521
|
+
popupClassName: 'be-popup-container',
|
|
522
|
+
loadOptions: loadOptions,
|
|
523
|
+
status: isInvalid ? 'error' : undefined,
|
|
524
|
+
dropdownRender: menu => {
|
|
525
|
+
if (toolbarItems && toolbarItems.length > 0) {
|
|
526
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, menu, toolbarItems && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, {
|
|
527
|
+
style: {
|
|
528
|
+
margin: '8px 0'
|
|
529
|
+
}
|
|
530
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
531
|
+
className: 'toolbar-control d-flex justify-content-end'
|
|
532
|
+
}, toolbarItems.map(it => {
|
|
533
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
534
|
+
key: it.key,
|
|
535
|
+
className: 'toolbar-item',
|
|
536
|
+
onClick: () => toolbarClick?.({
|
|
537
|
+
item: it,
|
|
538
|
+
column
|
|
539
|
+
})
|
|
540
|
+
}, it.template ? getTemplate(it.template) : /*#__PURE__*/React.createElement(Button, {
|
|
541
|
+
className: "toolbar-item-btn"
|
|
542
|
+
}, it.icon && getTemplate(it.icon), it.title));
|
|
543
|
+
}))));
|
|
544
|
+
} else {
|
|
545
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, " ", menu);
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
filterOption: filterKey ? (input, option) => {
|
|
549
|
+
const searchValue = removeVietnameseTones(input.toLowerCase() ?? '');
|
|
550
|
+
const filterValues = filterKey.some(k => {
|
|
551
|
+
const val = option?.[k];
|
|
552
|
+
return removeVietnameseTones((val ?? '').toString().toLowerCase()).includes(searchValue);
|
|
553
|
+
});
|
|
554
|
+
return filterValues;
|
|
555
|
+
} : filterOption,
|
|
556
|
+
fieldNames: fieldNames ? fieldNames : {
|
|
557
|
+
value: keySelect,
|
|
558
|
+
label: inputKey ?? 'label'
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// onBlur={(event: any) => {
|
|
562
|
+
|
|
563
|
+
// if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
564
|
+
// const val = event.inputValue
|
|
565
|
+
// onChange(val ?? undefined)
|
|
566
|
+
|
|
567
|
+
// const formState = getValues()
|
|
568
|
+
// // const itemState = getValues(dataIndex)
|
|
569
|
+
// // @ts-ignore
|
|
570
|
+
// const prevState = record[dataIndex]
|
|
571
|
+
// const newState = val
|
|
572
|
+
|
|
573
|
+
// handleCellChange?.({
|
|
574
|
+
// key,
|
|
575
|
+
// field: column.field ?? column.field as any,
|
|
576
|
+
// record: formState,
|
|
577
|
+
// prevState,
|
|
578
|
+
// newState,
|
|
579
|
+
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
580
|
+
// indexCol,
|
|
581
|
+
// indexRow,
|
|
582
|
+
// type: 'blur'
|
|
583
|
+
// })
|
|
584
|
+
// }
|
|
585
|
+
// }}
|
|
586
|
+
|
|
587
|
+
// onKeyDown={(event: any) => {
|
|
588
|
+
|
|
589
|
+
// if (event.key === 'Enter' && event.target?.value && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
590
|
+
|
|
591
|
+
// const val = event.target.value
|
|
592
|
+
// onChange(val)
|
|
593
|
+
|
|
594
|
+
// const formState = getValues()
|
|
595
|
+
// // const itemState = getValues(dataIndex)
|
|
596
|
+
// // @ts-ignore
|
|
597
|
+
// const prevState = record[dataIndex]
|
|
598
|
+
// const newState = val
|
|
599
|
+
|
|
600
|
+
// handleCellChange?.({
|
|
601
|
+
// key,
|
|
602
|
+
// field: column.field ?? column.field as any,
|
|
603
|
+
// record: formState,
|
|
604
|
+
// prevState,
|
|
605
|
+
// newState,
|
|
606
|
+
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
607
|
+
// indexCol,
|
|
608
|
+
// indexRow,
|
|
609
|
+
// type: 'blur'
|
|
610
|
+
// })
|
|
611
|
+
|
|
612
|
+
// }
|
|
613
|
+
|
|
614
|
+
// }}
|
|
615
|
+
,
|
|
616
|
+
|
|
617
|
+
"data-tooltip-content": message,
|
|
618
|
+
"data-tooltip-id": `${tableId}-tooltip-error`
|
|
619
|
+
});
|
|
620
|
+
case 'select':
|
|
621
|
+
let valueSelect = formValues[dataIndex];
|
|
622
|
+
if (fieldValue) {
|
|
623
|
+
// @ts-ignore
|
|
624
|
+
valueSelect = record[fieldValue] ?? formValues[dataIndex];
|
|
625
|
+
}
|
|
626
|
+
return /*#__PURE__*/React.createElement(Select, {
|
|
627
|
+
options: options,
|
|
628
|
+
value: valueSelect ?? '',
|
|
629
|
+
onChange: (val, option) => {
|
|
630
|
+
onChange(val ?? '');
|
|
631
|
+
const formState = getValues();
|
|
632
|
+
const formNewState = {
|
|
633
|
+
...getValues(),
|
|
634
|
+
[dataIndex]: !isNullOrUndefined(formState[dataIndex]) ? formState[dataIndex] : undefined
|
|
635
|
+
};
|
|
636
|
+
// @ts-ignore
|
|
637
|
+
const prevState = record[dataIndex] ?? undefined;
|
|
638
|
+
const newState = val ?? undefined;
|
|
639
|
+
handleCellChange?.({
|
|
640
|
+
key,
|
|
641
|
+
field: column.field ?? column.field,
|
|
642
|
+
record: formNewState,
|
|
643
|
+
prevState,
|
|
644
|
+
newState,
|
|
645
|
+
option: option,
|
|
646
|
+
indexCol,
|
|
647
|
+
indexRow,
|
|
648
|
+
type: 'blur'
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
// destroyOnHidden
|
|
652
|
+
// des
|
|
653
|
+
// autoDestroy={true}
|
|
654
|
+
,
|
|
655
|
+
showSearch: true,
|
|
656
|
+
mode: isMulti || selectMode === 'checkbox' ? 'multiple' : undefined,
|
|
657
|
+
valueSelectAble: true,
|
|
658
|
+
defaultOpen: column.field === startCell?.colId,
|
|
659
|
+
autoFocus: column.field === startCell?.colId,
|
|
660
|
+
style: {
|
|
661
|
+
width: '100%',
|
|
662
|
+
height: '100%'
|
|
663
|
+
},
|
|
664
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : tableLocal?.selectPlaceholder,
|
|
665
|
+
allowClear: column.isClearable ?? false,
|
|
666
|
+
maxTagCount: 'responsive',
|
|
667
|
+
popupMatchSelectWidth: menuWidth ? menuWidth + 10 : undefined,
|
|
668
|
+
optionFilterProp: "label",
|
|
669
|
+
popupClassName: 'be-popup-container',
|
|
670
|
+
status: isInvalid ? 'error' : undefined,
|
|
671
|
+
filterOption: filterKey ? (input, option) => {
|
|
672
|
+
const searchValue = removeVietnameseTones(input.toLowerCase() ?? '');
|
|
673
|
+
const filterValues = filterKey.some(k => {
|
|
674
|
+
const val = option?.[k];
|
|
675
|
+
return removeVietnameseTones((val ?? '').toString().toLowerCase()).includes(searchValue);
|
|
676
|
+
});
|
|
677
|
+
return filterValues;
|
|
678
|
+
} : filterOption,
|
|
679
|
+
optionRender: column.editSelectSettings?.formatOptionLabel,
|
|
680
|
+
fieldNames: {
|
|
681
|
+
value: keySelect,
|
|
682
|
+
label: inputKey ?? 'label'
|
|
683
|
+
},
|
|
684
|
+
onBlur: event => {
|
|
685
|
+
if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
686
|
+
const val = event.inputValue;
|
|
687
|
+
onChange(val);
|
|
688
|
+
const formState = getValues();
|
|
689
|
+
// const itemState = getValues(dataIndex)
|
|
690
|
+
// @ts-ignore
|
|
691
|
+
const prevState = record[dataIndex];
|
|
692
|
+
const newState = val;
|
|
693
|
+
handleCellChange?.({
|
|
694
|
+
key,
|
|
695
|
+
field: column.field ?? column.field,
|
|
696
|
+
record: formState,
|
|
697
|
+
prevState,
|
|
698
|
+
newState,
|
|
699
|
+
option: {
|
|
700
|
+
value: val,
|
|
701
|
+
label: val,
|
|
702
|
+
searchTextAsValue: true
|
|
703
|
+
},
|
|
704
|
+
indexCol,
|
|
705
|
+
indexRow,
|
|
706
|
+
type: 'blur'
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
},
|
|
710
|
+
onKeyDown: event => {
|
|
711
|
+
if (event.key === 'Enter' && event.target?.value && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
712
|
+
const val = event.target.value;
|
|
713
|
+
onChange(val);
|
|
714
|
+
const formState = getValues();
|
|
715
|
+
// const itemState = getValues(dataIndex)
|
|
716
|
+
// @ts-ignore
|
|
717
|
+
const prevState = record[dataIndex];
|
|
718
|
+
const newState = val;
|
|
719
|
+
handleCellChange?.({
|
|
720
|
+
key,
|
|
721
|
+
field: column.field ?? column.field,
|
|
722
|
+
record: formState,
|
|
723
|
+
prevState,
|
|
724
|
+
newState,
|
|
725
|
+
option: {
|
|
726
|
+
value: val,
|
|
727
|
+
label: val,
|
|
728
|
+
searchTextAsValue: true
|
|
729
|
+
},
|
|
730
|
+
indexCol,
|
|
731
|
+
indexRow,
|
|
732
|
+
type: 'blur'
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
},
|
|
736
|
+
dropdownRender: menu => {
|
|
737
|
+
if (toolbarItems && toolbarItems.length > 0) {
|
|
738
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, menu, toolbarItems && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, {
|
|
739
|
+
style: {
|
|
740
|
+
margin: '8px 0'
|
|
741
|
+
}
|
|
742
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
743
|
+
className: 'toolbar-control d-flex justify-content-end'
|
|
744
|
+
}, toolbarItems.map(it => {
|
|
745
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
746
|
+
key: it.key,
|
|
747
|
+
className: 'toolbar-item',
|
|
748
|
+
onClick: () => toolbarClick?.({
|
|
749
|
+
item: it,
|
|
750
|
+
column
|
|
751
|
+
})
|
|
752
|
+
}, it.template ? getTemplate(it.template) : /*#__PURE__*/React.createElement(Button, {
|
|
753
|
+
className: "toolbar-item-btn"
|
|
754
|
+
}, it.icon && getTemplate(it.icon), it.title));
|
|
755
|
+
}))));
|
|
756
|
+
} else {
|
|
757
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, " ", menu);
|
|
758
|
+
}
|
|
759
|
+
},
|
|
760
|
+
"data-tooltip-content": message,
|
|
761
|
+
"data-tooltip-id": `${tableId}-tooltip-error`
|
|
762
|
+
});
|
|
763
|
+
case 'asyncSelect':
|
|
764
|
+
let valueAsyncSelect = formValues[dataIndex];
|
|
765
|
+
if (fieldValue) {
|
|
766
|
+
// @ts-ignore
|
|
767
|
+
valueAsyncSelect = record[fieldValue] ?? formValues[dataIndex];
|
|
768
|
+
}
|
|
769
|
+
return /*#__PURE__*/React.createElement(AsyncSelect, {
|
|
770
|
+
options: options,
|
|
771
|
+
defaultOptions: options,
|
|
772
|
+
value: valueAsyncSelect ?? undefined,
|
|
773
|
+
onChange: (val, option) => {
|
|
774
|
+
onChange(val ?? '');
|
|
775
|
+
const formState = getValues();
|
|
776
|
+
const formNewState = {
|
|
777
|
+
...getValues(),
|
|
778
|
+
[dataIndex]: !isNullOrUndefined(formState[dataIndex]) ? formState[dataIndex] : undefined
|
|
779
|
+
};
|
|
780
|
+
// @ts-ignore
|
|
781
|
+
const prevState = record[dataIndex] ?? undefined;
|
|
782
|
+
const newState = val ?? undefined;
|
|
783
|
+
handleCellChange?.({
|
|
784
|
+
key,
|
|
785
|
+
field: column.field ?? column.field,
|
|
786
|
+
record: formNewState,
|
|
787
|
+
prevState,
|
|
788
|
+
newState,
|
|
789
|
+
option: option,
|
|
790
|
+
indexCol,
|
|
791
|
+
indexRow,
|
|
792
|
+
type: 'blur'
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
// autoDestroy={true}
|
|
796
|
+
,
|
|
797
|
+
showSearch: true,
|
|
798
|
+
defaultOpen: column.field === startCell?.colId,
|
|
799
|
+
autoFocus: column.field === startCell?.colId,
|
|
800
|
+
mode: isMulti || selectMode === 'checkbox' ? 'multiple' : undefined,
|
|
801
|
+
valueSelectAble: true,
|
|
802
|
+
style: {
|
|
803
|
+
width: '100%',
|
|
804
|
+
height: '100%'
|
|
805
|
+
},
|
|
806
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : tableLocal?.selectPlaceholder,
|
|
807
|
+
allowClear: column.isClearable ?? false,
|
|
808
|
+
maxTagCount: 'responsive',
|
|
809
|
+
popupMatchSelectWidth: menuWidth ? menuWidth + 10 : undefined,
|
|
810
|
+
optionFilterProp: "label",
|
|
811
|
+
popupClassName: 'be-popup-container',
|
|
812
|
+
loadOptions: loadOptions,
|
|
813
|
+
status: isInvalid ? 'error' : undefined,
|
|
814
|
+
dropdownRender: menu => {
|
|
815
|
+
if (toolbarItems && toolbarItems.length > 0) {
|
|
816
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, menu, toolbarItems && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, {
|
|
817
|
+
style: {
|
|
818
|
+
margin: '8px 0'
|
|
819
|
+
}
|
|
820
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
821
|
+
className: 'toolbar-control d-flex justify-content-end'
|
|
822
|
+
}, toolbarItems.map(it => {
|
|
823
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
824
|
+
key: it.key,
|
|
825
|
+
className: 'toolbar-item',
|
|
826
|
+
onClick: () => toolbarClick?.({
|
|
827
|
+
item: it,
|
|
828
|
+
column
|
|
829
|
+
})
|
|
830
|
+
}, it.template ? getTemplate(it.template) : /*#__PURE__*/React.createElement(Button, {
|
|
831
|
+
className: "toolbar-item-btn"
|
|
832
|
+
}, it.icon && getTemplate(it.icon), it.title));
|
|
833
|
+
}))));
|
|
834
|
+
} else {
|
|
835
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, " ", menu);
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
optionRender: column.editSelectSettings?.formatOptionLabel,
|
|
839
|
+
filterOption: filterKey ? (input, option) => {
|
|
840
|
+
const searchValue = removeVietnameseTones(input.toLowerCase() ?? '');
|
|
841
|
+
const filterValues = filterKey.some(k => {
|
|
842
|
+
const val = option?.[k];
|
|
843
|
+
return removeVietnameseTones((val ?? '').toString().toLowerCase()).includes(searchValue);
|
|
844
|
+
});
|
|
845
|
+
return filterValues;
|
|
846
|
+
} : filterOption,
|
|
847
|
+
fieldNames: fieldNames ? fieldNames : {
|
|
848
|
+
value: keySelect,
|
|
849
|
+
label: inputKey ?? 'label'
|
|
850
|
+
},
|
|
851
|
+
onBlur: event => {
|
|
852
|
+
if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
853
|
+
const val = event.inputValue;
|
|
854
|
+
onChange(val);
|
|
855
|
+
const formState = getValues();
|
|
856
|
+
// const itemState = getValues(dataIndex)
|
|
857
|
+
// @ts-ignore
|
|
858
|
+
const prevState = record[dataIndex];
|
|
859
|
+
const newState = val;
|
|
860
|
+
handleCellChange?.({
|
|
861
|
+
key,
|
|
862
|
+
field: column.field ?? column.field,
|
|
863
|
+
record: formState,
|
|
864
|
+
prevState,
|
|
865
|
+
newState,
|
|
866
|
+
option: {
|
|
867
|
+
value: val,
|
|
868
|
+
label: val,
|
|
869
|
+
searchTextAsValue: true
|
|
870
|
+
},
|
|
871
|
+
indexCol,
|
|
872
|
+
indexRow,
|
|
873
|
+
type: 'blur'
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
},
|
|
877
|
+
"data-tooltip-content": message,
|
|
878
|
+
"data-tooltip-id": `${tableId}-tooltip-error`
|
|
879
|
+
});
|
|
880
|
+
case 'treeSelect':
|
|
881
|
+
const newTreeData = convertLabelToTitle(optionsTree);
|
|
882
|
+
let valueTreeSelect = value;
|
|
883
|
+
if (fieldValue) {
|
|
884
|
+
// @ts-ignore
|
|
885
|
+
valueTreeSelect = record[fieldValue] ?? value;
|
|
886
|
+
}
|
|
887
|
+
return /*#__PURE__*/React.createElement(TreeSelect, {
|
|
888
|
+
id: `col${indexCol}-record${indexRow}`,
|
|
889
|
+
className: 'be-tree-select',
|
|
890
|
+
style: {
|
|
891
|
+
width: '100%',
|
|
892
|
+
height: '100%'
|
|
893
|
+
},
|
|
894
|
+
value: valueTreeSelect ?? undefined,
|
|
895
|
+
dropdownStyle: {
|
|
896
|
+
maxHeight: 400,
|
|
897
|
+
overflow: 'auto'
|
|
898
|
+
},
|
|
899
|
+
treeData: newTreeData,
|
|
900
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : tableLocal?.selectPlaceholder,
|
|
901
|
+
treeDefaultExpandAll: true,
|
|
902
|
+
defaultOpen: column.field === startCell?.colId,
|
|
903
|
+
autoFocus: column.field === startCell?.colId,
|
|
904
|
+
virtual: true,
|
|
905
|
+
allowClear: true,
|
|
906
|
+
showSearch: true,
|
|
907
|
+
maxTagCount: column?.editSelectSettings?.showItems,
|
|
908
|
+
maxTagPlaceholder: 2,
|
|
909
|
+
treeTitleRender: column?.editSelectSettings?.formatOptionLabel,
|
|
910
|
+
showCheckedStrategy: SHOW_PARENT,
|
|
911
|
+
multiple: column?.editSelectSettings?.selectMode === 'checkbox' || column?.editSelectSettings?.isMulti
|
|
912
|
+
// fieldNames={{label: inputKey ? inputKey : 'title', value: keySelect, children: 'children'}}
|
|
913
|
+
,
|
|
914
|
+
treeCheckable: column?.editSelectSettings?.selectMode === 'checkbox',
|
|
915
|
+
filterTreeNode: filterTreeNode,
|
|
916
|
+
popupMatchSelectWidth: menuWidth ? menuWidth + 10 : undefined,
|
|
917
|
+
onSelect: (val, option) => {
|
|
918
|
+
onChange(val);
|
|
919
|
+
const formState = getValues();
|
|
920
|
+
// const itemState = getValues(dataIndex)
|
|
921
|
+
// @ts-ignore
|
|
922
|
+
const prevState = record[dataIndex];
|
|
923
|
+
const newState = val;
|
|
924
|
+
handleCellChange?.({
|
|
925
|
+
key,
|
|
926
|
+
field: column.field,
|
|
927
|
+
record: formState,
|
|
928
|
+
prevState,
|
|
929
|
+
newState,
|
|
930
|
+
option: option,
|
|
931
|
+
indexCol,
|
|
932
|
+
indexRow,
|
|
933
|
+
type: 'blur'
|
|
934
|
+
});
|
|
935
|
+
},
|
|
936
|
+
popupClassName: 'be-popup-container',
|
|
937
|
+
status: isInvalid ? 'error' : undefined,
|
|
938
|
+
"data-tooltip-content": message,
|
|
939
|
+
"data-tooltip-id": `${tableId}-tooltip-error`
|
|
940
|
+
});
|
|
941
|
+
case 'checkbox':
|
|
942
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
943
|
+
style: {
|
|
944
|
+
display: 'flex',
|
|
945
|
+
alignItems: 'center',
|
|
946
|
+
justifyContent: column.align ?? 'center',
|
|
947
|
+
paddingInline: 5,
|
|
948
|
+
height: '100%',
|
|
949
|
+
width: '100%'
|
|
950
|
+
}
|
|
951
|
+
}, /*#__PURE__*/React.createElement(Checkbox, {
|
|
952
|
+
checked: Boolean(value)
|
|
953
|
+
// style={{ textAlign: column.align ?? 'left' }}
|
|
954
|
+
,
|
|
955
|
+
onChange: val => {
|
|
956
|
+
const newVal = typeof value === "number" ? parseBooleanToValue(val.target.checked, typeof value) : val.target.checked;
|
|
957
|
+
onChange(newVal);
|
|
958
|
+
const formState = getValues();
|
|
959
|
+
handleCellChange?.({
|
|
960
|
+
key,
|
|
961
|
+
record: formState,
|
|
962
|
+
option: value,
|
|
963
|
+
prevState: value,
|
|
964
|
+
newState: newVal,
|
|
965
|
+
field: column.field ?? column.field,
|
|
966
|
+
indexCol,
|
|
967
|
+
indexRow,
|
|
968
|
+
type: 'blur'
|
|
969
|
+
});
|
|
970
|
+
},
|
|
971
|
+
disabled: isDisable(column, record) ?? false
|
|
972
|
+
}));
|
|
973
|
+
case 'form':
|
|
974
|
+
const valueForm = value;
|
|
975
|
+
return /*#__PURE__*/React.createElement(EditForm, {
|
|
976
|
+
rowData: record,
|
|
977
|
+
column: column,
|
|
978
|
+
t: t,
|
|
979
|
+
id: `col${indexCol}-record${indexRow}`,
|
|
980
|
+
value: valueForm,
|
|
981
|
+
fieldKey: column.editFromSettings?.fieldKey,
|
|
982
|
+
indexRow: indexRow
|
|
983
|
+
|
|
984
|
+
// cellFocus={column.field === cellEditing?.column.field}
|
|
985
|
+
,
|
|
986
|
+
|
|
987
|
+
onChange: val => {
|
|
988
|
+
const formState = getValues();
|
|
989
|
+
|
|
990
|
+
// @ts-ignore
|
|
991
|
+
const prevState = record[dataIndex];
|
|
992
|
+
const newState = val;
|
|
993
|
+
handleCellChange?.({
|
|
994
|
+
key,
|
|
995
|
+
field: column.field,
|
|
996
|
+
record: {
|
|
997
|
+
...formState,
|
|
998
|
+
[column.field ?? '']: val
|
|
999
|
+
},
|
|
1000
|
+
prevState,
|
|
1001
|
+
newState,
|
|
1002
|
+
option: val,
|
|
1003
|
+
indexCol,
|
|
1004
|
+
indexRow,
|
|
1005
|
+
type: 'blur'
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
// cellEditing={cellEditing}
|
|
1009
|
+
|
|
1010
|
+
// menuPortalTarget={tableContainerRef}
|
|
1011
|
+
// classNamePrefix={column.classElement ?? 'select'}
|
|
1012
|
+
,
|
|
1013
|
+
placeholder: t ? t(column.placeholder ? column.placeholder : '') : column.placeholder ? column.placeholder : '',
|
|
1014
|
+
menuWidth: column.editFromSettings?.menuWidth,
|
|
1015
|
+
menuHeight: column.editFromSettings?.menuHeight
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
// case 'file':
|
|
1019
|
+
// const valueFile = record[dataIndex]
|
|
1020
|
+
// return (
|
|
1021
|
+
//
|
|
1022
|
+
//
|
|
1023
|
+
// <InputFile
|
|
1024
|
+
// value={valueFile}
|
|
1025
|
+
// uploading={column.uploading}
|
|
1026
|
+
// allowedExtensions={column.allowedExtensions}
|
|
1027
|
+
// asyncUploadSettings={column.asyncUploadSettings}
|
|
1028
|
+
// disable={isDisable(col, record)}
|
|
1029
|
+
// onChange={(val: string) => {
|
|
1030
|
+
//
|
|
1031
|
+
// const newValue = Array.isArray(val) ? val.map((it: any) => it) : val
|
|
1032
|
+
// const newrecordData = {
|
|
1033
|
+
// ...record,
|
|
1034
|
+
// [dataIndex]: newValue
|
|
1035
|
+
// }
|
|
1036
|
+
// handleCellChange(val, newValue, newrecordData, col, indexRow, indexCol)
|
|
1037
|
+
// }}
|
|
1038
|
+
//
|
|
1039
|
+
//
|
|
1040
|
+
// />
|
|
1041
|
+
//
|
|
1042
|
+
//
|
|
1043
|
+
// )
|
|
1044
|
+
|
|
1045
|
+
case 'color':
|
|
1046
|
+
const color = isColor(value) ? value : '#ffffff';
|
|
1047
|
+
const presets = genPresets({
|
|
1048
|
+
blue,
|
|
1049
|
+
red,
|
|
1050
|
+
green,
|
|
1051
|
+
cyan
|
|
1052
|
+
});
|
|
1053
|
+
return /*#__PURE__*/React.createElement(ColorPicker, {
|
|
1054
|
+
value: color,
|
|
1055
|
+
allowClear: column.isClearable ?? true,
|
|
1056
|
+
onChangeComplete: valueColor => {
|
|
1057
|
+
onChange(`#${valueColor.toHex()}`);
|
|
1058
|
+
const formState = getValues();
|
|
1059
|
+
handleCellChange?.({
|
|
1060
|
+
key,
|
|
1061
|
+
field,
|
|
1062
|
+
option: `#${valueColor.toHex()}`,
|
|
1063
|
+
record: formState,
|
|
1064
|
+
prevState: value,
|
|
1065
|
+
newState: `#${valueColor.toHex()}`,
|
|
1066
|
+
indexCol,
|
|
1067
|
+
indexRow,
|
|
1068
|
+
type: 'blur'
|
|
1069
|
+
});
|
|
1070
|
+
},
|
|
1071
|
+
presets: presets,
|
|
1072
|
+
panelRender: (_, {
|
|
1073
|
+
components: {
|
|
1074
|
+
Picker,
|
|
1075
|
+
Presets
|
|
1076
|
+
}
|
|
1077
|
+
}) => /*#__PURE__*/React.createElement(Row, {
|
|
1078
|
+
justify: "space-between",
|
|
1079
|
+
wrap: false,
|
|
1080
|
+
className: "custom-panel be-popup-container"
|
|
1081
|
+
}, /*#__PURE__*/React.createElement(Col, {
|
|
1082
|
+
span: 12
|
|
1083
|
+
}, /*#__PURE__*/React.createElement(Presets, null)), /*#__PURE__*/React.createElement(Divider, {
|
|
1084
|
+
type: "vertical",
|
|
1085
|
+
style: {
|
|
1086
|
+
height: 'auto'
|
|
1087
|
+
}
|
|
1088
|
+
}), /*#__PURE__*/React.createElement(Col, {
|
|
1089
|
+
flex: "auto"
|
|
1090
|
+
}, /*#__PURE__*/React.createElement(Picker, null)))
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
// case 'image':
|
|
1094
|
+
// let image = record[dataIndex]
|
|
1095
|
+
// return (
|
|
1096
|
+
// <ImageUpload
|
|
1097
|
+
// id={`col${indexCol}-record${indexRow}`}
|
|
1098
|
+
// defaultImage={image}
|
|
1099
|
+
// width={column.width}
|
|
1100
|
+
// height={38}
|
|
1101
|
+
// onKeyDown={(val: any, path: string) => {
|
|
1102
|
+
// const checkKey = checkKeyDown(val, col, indexRow + 1, indexCol + 1)
|
|
1103
|
+
// if (checkKey === 'ArrecordDown' || checkKey === 'ArrecordUp' || checkKey === 'Enter') {
|
|
1104
|
+
// let newVal = ''
|
|
1105
|
+
// if (newVal != record[dataIndex]) {
|
|
1106
|
+
// record[dataIndex] = path
|
|
1107
|
+
// // handleDataChange(path, record, col, indexRow, indexCol)
|
|
1108
|
+
// handleCellChange(path, record, col, indexRow, indexCol)
|
|
1109
|
+
// }
|
|
1110
|
+
// }
|
|
1111
|
+
// }}
|
|
1112
|
+
// />
|
|
1113
|
+
// )
|
|
1114
|
+
|
|
1115
|
+
case 'numeric':
|
|
1116
|
+
const thousandSeparator = cellFormat?.thousandSeparator;
|
|
1117
|
+
const decimalSeparator = cellFormat?.decimalSeparator;
|
|
1118
|
+
|
|
1119
|
+
// let floatValue = value
|
|
1120
|
+
|
|
1121
|
+
const numericFormatProps = {
|
|
1122
|
+
value,
|
|
1123
|
+
thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
|
|
1124
|
+
decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
|
|
1125
|
+
decimalScale: cellFormat?.decimalScale ?? undefined,
|
|
1126
|
+
fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false,
|
|
1127
|
+
allowNegative: cellFormat?.allowNegative ?? true,
|
|
1128
|
+
prefix: cellFormat?.prefix ?? undefined,
|
|
1129
|
+
suffix: cellFormat?.suffix ?? undefined
|
|
1130
|
+
};
|
|
1131
|
+
return /*#__PURE__*/React.createElement(NumericFormat, _extends({
|
|
1132
|
+
id: `col${indexCol}-record${indexRow}`
|
|
1133
|
+
}, numericFormatProps, {
|
|
1134
|
+
min: column.min,
|
|
1135
|
+
max: column.max,
|
|
1136
|
+
customInput: Input
|
|
1137
|
+
// valueIsNumericString={true}
|
|
1138
|
+
,
|
|
1139
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : tableLocal?.textPlaceholder,
|
|
1140
|
+
autoComplete: 'off',
|
|
1141
|
+
className: classNames('be-cell-editing rounded-0 input-element', {
|
|
1142
|
+
'is-invalid': isInvalid,
|
|
1143
|
+
'be-cell-edit-align-center': column.align === 'center',
|
|
1144
|
+
'be-cell-edit-align-left': column.align === 'left',
|
|
1145
|
+
'be-cell-edit-align-right': !column.align || column.align === 'right'
|
|
1146
|
+
}),
|
|
1147
|
+
autoFocus: column.field === startCell?.colId,
|
|
1148
|
+
onValueChange: values => {
|
|
1149
|
+
onChange(values?.floatValue || 0);
|
|
1150
|
+
},
|
|
1151
|
+
onBlur: () => {
|
|
1152
|
+
const formState = getValues();
|
|
1153
|
+
const itemState = getValues(dataIndex);
|
|
1154
|
+
|
|
1155
|
+
// @ts-ignore
|
|
1156
|
+
const prevState = record[dataIndex];
|
|
1157
|
+
const newState = value;
|
|
1158
|
+
// @ts-ignore
|
|
1159
|
+
if (itemState !== record[dataIndex]) {
|
|
1160
|
+
handleCellChange?.({
|
|
1161
|
+
key: key,
|
|
1162
|
+
field,
|
|
1163
|
+
option: newState,
|
|
1164
|
+
record: formState,
|
|
1165
|
+
prevState,
|
|
1166
|
+
newState,
|
|
1167
|
+
indexCol,
|
|
1168
|
+
indexRow,
|
|
1169
|
+
type: 'blur'
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
},
|
|
1173
|
+
"data-tooltip-content": message,
|
|
1174
|
+
"data-tooltip-id": `${tableId}-tooltip-error`
|
|
1175
|
+
}));
|
|
1176
|
+
default:
|
|
1177
|
+
return /*#__PURE__*/React.createElement(TextArea, {
|
|
1178
|
+
id: `col${indexCol}-record${indexRow}`,
|
|
1179
|
+
style: {
|
|
1180
|
+
textAlign: column.align,
|
|
1181
|
+
resize: 'none',
|
|
1182
|
+
height: '100%'
|
|
1183
|
+
},
|
|
1184
|
+
disabled: isDisable(column, record) ?? false,
|
|
1185
|
+
className: classNames('be-cell-editing rounded-0 input-element'),
|
|
1186
|
+
placeholder: t && column.placeholder ? t(column.placeholder) : tableLocal?.textPlaceholder,
|
|
1187
|
+
value: !isNullOrUndefined(value) ? value : '',
|
|
1188
|
+
onBlur: () => {
|
|
1189
|
+
const formState = getValues();
|
|
1190
|
+
// const itemState = getValues(dataIndex)
|
|
1191
|
+
|
|
1192
|
+
// @ts-ignore
|
|
1193
|
+
const prevState = record[dataIndex];
|
|
1194
|
+
const newState = value;
|
|
1195
|
+
if (newState !== prevState) {
|
|
1196
|
+
handleCellChange?.({
|
|
1197
|
+
key: key,
|
|
1198
|
+
record: formState,
|
|
1199
|
+
option: value,
|
|
1200
|
+
prevState,
|
|
1201
|
+
newState,
|
|
1202
|
+
field,
|
|
1203
|
+
indexCol,
|
|
1204
|
+
indexRow,
|
|
1205
|
+
type: 'blur'
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
},
|
|
1209
|
+
onPressEnter: () => {
|
|
1210
|
+
const formState = getValues();
|
|
1211
|
+
const newState = getValues(dataIndex);
|
|
1212
|
+
// @ts-ignore
|
|
1213
|
+
const prevState = record[dataIndex];
|
|
1214
|
+
|
|
1215
|
+
// @ts-ignore
|
|
1216
|
+
|
|
1217
|
+
handleCellChange?.({
|
|
1218
|
+
key: key,
|
|
1219
|
+
newState,
|
|
1220
|
+
prevState,
|
|
1221
|
+
record: formState,
|
|
1222
|
+
indexCol,
|
|
1223
|
+
indexRow,
|
|
1224
|
+
type: 'enter'
|
|
1225
|
+
});
|
|
1226
|
+
// }
|
|
1227
|
+
},
|
|
1228
|
+
onChange: onChange,
|
|
1229
|
+
status: isInvalid ? 'error' : undefined,
|
|
1230
|
+
"data-tooltip-content": message,
|
|
1231
|
+
"data-tooltip-id": `${tableId}-tooltip-error`,
|
|
1232
|
+
autoSize: {
|
|
1233
|
+
minRows: 1,
|
|
1234
|
+
maxRows: 1
|
|
1235
|
+
}
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
};
|
|
1239
|
+
return /*#__PURE__*/React.createElement("form", {
|
|
1240
|
+
onSubmit: handleSubmit(onSubmit)
|
|
1241
|
+
}, /*#__PURE__*/React.createElement(Controller, {
|
|
1242
|
+
name: dataIndex,
|
|
1243
|
+
control: control,
|
|
1244
|
+
render: ({
|
|
1245
|
+
field: {
|
|
1246
|
+
value,
|
|
1247
|
+
onChange
|
|
1248
|
+
}
|
|
1249
|
+
}) => inputNode(value, onChange)
|
|
1250
|
+
}));
|
|
1251
|
+
};
|
|
1252
|
+
export default EditCell;
|