es-grid-template 1.8.62 → 1.8.64

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.
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import React, { createContext, Fragment, useCallback, useContext, useState } from 'react';
3
3
  import 'react-resizable/css/styles.css';
4
4
  import customParseFormat from 'dayjs/plugin/customParseFormat';
5
- import { addRowIdArray, booleanOperator, convertFilters, convertFlatColumn, filterDataByColumns4, findItemByKey, findItemPath, flattenArray, getAllRowKey, getFormat, getTypeFilter, groupArrayByColumns, isNullOrUndefined, numberOperator, removeColumns, removeInvisibleColumns, stringOperator, sumByField, translateOption, unFlattenData, updateArrayByKey, updateColumnsByGroup,
5
+ import { addRowIdArray, booleanOperator, checkDecimalSeparator, checkThousandSeparator, convertFilters, convertFlatColumn, filterDataByColumns4, findItemByKey, findItemPath, flattenArray, getAllRowKey, getFormat, getTypeFilter, groupArrayByColumns, isNullOrUndefined, numberOperator, removeColumns, removeInvisibleColumns, stringOperator, sumByField, translateOption, unFlattenData, updateArrayByKey, updateColumnsByGroup,
6
6
  // updateData,
7
7
  updateOrInsert } from "./hooks";
8
8
  import ReactDOMServer from 'react-dom/server';
@@ -33,7 +33,7 @@ import classNames from "classnames";
33
33
  import HeaderContent from "./hooks/content/HeaderContent";
34
34
  import { ArrowDown, ArrowUp, FilterFill, SortCancel } from "becoxy-icons";
35
35
  import { Select } from "rc-master-ui";
36
- import { Button, Space, Modal } from "antd";
36
+ import { Button, Modal, Space } from "antd";
37
37
  import { SearchOutlined } from "@ant-design/icons";
38
38
  import { restrictToHorizontalAxis } from "@dnd-kit/modifiers";
39
39
  import { closestCenter, DndContext, DragOverlay, PointerSensor, useSensor, useSensors } from "@dnd-kit/core";
@@ -42,6 +42,9 @@ import { arrayMove, horizontalListSortingStrategy, SortableContext, useSortable
42
42
  import { Resizable } from "react-resizable";
43
43
  import { faker } from "@faker-js/faker";
44
44
  import useMergedState from "rc-util/es/hooks/useMergedState";
45
+ import { numericFormatter } from 'react-numeric-component';
46
+ // import Modal from 'antd/es/modal/Modal'
47
+
45
48
  dayjs.extend(customParseFormat);
46
49
  const MySwal = withReactContent(Swal);
47
50
  const ASCEND = 'ascend';
@@ -80,9 +83,6 @@ const ResizableTitle = props => {
80
83
  ...restProps
81
84
  } = props;
82
85
  const dragState = useContext(DragIndexContext);
83
-
84
- // const { attributes, listeners, setNodeRef, isDragging } = useSortable({ id: props.id });
85
-
86
86
  const style = {
87
87
  ...props.style,
88
88
  borderBottom: '1px solid #e0e0e0',
@@ -263,10 +263,10 @@ const InternalTable = props => {
263
263
  if (totalHeight) {
264
264
  const table = document.querySelector(`#${id}`);
265
265
  const title = table?.querySelector(`.ui-rc-table-title`);
266
+ const tableScrollRight = table?.querySelector(`.ui-rc-table-ping-right`);
266
267
  const paginationE = table?.querySelector(`.ui-rc-pagination`);
267
268
  const toolbar = table?.querySelector(`.ui-rc-toolbar-bottom`);
268
269
  const summaryE = table?.querySelector(`.ui-rc-table-summary`);
269
- const tableScrollRight = table?.querySelector(`.ui-rc-table-ping-right`);
270
270
  const hhh = (totalHeight ?? 0) - (title ? title.offsetHeight : 0) - (theadRef ? theadRef.current.clientHeight : 0) - (paginationE ? paginationE.offsetHeight : 0) - (toolbar ? toolbar.offsetHeight : 0) - (summaryE ? 40 : 0) - (tableScrollRight ? 10 : 0);
271
271
  setHeight(hhh > 0 ? hhh : 0);
272
272
  }
@@ -423,26 +423,28 @@ const InternalTable = props => {
423
423
  dataIndex: column.field ?? column.dataIndex,
424
424
  key: column.field ?? column.key,
425
425
  // title: () => (<HeaderContent column={{...column} as any} t={t}/>),
426
- title: /*#__PURE__*/React.createElement(SortableHeaderCell, {
427
- columnKey: column.field
428
- }, /*#__PURE__*/React.createElement(HeaderContent, {
426
+ title:
427
+ /*#__PURE__*/
428
+ // <SortableHeaderCell columnKey={column.field}>
429
+ React.createElement(HeaderContent, {
429
430
  column: {
430
431
  ...column
431
432
  },
432
433
  t: t,
433
434
  id: id,
434
435
  wrapSettings: wrapSettings
435
- })),
436
+ })
437
+ // </SortableHeaderCell>
438
+ ,
436
439
  // ellipsis: editAble || column.ellipsis !== false && wrapSettings && wrapSettings.wrapMode !== 'Content' && wrapSettings.wrapMode !== 'Both',
437
- ellipsis: column.ellipsis !== false || wrapSettings && wrapSettings.wrapMode !== 'Content' && wrapSettings.wrapMode !== 'Both',
438
- // ellipsis: false,
439
- // ellipsis: column.ellipsis !== false,
440
-
440
+ // ellipsis: column.ellipsis !== false || (wrapSettings && wrapSettings.wrapMode !== 'Content' && wrapSettings.wrapMode !== 'Both'),
441
+ ellipsis: false,
441
442
  align: column.textAlign ?? column.align,
442
443
  fixed: column.fixedType ?? column.fixed,
443
444
  isSummary: column.isSummary ?? column.haveSum,
444
445
  hidden: column.hidden ?? column.visible === false
445
446
  };
447
+ const headerTooltip = t ? t?.(column.headerTooltip ?? column.columnGroupText ?? column.headerText) : column.headerTooltip ?? column.columnGroupText ?? column.headerText;
446
448
  if (transformedColumn.field === '#') {
447
449
  return {
448
450
  ...transformedColumn,
@@ -544,10 +546,18 @@ const InternalTable = props => {
544
546
  },
545
547
  onHeaderCell: () => ({
546
548
  id: `${column.field}`,
547
- width: column.width,
549
+ // width: column.width,
550
+
551
+ 'data-tooltip-id': `${id}-tooltip-header`,
552
+ 'data-tooltip-content': headerTooltip,
548
553
  onResize: handleResize?.(column),
549
- className: `${column.headerTextAlign === 'center' ? 'head-align-center' : column.headerTextAlign === 'right' ? 'head-align-right' : ''}
550
- ${wrapSettings && wrapSettings.wrapMode === 'Content' ? 'ui-rc-table-cell-ellipsis' : ''}`
554
+ className: classNames('', {
555
+ 'head-align-center': column.headerTextAlign === 'center',
556
+ 'head-align-right': column.headerTextAlign === 'right',
557
+ 'ui-rc-table-cell-ellipsis': !wrapSettings || !!(wrapSettings && wrapSettings.wrapMode === 'Content'),
558
+ // mặc định = true
559
+ 'ui-rc-table-cell-wrap': wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header')
560
+ })
551
561
  }),
552
562
  onCell: (data, index) => {
553
563
  const tooltipContent = isOpenTooltip === false ? '' : column?.tooltipDescription ? typeof column.tooltipDescription === 'function' ? column.tooltipDescription({
@@ -556,14 +566,16 @@ const InternalTable = props => {
556
566
  }) : column.tooltipDescription : column.template && typeof column.template !== 'function' ? column.template : data[column.field ?? ''];
557
567
  return {
558
568
  id: `${column.field}`,
559
- colSpan: groupColumns && data.children && column.field === firstNonGroupColumn?.field ? 3 : groupColumns && data.children && nonGroupColumns[1].field === column.field ? 0 : 1,
569
+ colSpan: groupColumns && data.children && column.field === firstNonGroupColumn?.field ? groupSetting?.groupColumnSpan ?? 2 : groupColumns && data.children && nonGroupColumns[1].field === column.field ? 0 : 1,
560
570
  // 'z-index': data?.children && column.field === firstNonGroupColumn?.field ? 11 : undefined,
561
571
  ...transformedColumn?.onCell?.(data, index),
562
572
  className: classNames(transformedColumn?.onCell?.(data, index).className ?? '', {
563
573
  'cell-group': groupColumns && data.children,
564
- 'cell-group-fixed': groupColumns && data.children && column.field === firstNonGroupColumn?.field
574
+ 'cell-group-fixed': groupColumns && data.children && column.field === firstNonGroupColumn?.field,
575
+ 'ui-rc-table-cell-ellipsis': !wrapSettings || wrapSettings && (wrapSettings.wrapMode === 'Header' || wrapSettings.wrapMode !== 'Both'),
576
+ // mặc định = true
577
+ 'ui-rc-table-cell-wrap': wrapSettings && (wrapSettings.wrapMode === 'Content' || wrapSettings.wrapMode === 'Both')
565
578
  }),
566
- // 'data-tooltip-id': "tooltip-cell-content"
567
579
  'data-tooltip-id': `${id}-tooltip-cell-content`,
568
580
  "data-tooltip-html": ReactDOMServer.renderToStaticMarkup( /*#__PURE__*/React.createElement(React.Fragment, null, tooltipContent)),
569
581
  onMouseEnter: e => {
@@ -603,8 +615,20 @@ const InternalTable = props => {
603
615
  return /*#__PURE__*/React.createElement("span", null, currentGroupColumn?.headerText, ": ", renderContent(currentGroupColumn, record[record.field], record, rowIndex, colIndex, false, cellFormat));
604
616
  }
605
617
  if (groupAble && record.children && column.sumGroup === true && column.type === 'number') {
618
+ const thousandSeparator = cellFormat?.thousandSeparator;
619
+ const decimalSeparator = cellFormat?.decimalSeparator;
620
+ const dec = cellFormat?.decimalScale;
621
+ const numericFormatProps = {
622
+ thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
623
+ decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
624
+ allowNegative: cellFormat?.allowNegative ?? true,
625
+ prefix: cellFormat?.prefix,
626
+ suffix: cellFormat?.suffix,
627
+ decimalScale: dec,
628
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
629
+ };
606
630
  const sumValue = sumByField(filterDataByColumns4(record.children, [], []), column?.field);
607
- return /*#__PURE__*/React.createElement(React.Fragment, null, sumValue);
631
+ return /*#__PURE__*/React.createElement(React.Fragment, null, numericFormatter(sumValue.toString(), numericFormatProps));
608
632
  }
609
633
  return renderContent(column, value, record, rowIndex, colIndex, false, cellFormat);
610
634
  },
@@ -634,13 +658,14 @@ const InternalTable = props => {
634
658
  id: id,
635
659
  wrapSettings: wrapSettings
636
660
  })),
637
- // ellipsis: column.ellipsis !== false,
638
- ellipsis: editAble || column.ellipsis !== false && wrapSettings && wrapSettings.wrapMode !== 'Content' && wrapSettings.wrapMode !== 'Both',
661
+ ellipsis: false,
662
+ // ellipsis: editAble || column.ellipsis !== false && wrapSettings && wrapSettings.wrapMode !== 'Content' && wrapSettings.wrapMode !== 'Both',
663
+
639
664
  align: column.textAlign ?? column.align,
640
665
  fixed: column.fixedType ?? column.fixed,
641
666
  isSummary: column.isSummary ?? column.haveSum,
642
- hidden: column.hidden ?? column.visible === false,
643
- defaultSortOrder: 'ascend'
667
+ hidden: column.hidden ?? column.visible === false
668
+ // defaultSortOrder: 'ascend'
644
669
  };
645
670
 
646
671
  // Xử lý đệ quy cho children
@@ -927,12 +952,14 @@ const InternalTable = props => {
927
952
  const handleFullScreen = () => {
928
953
  setIsFullScreen(!isFullScreen);
929
954
  };
930
- const CustomThead = theadProps => {
955
+ const CustomThead = headerProps => {
931
956
  const {
932
- children
933
- } = theadProps;
957
+ children,
958
+ className
959
+ } = headerProps;
934
960
  return /*#__PURE__*/React.createElement("thead", {
935
- ref: theadRef
961
+ ref: theadRef,
962
+ className: className
936
963
  }, children);
937
964
  };
938
965
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(DndContext, {
@@ -958,7 +985,10 @@ const InternalTable = props => {
958
985
  ,
959
986
  dataSource: filterDataByColumns4(mergedData, filterStates, mergedFilterKeys),
960
987
  format: format,
961
- columns: mergedColumns,
988
+ columns: mergedColumns
989
+
990
+ // showSorterTooltip={false}
991
+ ,
962
992
  showSorterTooltip: {
963
993
  target: 'sorter-icon'
964
994
  },
@@ -285,6 +285,7 @@ export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<Re
285
285
  onRowStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | ((data: RecordType, row: Row<RecordType>) => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
286
286
  onRowHeaderStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | (() => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
287
287
  onRowFooterStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | (() => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
288
+ fullScreenTitle?: ReactNode | (() => ReactNode);
288
289
  }
289
290
  export type PaginationConfig = TablePaginationConfig & {
290
291
  currentPage?: number;
@@ -314,6 +315,7 @@ export interface CommandItem {
314
315
  export type IGroupSetting = {
315
316
  client?: boolean;
316
317
  onGroup?: (props: IOnGroup) => void;
318
+ groupColumnSpan?: number;
317
319
  hiddenColumnGroup?: boolean;
318
320
  showGroupIcon?: boolean;
319
321
  unClearableLevel?: 1 | 2 | 3 | undefined;
@@ -200,10 +200,7 @@ const InternalTable = props => {
200
200
  triggerSorter: setSorterStates,
201
201
  setMergedFilterKeys: setMergedFilterKeys,
202
202
  mergedFilterKeys: mergedFilterKeys,
203
- expanded: expanded
204
- // onContextMenu={onContextMenu}
205
- // contextMenuItems={contextMenuItems}
206
- ,
203
+ expanded: expanded,
207
204
  editAble: isFullScreen ? false : editAble,
208
205
  triggerChangeColumns: triggerChangeColumns,
209
206
  setExpanded: setExpanded,
@@ -185,10 +185,6 @@ const TableContainer = props => {
185
185
  ref: topToolbarRef,
186
186
  className: classNames(`${prefix}-grid-top-toolbar`, {})
187
187
  }, /*#__PURE__*/React.createElement("div", {
188
- style: {
189
- textAlign: 'center'
190
- }
191
- }, typeof title === 'function' ? title?.(originData) : title), /*#__PURE__*/React.createElement("div", {
192
188
  style: {
193
189
  display: 'flex',
194
190
  justifyContent: 'space-between',
@@ -239,7 +235,11 @@ const TableContainer = props => {
239
235
  t: t,
240
236
  columnsGroup: groupColumns,
241
237
  triggerChangeColumns: triggerChangeColumns
242
- })))), /*#__PURE__*/React.createElement(TableContext.Provider, {
238
+ }))), /*#__PURE__*/React.createElement("div", {
239
+ style: {
240
+ textAlign: 'center'
241
+ }
242
+ }, typeof title === 'function' ? title?.(originData) : title)), /*#__PURE__*/React.createElement(TableContext.Provider, {
243
243
  value: {
244
244
  t,
245
245
  locale,
@@ -358,6 +358,9 @@ const TableContainerEdit = props => {
358
358
  const [isPasting, setIsPasting] = React.useState(false);
359
359
  // const [isFullScreen] = React.useState(false);
360
360
  const [tableHeight, settableHeight] = React.useState(0);
361
+
362
+ // const [isAddNewRow, setIsAddNewRow] = React.useState(false)
363
+
361
364
  const rowsFocus = React.useMemo(() => {
362
365
  return startCell && endCell ? getRowIdsBetween(table, startCell.rowId, endCell.rowId) : [];
363
366
  }, [endCell, startCell, table]);
@@ -396,7 +399,7 @@ const TableContainerEdit = props => {
396
399
  }, [startCell, endCell, table]);
397
400
  const triggerChangeData = React.useCallback(newData => {
398
401
  onDataChange?.(newData);
399
- }, [onDataChange]);
402
+ }, [onDataChange, dataSource]);
400
403
  const triggerPaste = React.useCallback((pastedRows, pastedColumnsArray, newData, copyRows) => {
401
404
  const handlePasteCallback = callbackData => {
402
405
  const rsFilterData = updateOrInsert(flattenArray([...originData]), callbackData);
@@ -955,6 +958,30 @@ const TableContainerEdit = props => {
955
958
  mode: 'onChange',
956
959
  resolver: validate ? yupResolver(validate) : undefined
957
960
  });
961
+ const handleAddMulti = React.useCallback((item, n, newId) => {
962
+ if (item.onClick) {
963
+ item.onClick({
964
+ toolbar: item
965
+ });
966
+ } else {
967
+ const defaultRowValue = getDefaultValue(defaultValue);
968
+ const newRows = Array.from({
969
+ length: n
970
+ }).map(() => defaultRowValue ? {
971
+ ...defaultRowValue,
972
+ id: undefined,
973
+ rowId: n === 1 && newId ? newId : newGuid()
974
+ } : {
975
+ id: undefined,
976
+ rowId: n === 1 && newId ? newId : newGuid()
977
+ });
978
+ const kkk = getAllRowKey(newRows) ?? [];
979
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
980
+ setMergedFilterKeys?.(rs);
981
+ const newData = dataSource.concat(newRows);
982
+ triggerChangeData?.(newData);
983
+ }
984
+ }, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
958
985
  const onSubmit = formData => {
959
986
  try {
960
987
  // const record = (await form.validateFields()) as RecordType;
@@ -975,6 +1002,26 @@ const TableContainerEdit = props => {
975
1002
  console.log('Validate Failed:', errInfo);
976
1003
  }
977
1004
  };
1005
+ const onSubmit2 = (formData, newOriginData) => {
1006
+ try {
1007
+ // const record = (await form.validateFields()) as RecordType;
1008
+ const row = {
1009
+ ...formData
1010
+ };
1011
+
1012
+ // const newData = [...dataSource]
1013
+ const newData = [...newOriginData];
1014
+
1015
+ // @ts-ignore
1016
+ const index = flattenData(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
1017
+ const rs = updateArrayByKey(newData, row, rowKey);
1018
+ if (index > -1) {
1019
+ triggerChangeData?.(rs);
1020
+ }
1021
+ } catch (errInfo) {
1022
+ console.log('Validate Failed:', errInfo);
1023
+ }
1024
+ };
978
1025
  const handleCellChange = args => {
979
1026
  const {
980
1027
  record,
@@ -1032,30 +1079,111 @@ const TableContainerEdit = props => {
1032
1079
  onSubmit(record);
1033
1080
  }
1034
1081
  };
1035
- const handleAddMulti = React.useCallback((item, n, newId) => {
1036
- if (item.onClick) {
1037
- item.onClick({
1038
- toolbar: item
1039
- });
1040
- } else {
1041
- const defaultRowValue = getDefaultValue(defaultValue);
1042
- const newRows = Array.from({
1043
- length: n
1044
- }).map(() => defaultRowValue ? {
1045
- ...defaultRowValue,
1046
- id: undefined,
1047
- rowId: n === 1 && newId ? newId : newGuid()
1048
- } : {
1049
- id: undefined,
1050
- rowId: n === 1 && newId ? newId : newGuid()
1051
- });
1052
- const kkk = getAllRowKey(newRows) ?? [];
1053
- const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
1054
- setMergedFilterKeys?.(rs);
1055
- const newData = dataSource.concat(newRows);
1056
- triggerChangeData?.(newData);
1082
+ const handleCellChangeAndAddRow = args => {
1083
+ const {
1084
+ record,
1085
+ type: changeType,
1086
+ newState,
1087
+ option,
1088
+ field,
1089
+ indexCol,
1090
+ indexRow,
1091
+ key
1092
+ } = args;
1093
+
1094
+ // add new row
1095
+
1096
+ const defaultRowValue = getDefaultValue(defaultValue);
1097
+ const newRowId = newGuid();
1098
+ const newRows = Array.from({
1099
+ length: 1
1100
+ }).map(() => defaultRowValue ? {
1101
+ ...defaultRowValue,
1102
+ id: undefined,
1103
+ rowId: newRowId
1104
+ } : {
1105
+ id: undefined,
1106
+ rowId: newRowId
1107
+ });
1108
+ const kkk = getAllRowKey(newRows) ?? [];
1109
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
1110
+ setMergedFilterKeys?.(rs);
1111
+ const newData = originData.concat(newRows);
1112
+ setFocusedCell?.({
1113
+ rowId: newRowId,
1114
+ colId: field
1115
+ });
1116
+ setStartCell?.({
1117
+ rowId: newRowId,
1118
+ colId: field
1119
+ });
1120
+ setEndCell?.({
1121
+ rowId: newRowId,
1122
+ colId: field
1123
+ });
1124
+ setTimeout(() => {
1125
+ setRangeState?.(getSelectedCellMatrix(table, {
1126
+ rowId: newRowId,
1127
+ colId: field
1128
+ }, {
1129
+ rowId: newRowId,
1130
+ colId: field
1131
+ }));
1132
+ });
1133
+ setTimeout(() => {
1134
+ const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${newRowId}"]`);
1135
+ const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
1136
+ if (cellFocus) {
1137
+ cellFocus.scrollIntoView({
1138
+ behavior: "smooth",
1139
+ block: "start"
1140
+ });
1141
+ cellFocus.focus();
1142
+ }
1143
+ }, 100);
1144
+ if (changeType === 'blur') {
1145
+ const handleChangeCallback = callbackData => {
1146
+ const callbackRecord = callbackData;
1147
+ onSubmit2(callbackRecord, [...newData]);
1148
+ };
1149
+ if (onCellChange) {
1150
+ if (onCellChange.length > 1) {
1151
+ onCellChange({
1152
+ field,
1153
+ indexCol,
1154
+ type: 'onChange',
1155
+ value: newState,
1156
+ option,
1157
+ indexRow,
1158
+ rowData: record,
1159
+ rowId: key,
1160
+ rowsData: [...newData],
1161
+ sumValue: []
1162
+ }, handleChangeCallback);
1163
+ } else {
1164
+ onCellChange({
1165
+ field,
1166
+ indexCol,
1167
+ type: 'onChange',
1168
+ option,
1169
+ value: newState,
1170
+ indexRow,
1171
+ rowData: record,
1172
+ rowId: key,
1173
+ rowsData: [...newData],
1174
+ sumValue: []
1175
+ }, handleChangeCallback);
1176
+ onSubmit2(record, [...newData]);
1177
+ }
1178
+ }
1057
1179
  }
1058
- }, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
1180
+
1181
+ // if (prevState && newState && prevState !== newState && changeType === 'enter') {
1182
+
1183
+ // onSubmit(record)
1184
+
1185
+ // }
1186
+ };
1059
1187
  const handleDuplicate = React.useCallback(() => {
1060
1188
  // không tính tree
1061
1189
 
@@ -1782,10 +1910,6 @@ const TableContainerEdit = props => {
1782
1910
  ref: topToolbarRef,
1783
1911
  className: classNames(`${prefix}-grid-top-toolbar`, {})
1784
1912
  }, /*#__PURE__*/React.createElement("div", {
1785
- style: {
1786
- textAlign: 'center'
1787
- }
1788
- }, typeof title === 'function' ? title?.(originData) : title), /*#__PURE__*/React.createElement("div", {
1789
1913
  style: {
1790
1914
  display: 'flex',
1791
1915
  justifyContent: 'space-between',
@@ -1836,7 +1960,11 @@ const TableContainerEdit = props => {
1836
1960
  columnsGroup: groupColumns,
1837
1961
  triggerChangeColumns: triggerChangeColumns,
1838
1962
  columnHidden: columnHidden
1839
- })))), /*#__PURE__*/React.createElement("form", {
1963
+ }))), /*#__PURE__*/React.createElement("div", {
1964
+ style: {
1965
+ textAlign: 'center'
1966
+ }
1967
+ }, typeof title === 'function' ? title?.(originData) : title)), /*#__PURE__*/React.createElement("form", {
1840
1968
  onSubmit: handleSubmit(onSubmit)
1841
1969
  }, /*#__PURE__*/React.createElement(TableContext.Provider, {
1842
1970
  value: {
@@ -1888,6 +2016,7 @@ const TableContainerEdit = props => {
1888
2016
  setValue,
1889
2017
  reset,
1890
2018
  handleCellChange,
2019
+ handleCellChangeAndAddRow,
1891
2020
  triggerPaste,
1892
2021
  handleDeleteContent,
1893
2022
  handleAddMulti,
@@ -227,7 +227,7 @@ const TableBodyCellEdit = props => {
227
227
  setValue,
228
228
  getValues,
229
229
  handleCellChange,
230
- // handleAddMulti,
230
+ handleCellChangeAndAddRow,
231
231
  dataErrors,
232
232
  expanded,
233
233
  setExpanded,
@@ -237,17 +237,13 @@ const TableBodyCellEdit = props => {
237
237
  isSelectionChange,
238
238
  setIsSelectionChange,
239
239
  selectionSettings,
240
- pagination
240
+ pagination,
241
+ handleAddMulti
241
242
  } = React.useContext(TableContext);
242
243
  const expandIconColumnIndex = expandable?.expandIconColumnIndex;
243
244
  const record = cell.row.original;
244
245
  const columnMeta = cell.column.columnDef.meta ?? {};
245
246
  const [isOpenTooltip, setIsOpenTooltip] = React.useState(false);
246
-
247
- // const cellContent = columnMeta.type === 'checkbox' ? '' : flexRender(cell.column.columnDef.cell, cell.getContext());
248
- // const html = ReactDOMServer.renderToStaticMarkup(<>{cellContent}</>);
249
- // const hasValue = html.trim().length > 0;
250
-
251
247
  const rowError = dataErrors ? dataErrors.find(it => it.id === cell.row.id) : undefined;
252
248
  const message = rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : undefined;
253
249
  const tooltipContent = isOpenTooltip === false ? '' : columnMeta?.tooltipDescription ? typeof columnMeta.tooltipDescription === 'function' ? columnMeta.tooltipDescription({
@@ -783,6 +779,8 @@ const TableBodyCellEdit = props => {
783
779
  return;
784
780
  }
785
781
  if (e.key === 'Enter') {
782
+ e.preventDefault();
783
+ e.stopPropagation();
786
784
  handleEdit(e, true);
787
785
  return;
788
786
  }
@@ -1038,6 +1036,64 @@ const TableBodyCellEdit = props => {
1038
1036
  indexRow: currentRowIndex,
1039
1037
  type: 'blur'
1040
1038
  });
1039
+ } else {}
1040
+ };
1041
+ const handleChangeAndCreateRow = () => {
1042
+ const currentRowIndex = allRows.findIndex(r => r.id === editingKey);
1043
+ const formState = getValues();
1044
+ const itemState = getValues(cell.column.id);
1045
+ const prevState = record[cell.column.id];
1046
+ const newState = itemState;
1047
+ if (newState !== prevState) {
1048
+ // vừa cell change + add new row
1049
+ handleCellChangeAndAddRow?.({
1050
+ key: cell.row.id,
1051
+ field: cell.column.id,
1052
+ record: formState,
1053
+ prevState,
1054
+ newState,
1055
+ option: newState,
1056
+ indexCol: cell.column.getIndex(),
1057
+ indexRow: currentRowIndex,
1058
+ type: 'blur'
1059
+ });
1060
+ } else {
1061
+ // chỉ add new row
1062
+
1063
+ const newRowId = newGuid();
1064
+ handleAddMulti?.({}, 1, newRowId);
1065
+ setFocusedCell?.({
1066
+ rowId: newRowId,
1067
+ colId: cell.column.id
1068
+ });
1069
+ setStartCell?.({
1070
+ rowId: newRowId,
1071
+ colId: cell.column.id
1072
+ });
1073
+ setEndCell?.({
1074
+ rowId: newRowId,
1075
+ colId: cell.column.id
1076
+ });
1077
+ setTimeout(() => {
1078
+ setRangeState?.(getSelectedCellMatrix(table, {
1079
+ rowId: newRowId,
1080
+ colId: cell.column.id
1081
+ }, {
1082
+ rowId: newRowId,
1083
+ colId: cell.column.id
1084
+ }));
1085
+ });
1086
+ setTimeout(() => {
1087
+ const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${newRowId}"]`);
1088
+ const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
1089
+ if (cellFocus) {
1090
+ cellFocus.scrollIntoView({
1091
+ behavior: "smooth",
1092
+ block: "start"
1093
+ });
1094
+ cellFocus.focus();
1095
+ }
1096
+ }, 100);
1041
1097
  }
1042
1098
  };
1043
1099
  return /*#__PURE__*/React.createElement("div", {
@@ -1110,9 +1166,10 @@ const TableBodyCellEdit = props => {
1110
1166
  if (!isEditing) {
1111
1167
  handleKeyDown(e, cell.row.id, cell.column.id);
1112
1168
  } else {
1113
- // setStartCell?.(undefined)
1114
-
1115
- if (e.shiftKey && e.key === 'Enter') {} else {
1169
+ if (e.shiftKey && e.key === 'Enter') {
1170
+ e.preventDefault();
1171
+ e.stopPropagation();
1172
+ } else {
1116
1173
  if (e.key === 'Enter') {
1117
1174
  e.preventDefault();
1118
1175
  e.stopPropagation();
@@ -1141,29 +1198,10 @@ const TableBodyCellEdit = props => {
1141
1198
  rowVirtualizer.scrollToIndex(nextRow.index, {
1142
1199
  align: 'center'
1143
1200
  });
1201
+ handleChange();
1144
1202
  } else {
1145
-
1146
- // const newRowId = newGuid()
1147
- // handleAddMulti?.({}, 1, newRowId)
1148
-
1149
- // setFocusedCell?.({ rowId: newRowId, colId: cell.column.id });
1150
-
1151
- // setStartCell?.({ rowId: newRowId, colId: cell.column.id });
1152
- // setEndCell?.({ rowId: newRowId, colId: cell.column.id });
1153
-
1154
- // setTimeout(() => {
1155
- // setRangeState?.(getSelectedCellMatrix(table, { rowId: newRowId, colId: cell.column.id }, { rowId: newRowId, colId: cell.column.id }))
1156
- // // rowVirtualizer.scrollToIndex(currentRowIndex + 1, { align: 'end', })
1157
-
1158
- // })
1159
-
1160
- // setTimeout(() => {
1161
-
1162
- // rowVirtualizer.scrollToIndex(currentRowIndex + 1, { align: 'center', })
1163
-
1164
- // }, 100)
1203
+ handleChangeAndCreateRow();
1165
1204
  }
1166
- handleChange();
1167
1205
  setEditingKey?.('');
1168
1206
  reset?.();
1169
1207
  }
@@ -154,3 +154,5 @@ export declare function countUnselectedChildren(row: Row<any>): number;
154
154
  export declare function removeDuplicatesByKey(arr: any[], key?: string): any[];
155
155
  export declare const getTableHeight: (height?: number, minHeight?: number) => number;
156
156
  export declare const convertFlatColumn1: (array: ColumnsTable) => ColumnsTable[];
157
+ export declare const updateColumnsByGroup: (columns: any[], columnsGroup: string[]) => any[];
158
+ export declare const removeColumns: <RecordType>(columns: ColumnTable<RecordType>[], groupColumns: string[]) => ColumnsTable<RecordType>;