es-grid-template 1.9.60 → 1.9.62

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.
Files changed (31) hide show
  1. package/es/ali-table/InternalTable.d.ts +2 -1
  2. package/es/ali-table/InternalTable.js +23 -43
  3. package/es/ali-table/base-table/table.d.ts +2 -2
  4. package/es/ali-table/base-table/utils.d.ts +2 -0
  5. package/es/ali-table/base-table/utils.js +12 -1
  6. package/es/ali-table/interfaces.d.ts +4 -0
  7. package/es/ali-table/internals.d.ts +2 -1
  8. package/es/ali-table/pipeline/features/columnCustom.d.ts +1 -0
  9. package/es/ali-table/pipeline/features/columnCustom.js +297 -17
  10. package/es/grid-component/type.d.ts +2 -1
  11. package/es/group-component/body/EditableCell.d.ts +3 -0
  12. package/es/group-component/body/EditableCell.js +402 -196
  13. package/es/table-component/body/EditableCell.js +1 -1
  14. package/es/table-component/components/async-select/index.js +1 -1
  15. package/es/table-component/hook/utils.d.ts +1 -3
  16. package/lib/ali-table/InternalTable.d.ts +2 -1
  17. package/lib/ali-table/InternalTable.js +23 -43
  18. package/lib/ali-table/base-table/table.d.ts +2 -2
  19. package/lib/ali-table/base-table/utils.d.ts +2 -0
  20. package/lib/ali-table/base-table/utils.js +13 -0
  21. package/lib/ali-table/interfaces.d.ts +4 -0
  22. package/lib/ali-table/internals.d.ts +2 -1
  23. package/lib/ali-table/pipeline/features/columnCustom.d.ts +1 -0
  24. package/lib/ali-table/pipeline/features/columnCustom.js +297 -17
  25. package/lib/grid-component/type.d.ts +2 -1
  26. package/lib/group-component/body/EditableCell.d.ts +3 -0
  27. package/lib/group-component/body/EditableCell.js +399 -194
  28. package/lib/table-component/body/EditableCell.js +1 -1
  29. package/lib/table-component/components/async-select/index.js +1 -1
  30. package/lib/table-component/hook/utils.d.ts +1 -3
  31. package/package.json +1 -1
@@ -1,19 +1,23 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import React, { useContext } from "react";
3
- import { DatePicker, TimePicker, ColorPicker, Divider, Input, Row, Col } from "rc-master-ui";
4
- import { checkDecimalSeparator, checkThousandSeparator, checkFieldKey, convertArrayWithIndent, convertDateToDayjs, convertLabelToTitle, getDatepickerFormat, isDisable, isEmpty, isNullOrUndefined, customWeekStartEndFormat, convertDayjsToDate, parseBooleanToValue, isColor, genPresets, getFormat } from "../hook/utils";
3
+ import { DatePicker, TimePicker, ColorPicker, Input } from "rc-master-ui";
4
+ import { Divider, Row, Col, Button } from "rc-master-ui";
5
+ // import type { EditType } from "rc-master-ui"
6
+
7
+ import { checkDecimalSeparator, checkThousandSeparator, checkFieldKey, convertArrayWithIndent, convertDateToDayjs, convertLabelToTitle, getDatepickerFormat, isDisable, isEmpty, isNullOrUndefined, customWeekStartEndFormat, convertDayjsToDate, parseBooleanToValue, isColor, genPresets, getFormat, removeVietnameseTones, getDateValueType } from "../../table-component/hook/utils";
5
8
  import classNames from "classnames";
6
9
  import { NumericFormat } from "react-numeric-component";
7
10
  import dayjs from "dayjs";
8
11
  import moment from "moment";
9
12
  import { Controller } from "react-hook-form";
10
- import { Checkbox, TreeSelect, Select } from "rc-master-ui";
13
+ import { Checkbox, Select, TreeSelect } from "rc-master-ui";
11
14
  import { AsyncSelect } from "../components/async-select";
12
15
  import { AsyncTableSelect } from "../components/async-table-select";
13
16
  import { cyan, green, red, blue } from '@ant-design/colors';
14
17
  import { EditForm } from "../components/EditForm";
15
18
  import { TableContext } from "../useContext";
16
19
  import { useLocale } from "rc-master-ui/es/locale";
20
+ import { getTemplate } from "../../grid-component/hooks";
17
21
  const {
18
22
  SHOW_PARENT
19
23
  } = TreeSelect;
@@ -41,7 +45,9 @@ const EditableCell = props => {
41
45
  // children,
42
46
  column,
43
47
  indexRow,
44
- indexCol
48
+ indexCol,
49
+ // visibleColumns,
50
+ handleNextCell
45
51
  // cellEditing,
46
52
  // ...restProps
47
53
  } = props;
@@ -59,8 +65,7 @@ const EditableCell = props => {
59
65
  } = useContext(TableContext);
60
66
  const datePickerRef = React.useRef(null);
61
67
  const dateTimePickerRef = React.useRef(null);
62
- // const timePickerRef = React.useRef(null);
63
-
68
+ const timePickerRef = React.useRef(null);
64
69
  const colFormat = typeof column?.format === 'function' ? column?.format(record) : column?.format;
65
70
  const cellFormat = getFormat(colFormat, format);
66
71
  const inputNode = (value, onChange) => {
@@ -68,6 +73,7 @@ const EditableCell = props => {
68
73
  const date = !isEmpty(value) ? convertDateToDayjs(new Date(value), dateFormat) : null;
69
74
  const maxDate = convertDateToDayjs(column.maxDate, dateFormat) ?? undefined;
70
75
  const minDate = convertDateToDayjs(column.minDate, dateFormat) ?? undefined;
76
+ const formValues = getValues();
71
77
  const {
72
78
  fieldValue,
73
79
  columns: selectColumns,
@@ -77,8 +83,9 @@ const EditableCell = props => {
77
83
  fieldNames,
78
84
  toolbarItems,
79
85
  filterOption,
86
+ filterKey,
80
87
  inputKey,
81
- // toolbarClick,
88
+ toolbarClick,
82
89
  loadOptions,
83
90
  validateOption,
84
91
  options: propsOptions
@@ -96,7 +103,24 @@ const EditableCell = props => {
96
103
  const options = validateOption ? validateOption(record, column.field) : selectOptions ?? [];
97
104
  const optionsTree = validateOption ? convertArrayWithIndent(validateOption(record, column.field)) : selectOptions ? convertArrayWithIndent(selectOptions) : [];
98
105
 
99
- // const currt = flatColumns2()
106
+ // const focusToken = (token: FormatToken, fmt: string) => {
107
+ // const input: HTMLInputElement | null =
108
+ // timePickerRef.current?.nativeElement?.querySelector('input') ??
109
+ // timePickerRef.current?.input;
110
+
111
+ // if (!input) return;
112
+
113
+ // const start = fmt.indexOf(token);
114
+ // if (start === -1) return;
115
+
116
+ // input.focus();
117
+
118
+ // input.setSelectionRange(start, start + token.length - 1);
119
+
120
+ // requestAnimationFrame(() => {
121
+ // input.setSelectionRange(start, start + token.length);
122
+ // });
123
+ // };
100
124
 
101
125
  switch (editType) {
102
126
  case 'date':
@@ -107,10 +131,7 @@ const EditableCell = props => {
107
131
  type: 'mask'
108
132
  },
109
133
  autoFocus: column.field === startCell?.colId,
110
- defaultOpen: column.field === startCell?.colId
111
-
112
- // locale={buddhistLocale}
113
- ,
134
+ defaultOpen: column.field === startCell?.colId,
114
135
  style: {
115
136
  width: '100%',
116
137
  height: '100%'
@@ -164,9 +185,7 @@ const EditableCell = props => {
164
185
  format: {
165
186
  format: dateFormat,
166
187
  type: 'mask'
167
- }
168
- // locale={buddhistLocale}
169
- ,
188
+ },
170
189
  style: {
171
190
  width: '100%',
172
191
  height: '100%'
@@ -178,8 +197,20 @@ const EditableCell = props => {
178
197
  placeholder: t && column.placeholder ? t(column.placeholder) : undefined,
179
198
  disabled: isDisable(column, record) ?? false,
180
199
  maxDate: maxDate,
181
- minDate: minDate,
182
- onChange: (newDate, dateString) => {
200
+ minDate: minDate
201
+ // mode="date"
202
+ ,
203
+
204
+ popupClassName: 'be-popup-container',
205
+ status: isInvalid ? 'error' : undefined,
206
+ "data-tooltip-content": message,
207
+ "data-tooltip-id": `${id}-tooltip-error`,
208
+ autoFocus: column.field === startCell?.colId,
209
+ defaultOpen: column.field === startCell?.colId
210
+ // needConfirm={true}
211
+ ,
212
+
213
+ onCalendarChange: (newDate, dateString) => {
183
214
  const newDateValue = dateString ? moment(convertDayjsToDate(dateString, dateFormat)).format() : null;
184
215
  onChange(newDateValue);
185
216
  setTimeout(() => {
@@ -187,32 +218,28 @@ const EditableCell = props => {
187
218
  dateTimePickerRef.current?.focus();
188
219
  }, 0);
189
220
  },
190
- onBlur: () => {
191
- const formState = getValues();
192
- const itemState = getValues(dataIndex);
193
- // @ts-ignore
194
- const prevState = record[dataIndex];
195
- const newState = itemState;
196
- if (prevState !== newState) {
197
- handleCellChange?.({
198
- key: key,
199
- field: column.field ?? column.field,
200
- record: formState,
201
- prevState,
202
- newState,
203
- option: newState,
204
- indexCol,
205
- indexRow,
206
- type: 'blur'
207
- });
221
+ onOpenChange: open => {
222
+ if (!open) {
223
+ const formState = getValues();
224
+ const itemState = getValues(dataIndex);
225
+ // @ts-ignore
226
+ const prevState = record[dataIndex];
227
+ const newState = itemState;
228
+ if (prevState !== newState) {
229
+ handleCellChange?.({
230
+ key: key,
231
+ field: column.field ?? column.field,
232
+ record: formState,
233
+ prevState,
234
+ newState,
235
+ option: newState,
236
+ indexCol,
237
+ indexRow,
238
+ type: 'blur'
239
+ });
240
+ }
208
241
  }
209
- },
210
- popupClassName: 'be-popup-container',
211
- status: isInvalid ? 'error' : undefined,
212
- "data-tooltip-content": message,
213
- "data-tooltip-id": `${id}-tooltip-error`,
214
- autoFocus: column.field === startCell?.colId,
215
- defaultOpen: column.field === startCell?.colId
242
+ }
216
243
  });
217
244
  case 'month':
218
245
  case 'quarter':
@@ -266,7 +293,17 @@ const EditableCell = props => {
266
293
  });
267
294
  case 'time':
268
295
  const timeFormat = getDatepickerFormat(editType, cellFormat);
269
- const time = value ? dayjs(value, timeFormat) : null;
296
+
297
+ // chỉ nhận giá trị dạng HH:mm | mm:HH => convert
298
+
299
+ let time = value ?? undefined;
300
+ const typeTime = getDateValueType(value);
301
+ if (typeTime === 'time') {
302
+ time = value ? dayjs(value, timeFormat) : undefined;
303
+ } else {
304
+ const abc = value ? moment(value).format(timeFormat) : undefined;
305
+ time = abc ? dayjs(abc, timeFormat) : undefined;
306
+ }
270
307
  const maxTimeValue = !isEmpty(column.maxTime) ? dayjs(column.maxTime).format(timeFormat) : null;
271
308
  const minTimeValue = !isEmpty(column.minTime) ? dayjs(column.minTime).format(timeFormat) : null;
272
309
 
@@ -275,6 +312,7 @@ const EditableCell = props => {
275
312
  const maxTime = maxTimeValue ? dayjs(maxTimeValue, timeFormat) : undefined;
276
313
  const minTime = minTimeValue ? dayjs(minTimeValue, timeFormat) : undefined;
277
314
  return /*#__PURE__*/React.createElement(TimePicker, {
315
+ ref: timePickerRef,
278
316
  format: {
279
317
  format: timeFormat,
280
318
  type: 'mask'
@@ -295,33 +333,119 @@ const EditableCell = props => {
295
333
  "data-tooltip-content": message,
296
334
  "data-tooltip-id": `${id}-tooltip-error`,
297
335
  autoFocus: column.field === startCell?.colId,
298
- defaultOpen: column.field === startCell?.colId,
299
- onChange: (newDate, dateString) => {
336
+ defaultOpen: column.field === startCell?.colId
337
+
338
+ // onChange={(newDate, dateString) => {
339
+
340
+ // if (typeTime === 'time') {
341
+
342
+ // onChange(dateString)
343
+
344
+ // } else {
345
+
346
+ // // const datetime = dayjs(dateString as string, timeFormat, true);
347
+
348
+ // const newVal = newDate ? moment(newDate.toDate()).format() : undefined
349
+
350
+ // // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
351
+ // onChange(newVal)
352
+
353
+ // }
354
+
355
+ // setTimeout(() => {
356
+ // // @ts-ignore
357
+ // dateTimePickerRef.current?.focus()
358
+ // }, 0)
359
+
360
+ // }}
361
+
362
+ // onBlur={() => {
363
+ // const formState = getValues()
364
+ // const itemState = getValues(dataIndex)
365
+ // // @ts-ignore
366
+ // const prevState = record[dataIndex]
367
+ // const newState = itemState
368
+
369
+ // let newValue = newState
370
+
371
+ // if (typeTime === 'time') {
372
+
373
+ // newValue = newState
374
+
375
+ // } else {
376
+
377
+ // const datetime = dayjs(newState as string, timeFormat, true);
378
+
379
+ // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : undefined
380
+ // onChange(newVal)
381
+
382
+ // newValue = newVal
383
+
384
+ // }
385
+
386
+ // if (prevState !== newState) {
387
+ // handleCellChange?.({
388
+ // key: key as any,
389
+ // field: column.field ?? column.field as any,
390
+ // record: formState,
391
+ // prevState,
392
+ // newState: newValue,
393
+ // option: newValue,
394
+ // indexCol,
395
+ // indexRow,
396
+ // type: 'blur'
397
+ // })
398
+ // }
399
+ // }}
400
+
401
+ // needConfirm={false}
402
+ ,
403
+
404
+ onCalendarChange: (newDate, dateString) => {
300
405
  // const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
301
- onChange(dateString);
406
+
407
+ // onChange(newDateValue)
408
+
409
+ if (typeTime === 'time') {
410
+ onChange(dateString);
411
+ } else {
412
+ // const datetime = dayjs(dateString as string, timeFormat, true);
413
+
414
+ const newVal = newDate ? moment(newDate.toDate()).format() : undefined;
415
+
416
+ // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
417
+ onChange(newVal);
418
+ }
302
419
  setTimeout(() => {
303
420
  // @ts-ignore
304
- dateTimePickerRef.current?.focus();
305
- }, 0);
421
+ timePickerRef.current?.focus();
422
+ });
306
423
  },
307
- onBlur: () => {
308
- const formState = getValues();
309
- const itemState = getValues(dataIndex);
310
- // @ts-ignore
311
- const prevState = record[dataIndex];
312
- const newState = itemState;
313
- if (prevState !== newState) {
314
- handleCellChange?.({
315
- key: key,
316
- field: column.field ?? column.field,
317
- record: formState,
318
- prevState,
319
- newState,
320
- option: newState,
321
- indexCol,
322
- indexRow,
323
- type: 'blur'
324
- });
424
+ onOpenChange: open => {
425
+ if (!open) {
426
+ const formState = getValues();
427
+ const itemState = getValues(dataIndex);
428
+ // @ts-ignore
429
+ const prevState = record[dataIndex];
430
+ const newState = itemState;
431
+ if (prevState !== newState) {
432
+ handleCellChange?.({
433
+ key: key,
434
+ field: column.field ?? column.field,
435
+ record: formState,
436
+ prevState,
437
+ newState,
438
+ option: newState,
439
+ indexCol,
440
+ indexRow,
441
+ type: 'blur'
442
+ });
443
+ }
444
+ }
445
+ },
446
+ onKeyDown: e => {
447
+ if (e?.code === "Tab") {
448
+ handleNextCell?.();
325
449
  }
326
450
  }
327
451
  });
@@ -345,37 +469,31 @@ const EditableCell = props => {
345
469
  align: colSelect.textAlign
346
470
  };
347
471
  });
348
- let valueSelectTable = value;
472
+ let valueSelectTable = formValues[dataIndex];
349
473
  if (fieldValue) {
350
474
  // @ts-ignore
351
- valueSelectTable = record[fieldValue] ?? value;
475
+ valueSelectTable = record[fieldValue] ?? formValues[dataIndex];
352
476
  }
353
-
354
- // if (isMulti || selectMode === 'checkbox') {
355
- // // @ts-ignore
356
- // valueSelectTable = (!isNullOrUndefined(record[dataIndex]) && Array.isArray(record[dataIndex]) && record[dataIndex]?.length > 0) ? options.filter((val: any) => record[dataIndex]?.includes(val[keySelect])) : undefined
357
-
358
- // }
359
-
360
477
  return /*#__PURE__*/React.createElement(AsyncTableSelect, {
361
478
  columns: columnsTable,
362
479
  options: options,
363
480
  defaultOptions: options,
364
481
  value: valueSelectTable ?? undefined,
365
- rowData: record,
366
482
  autoDestroy: true,
367
483
  onChange: (val, option) => {
368
- onChange(val);
484
+ onChange(val ?? '');
369
485
  const formState = getValues();
370
- // const itemState = getValues(dataIndex)
486
+ const formNewState = {
487
+ ...getValues(),
488
+ [dataIndex]: !isNullOrUndefined(formState[dataIndex]) ? formState[dataIndex] : undefined
489
+ };
371
490
  // @ts-ignore
372
- const prevState = record[dataIndex];
373
- const newState = val;
491
+ const prevState = record[dataIndex] ?? undefined;
492
+ const newState = val ?? undefined;
374
493
  handleCellChange?.({
375
- // @ts-ignore
376
- key: record[rowKey],
494
+ key,
377
495
  field: column.field ?? column.field,
378
- record: formState,
496
+ record: formNewState,
379
497
  prevState,
380
498
  newState,
381
499
  option: option,
@@ -405,71 +523,123 @@ const EditableCell = props => {
405
523
  status: isInvalid ? 'error' : undefined,
406
524
  dropdownRender: menu => {
407
525
  if (toolbarItems && toolbarItems.length > 0) {
408
- return /*#__PURE__*/React.createElement(React.Fragment, null, menu, /*#__PURE__*/React.createElement(Divider, {
526
+ return /*#__PURE__*/React.createElement(React.Fragment, null, menu, toolbarItems && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, {
409
527
  style: {
410
528
  margin: '8px 0'
411
529
  }
412
530
  }), /*#__PURE__*/React.createElement("div", {
413
531
  className: 'toolbar-control d-flex justify-content-end'
414
- }));
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
+ }))));
415
544
  } else {
416
545
  return /*#__PURE__*/React.createElement(React.Fragment, null, " ", menu);
417
546
  }
418
547
  },
419
- filterOption: filterOption,
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,
420
556
  fieldNames: fieldNames ? fieldNames : {
421
557
  value: keySelect,
422
558
  label: inputKey ?? 'label'
423
- },
424
- onBlur: event => {
425
- if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
426
- const val = event.inputValue;
427
- onChange(val);
428
- const formState = getValues();
429
- // const itemState = getValues(dataIndex)
430
- // @ts-ignore
431
- const prevState = record[dataIndex];
432
- const newState = val;
433
- handleCellChange?.({
434
- key,
435
- field: column.field ?? column.field,
436
- record: formState,
437
- prevState,
438
- newState,
439
- option: {
440
- value: val,
441
- label: val,
442
- searchTextAsValue: true
443
- },
444
- indexCol,
445
- indexRow,
446
- type: 'blur'
447
- });
448
- }
449
- },
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
+
450
617
  "data-tooltip-content": message,
451
618
  "data-tooltip-id": `${id}-tooltip-error`
452
619
  });
453
620
  case 'select':
454
- let valueSelect = value;
621
+ let valueSelect = formValues[dataIndex];
455
622
  if (fieldValue) {
456
623
  // @ts-ignore
457
- valueSelect = record[fieldValue] ?? value;
624
+ valueSelect = record[fieldValue] ?? formValues[dataIndex];
458
625
  }
459
626
  return /*#__PURE__*/React.createElement(Select, {
460
627
  options: options,
461
- value: valueSelect ?? undefined,
628
+ value: valueSelect ?? '',
462
629
  onChange: (val, option) => {
463
- onChange(val);
630
+ onChange(val ?? '');
464
631
  const formState = getValues();
465
- // const itemState = getValues(dataIndex)
632
+ const formNewState = {
633
+ ...getValues(),
634
+ [dataIndex]: !isNullOrUndefined(formState[dataIndex]) ? formState[dataIndex] : undefined
635
+ };
466
636
  // @ts-ignore
467
- const prevState = record[dataIndex];
468
- const newState = val;
637
+ const prevState = record[dataIndex] ?? undefined;
638
+ const newState = val ?? undefined;
469
639
  handleCellChange?.({
470
640
  key,
471
641
  field: column.field ?? column.field,
472
- record: formState,
642
+ record: formNewState,
473
643
  prevState,
474
644
  newState,
475
645
  option: option,
@@ -478,6 +648,8 @@ const EditableCell = props => {
478
648
  type: 'blur'
479
649
  });
480
650
  }
651
+ // destroyOnHidden
652
+ // des
481
653
  // autoDestroy={true}
482
654
  ,
483
655
  showSearch: true,
@@ -496,8 +668,16 @@ const EditableCell = props => {
496
668
  optionFilterProp: "label",
497
669
  popupClassName: 'be-popup-container',
498
670
  status: isInvalid ? 'error' : undefined,
499
- filterOption: filterOption,
500
- fieldNames: fieldNames ? fieldNames : {
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: {
501
681
  value: keySelect,
502
682
  label: inputKey ?? 'label'
503
683
  },
@@ -527,30 +707,83 @@ const EditableCell = props => {
527
707
  });
528
708
  }
529
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
+ },
530
760
  "data-tooltip-content": message,
531
761
  "data-tooltip-id": `${id}-tooltip-error`
532
762
  });
533
763
  case 'asyncSelect':
534
- let valueAsyncSelect = value;
764
+ let valueAsyncSelect = formValues[dataIndex];
535
765
  if (fieldValue) {
536
766
  // @ts-ignore
537
- valueAsyncSelect = record[fieldValue] ?? value;
767
+ valueAsyncSelect = record[fieldValue] ?? formValues[dataIndex];
538
768
  }
539
769
  return /*#__PURE__*/React.createElement(AsyncSelect, {
540
770
  options: options,
541
771
  defaultOptions: options,
542
772
  value: valueAsyncSelect ?? undefined,
543
773
  onChange: (val, option) => {
544
- onChange(val);
774
+ onChange(val ?? '');
545
775
  const formState = getValues();
546
- // const itemState = getValues(dataIndex)
776
+ const formNewState = {
777
+ ...getValues(),
778
+ [dataIndex]: !isNullOrUndefined(formState[dataIndex]) ? formState[dataIndex] : undefined
779
+ };
547
780
  // @ts-ignore
548
- const prevState = record[dataIndex];
549
- const newState = val;
781
+ const prevState = record[dataIndex] ?? undefined;
782
+ const newState = val ?? undefined;
550
783
  handleCellChange?.({
551
784
  key,
552
785
  field: column.field ?? column.field,
553
- record: formState,
786
+ record: formNewState,
554
787
  prevState,
555
788
  newState,
556
789
  option: option,
@@ -577,46 +810,40 @@ const EditableCell = props => {
577
810
  optionFilterProp: "label",
578
811
  popupClassName: 'be-popup-container',
579
812
  loadOptions: loadOptions,
580
- status: isInvalid ? 'error' : undefined
581
- // dropdownRender={(menu) => {
582
- // if (toolbarItems && toolbarItems.length > 0) {
583
- // return (
584
- // <>
585
- // {menu}
586
- // <Divider style={{margin: '8px 0'}}/>
587
- //
588
- // <div
589
- // className={'toolbar-control d-flex justify-content-end'}
590
- // >
591
- // {toolbarItems.map((it) => {
592
- // return (
593
- // <div
594
- // key={it.key}
595
- // className={'toolbar-item'}
596
- // onClick={() => toolbarClick?.({item: it, column})}
597
- // >
598
- // {it.template ? getTemplate(it.template) : (
599
- // <Button className='toolbar-item-btn'>
600
- //
601
- // {it.icon && getTemplate(it.icon)}
602
- // {it.title}
603
- // </Button>
604
- // )}
605
- //
606
- // </div>
607
- // )
608
- // })}
609
- //
610
- // </div>
611
- // </>
612
- // )
613
- // } else {
614
- // return <> {menu}</>
615
- // }
616
- //
617
- // }}
618
- ,
619
- filterOption: filterOption,
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,
620
847
  fieldNames: fieldNames ? fieldNames : {
621
848
  value: keySelect,
622
849
  label: inputKey ?? 'label'
@@ -651,24 +878,12 @@ const EditableCell = props => {
651
878
  "data-tooltip-id": `${id}-tooltip-error`
652
879
  });
653
880
  case 'treeSelect':
654
- // let valueTreeSelect
655
-
656
881
  const newTreeData = convertLabelToTitle(optionsTree);
657
- // @ts-ignore
658
- // const valueTreeSelect = column?.editSelectSettings?.isMulti ? (Array.isArray(record[dataIndex]) ? record[dataIndex] : []) : record[dataIndex]
659
-
660
882
  let valueTreeSelect = value;
661
883
  if (fieldValue) {
662
884
  // @ts-ignore
663
885
  valueTreeSelect = record[fieldValue] ?? value;
664
886
  }
665
-
666
- // if (isMulti || selectMode === 'checkbox') {
667
- // // @ts-ignore
668
- // valueTreeSelect = (!isNullOrUndefined(record[dataIndex]) && Array.isArray(record[dataIndex]) && record[dataIndex]?.length > 0) ? options.filter((val: any) => record[dataIndex]?.includes(val[keySelect])) : undefined
669
-
670
- // }
671
-
672
887
  return /*#__PURE__*/React.createElement(TreeSelect, {
673
888
  id: `col${indexCol}-record${indexRow}`,
674
889
  className: 'be-tree-select',
@@ -681,21 +896,14 @@ const EditableCell = props => {
681
896
  maxHeight: 400,
682
897
  overflow: 'auto'
683
898
  },
684
- treeData: newTreeData
685
- // placeholder={t ? t(column.placeholder ?? 'Select') : (column.placeholder ?? 'Select')}
686
- ,
687
- placeholder: t && column?.placeholder ? t(column.placeholder) : tableLocal?.selectPlaceholder,
899
+ treeData: newTreeData,
900
+ placeholder: t && column.placeholder ? t(column.placeholder) : tableLocal?.selectPlaceholder,
688
901
  treeDefaultExpandAll: true,
689
902
  defaultOpen: column.field === startCell?.colId,
690
- autoFocus: column.field === startCell?.colId
691
-
692
- // defaultOpen={column.field === cellEditing?.column.field}
693
- ,
903
+ autoFocus: column.field === startCell?.colId,
694
904
  virtual: true,
695
905
  allowClear: true,
696
- showSearch: true
697
- // maxTagTextLength={column?.editSelectSettings?.showItems}
698
- ,
906
+ showSearch: true,
699
907
  maxTagCount: column?.editSelectSettings?.showItems,
700
908
  maxTagPlaceholder: 2,
701
909
  treeTitleRender: column?.editSelectSettings?.formatOptionLabel,
@@ -911,7 +1119,7 @@ const EditableCell = props => {
911
1119
  // let floatValue = value
912
1120
 
913
1121
  const numericFormatProps = {
914
- value,
1122
+ value: value || '',
915
1123
  thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
916
1124
  decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
917
1125
  decimalScale: cellFormat?.decimalScale ?? undefined,
@@ -922,8 +1130,6 @@ const EditableCell = props => {
922
1130
  };
923
1131
  return /*#__PURE__*/React.createElement(NumericFormat, _extends({
924
1132
  id: `col${indexCol}-record${indexRow}`
925
- // value={value ? numericFormatter(value.toString(), numericFormatProps) : ''}
926
- // value={value}
927
1133
  }, numericFormatProps, {
928
1134
  min: column.min,
929
1135
  max: column.max,