es-grid-template 1.5.15 → 1.5.17

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.
@@ -785,7 +785,7 @@ const InternalTable = props => {
785
785
  }
786
786
  }
787
787
  };
788
- const triggerPaste = (pastedRows, pastedColumnsArray, newData) => {
788
+ const triggerPaste = (pastedRows, pastedColumnsArray, newData, copyRows) => {
789
789
  const handlePasteCallback = callbackData => {
790
790
  const newDataUpdate = updateData(mergedData, callbackData, rowKey);
791
791
  triggerChangeData(newDataUpdate);
@@ -797,6 +797,7 @@ const InternalTable = props => {
797
797
  // có callback
798
798
  onCellPaste.onPasted({
799
799
  pasteData: pastedRows,
800
+ copyRows,
800
801
  type: 'onPaste',
801
802
  data: mergedData,
802
803
  pastedColumns: pastedColumnsArray
@@ -806,6 +807,7 @@ const InternalTable = props => {
806
807
  onCellPaste.onPasted({
807
808
  pasteData: pastedRows,
808
809
  type: 'onPaste',
810
+ copyRows,
809
811
  data: mergedData,
810
812
  pastedColumns: pastedColumnsArray
811
813
  }, handlePasteCallback);
@@ -178,6 +178,7 @@ const TableGrid = props => {
178
178
  groupToolbar,
179
179
  showEmptyText,
180
180
  setIsFilter,
181
+ actionTemplate,
181
182
  ...rest
182
183
  } = props;
183
184
  const {
@@ -337,7 +338,7 @@ const TableGrid = props => {
337
338
  setMergedSelectedKeys([selectedRow[rowKey]]);
338
339
  rowSelected?.({
339
340
  // @ts-ignore
340
- selected: [selectedRow[rowKey]],
341
+ selected: [selectedRow],
341
342
  type: 'rowSelected',
342
343
  rowData: selectedRow
343
344
  });
@@ -464,7 +465,7 @@ const TableGrid = props => {
464
465
  // @ts-ignore
465
466
  ,
466
467
  showTotal: (total, range) => `${range[0]}-${range[1]} / ${total} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
467
- }, pagination)), showColumnChoose && /*#__PURE__*/React.createElement(ColumnsChoose, {
468
+ }, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, showColumnChoose && /*#__PURE__*/React.createElement(ColumnsChoose, {
468
469
  columns: columns,
469
470
  t: t,
470
471
  columnsGroup: groupColumns,
@@ -15,5 +15,7 @@ interface UseColumnsConfig<RecordType> {
15
15
  rowKey?: any;
16
16
  onMouseHover?: any;
17
17
  }
18
- declare const useColumns: <RecordType extends AnyObject = AnyObject>(config: UseColumnsConfig<RecordType>) => readonly [any];
18
+ declare const useColumns: <RecordType extends AnyObject = AnyObject>(config: UseColumnsConfig<RecordType>) => readonly [
19
+ any
20
+ ];
19
21
  export default useColumns;
@@ -10,7 +10,7 @@ type Props<T> = GridTableProps<T> & {
10
10
  getRowKey: GetRowKey<T>;
11
11
  triggerGroupColumns?: (groupedColumns: string[]) => void;
12
12
  setTooltipContent?: any;
13
- triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[]) => void;
13
+ triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[], copyRows: T[]) => void;
14
14
  isFilter?: boolean;
15
15
  setIsFilter?: React.Dispatch<React.SetStateAction<boolean>>;
16
16
  };
@@ -8,7 +8,7 @@ type Props<RecordType> = TableProps<RecordType> & {
8
8
  tableRef: any;
9
9
  triggerChangeColumns?: (columns: ColumnsTable<RecordType>, type: string) => void;
10
10
  triggerChangeData?: (newData: RecordType[], type: string) => void;
11
- triggerPaste?: (pastedRows: RecordType[], pastedColumnsArray: string[], newData: RecordType[]) => void;
11
+ triggerPaste?: (pastedRows: RecordType[], pastedColumnsArray: string[], newData: RecordType[], copyRows: RecordType[]) => void;
12
12
  getRowKey: GetRowKey<RecordType>;
13
13
  triggerGroupColumns?: (groupedColumns: string[]) => void;
14
14
  setTooltipContent?: any;
@@ -1043,6 +1043,9 @@ const GridEdit = props => {
1043
1043
  };
1044
1044
  // return { row, col, value: '' };
1045
1045
  });
1046
+ const copyRows = selectedArray.map(it => ({
1047
+ ...flattenData(childrenColumnName, dataSource)[it.row]
1048
+ }));
1046
1049
 
1047
1050
  // Xác định min/max row và col để sắp xếp dữ liệu
1048
1051
  const minRow = Math.min(...selectedArray.map(cell => cell.row));
@@ -1115,7 +1118,7 @@ const GridEdit = props => {
1115
1118
  pastedRows.push(newData[targetRow]);
1116
1119
  });
1117
1120
  const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1118
- triggerPaste?.(pastedRows, pastedColumnsArray, newData);
1121
+ triggerPaste?.(pastedRows, pastedColumnsArray, newData, copyRows);
1119
1122
  }
1120
1123
 
1121
1124
  /// cập nhật cell class
@@ -1145,11 +1148,7 @@ const GridEdit = props => {
1145
1148
  };
1146
1149
  const handlePasted = (record, indexCol, rowNumber, pasteData) => {
1147
1150
  const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
1148
- console.log('rows', rows);
1149
- console.log('record', record);
1150
1151
  if (!record?.parentId) {
1151
- console.log('1');
1152
-
1153
1152
  // Cập nhật data mới
1154
1153
  const newData = [...dataSource];
1155
1154
 
@@ -1224,12 +1223,8 @@ const GridEdit = props => {
1224
1223
  pastedRows.push(newData[targetRow]);
1225
1224
  });
1226
1225
  const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1227
- console.log('pastedRows', pastedRows);
1228
- console.log('pastedColumnsArray', pastedColumnsArray);
1229
- console.log('newData', newData);
1230
- triggerPaste?.(pastedRows, pastedColumnsArray, newData);
1226
+ triggerPaste?.(pastedRows, pastedColumnsArray, newData, []);
1231
1227
  } else {
1232
- console.log('2');
1233
1228
  // Cập nhật data mới
1234
1229
  const newData = [...dataSource];
1235
1230
  const parent = findItemByKey(newData, rowKey, record.parentId);
@@ -1282,13 +1277,12 @@ const GridEdit = props => {
1282
1277
  children: childData
1283
1278
  };
1284
1279
  const newDataSource = updateArrayByKey(newData, newRowData, rowKey);
1285
- triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
1280
+ triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
1286
1281
  }
1287
1282
  };
1288
1283
  const handlePaste = (record, indexCol, rowNumber, e) => {
1289
1284
  // const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
1290
1285
  const pasteData = e.clipboardData.getData("text/plain");
1291
- console.log('pasteData', pasteData);
1292
1286
 
1293
1287
  // Chuyển đổi dữ liệu từ clipboard thành mảng
1294
1288
  const rowsPasted = pasteData.split("\n").map(row =>
@@ -1322,7 +1316,6 @@ const GridEdit = props => {
1322
1316
  // ),
1323
1317
  });
1324
1318
  } else {
1325
- console.log('5555');
1326
1319
  handlePasted(record, indexCol, rowNumber, rowsPasted);
1327
1320
  }
1328
1321
 
@@ -2246,7 +2239,6 @@ const GridEdit = props => {
2246
2239
  }
2247
2240
  },
2248
2241
  onPaste: event => {
2249
- console.log('aaaaaa');
2250
2242
  if (editingKey.current === '') {
2251
2243
  handlePaste(record, colIndex, rowNumber, event);
2252
2244
  event.preventDefault();
@@ -7,7 +7,7 @@ type Props<T> = GridTableProps<T> & {
7
7
  triggerChangeData?: (newData: T[], type: string) => void;
8
8
  getRowKey: GetRowKey<T>;
9
9
  triggerGroupColumns?: (groupedColumns: string[]) => void;
10
- triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[]) => void;
10
+ triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[], copyRows: T[]) => void;
11
11
  triggerFilter?: (queries: any) => void;
12
12
  setTooltipContent?: any;
13
13
  scrollHeight?: number;
@@ -10,7 +10,7 @@ type Props<T> = TableProps<T> & {
10
10
  getRowKey: GetRowKey<T>;
11
11
  triggerGroupColumns?: (groupedColumns: string[]) => void;
12
12
  setTooltipContent?: any;
13
- triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[]) => void;
13
+ triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[], copyRows: T[]) => void;
14
14
  isFilter?: boolean;
15
15
  setIsFilter?: React.Dispatch<React.SetStateAction<boolean>>;
16
16
  };
@@ -227,6 +227,7 @@ export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<Re
227
227
  rowData: any;
228
228
  }) => void;
229
229
  wrapSettings?: IWrapSettings;
230
+ actionTemplate?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
230
231
  }
231
232
  export type PaginationConfig = TablePaginationConfig & {
232
233
  currentPage?: number;
@@ -284,6 +285,7 @@ export type CellChangeArgs<T> = {
284
285
  };
285
286
  export type IOnPastedProps = {
286
287
  data: any[];
288
+ copyRows: any[];
287
289
  pastedColumns: string[];
288
290
  pasteData: any[];
289
291
  type: 'onPaste' | 'onChange' | 'onCellPaste';
@@ -796,7 +796,7 @@ const InternalTable = props => {
796
796
  }
797
797
  }
798
798
  };
799
- const triggerPaste = (pastedRows, pastedColumnsArray, newData) => {
799
+ const triggerPaste = (pastedRows, pastedColumnsArray, newData, copyRows) => {
800
800
  const handlePasteCallback = callbackData => {
801
801
  const newDataUpdate = (0, _hooks.updateData)(mergedData, callbackData, rowKey);
802
802
  triggerChangeData(newDataUpdate);
@@ -808,6 +808,7 @@ const InternalTable = props => {
808
808
  // có callback
809
809
  onCellPaste.onPasted({
810
810
  pasteData: pastedRows,
811
+ copyRows,
811
812
  type: 'onPaste',
812
813
  data: mergedData,
813
814
  pastedColumns: pastedColumnsArray
@@ -817,6 +818,7 @@ const InternalTable = props => {
817
818
  onCellPaste.onPasted({
818
819
  pasteData: pastedRows,
819
820
  type: 'onPaste',
821
+ copyRows,
820
822
  data: mergedData,
821
823
  pastedColumns: pastedColumnsArray
822
824
  }, handlePasteCallback);
@@ -178,6 +178,7 @@ const TableGrid = props => {
178
178
  groupToolbar,
179
179
  showEmptyText,
180
180
  setIsFilter,
181
+ actionTemplate,
181
182
  ...rest
182
183
  } = props;
183
184
  const {
@@ -337,7 +338,7 @@ const TableGrid = props => {
337
338
  setMergedSelectedKeys([selectedRow[rowKey]]);
338
339
  rowSelected?.({
339
340
  // @ts-ignore
340
- selected: [selectedRow[rowKey]],
341
+ selected: [selectedRow],
341
342
  type: 'rowSelected',
342
343
  rowData: selectedRow
343
344
  });
@@ -464,7 +465,7 @@ const TableGrid = props => {
464
465
  // @ts-ignore
465
466
  ,
466
467
  showTotal: (total, range) => `${range[0]}-${range[1]} / ${total} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
467
- }, pagination)), showColumnChoose && /*#__PURE__*/_react.default.createElement(_ColumnsChoose.ColumnsChoose, {
468
+ }, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, showColumnChoose && /*#__PURE__*/_react.default.createElement(_ColumnsChoose.ColumnsChoose, {
468
469
  columns: columns,
469
470
  t: t,
470
471
  columnsGroup: groupColumns,
@@ -10,7 +10,7 @@ type Props<T> = GridTableProps<T> & {
10
10
  getRowKey: GetRowKey<T>;
11
11
  triggerGroupColumns?: (groupedColumns: string[]) => void;
12
12
  setTooltipContent?: any;
13
- triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[]) => void;
13
+ triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[], copyRows: T[]) => void;
14
14
  isFilter?: boolean;
15
15
  setIsFilter?: React.Dispatch<React.SetStateAction<boolean>>;
16
16
  };
@@ -8,7 +8,7 @@ type Props<RecordType> = TableProps<RecordType> & {
8
8
  tableRef: any;
9
9
  triggerChangeColumns?: (columns: ColumnsTable<RecordType>, type: string) => void;
10
10
  triggerChangeData?: (newData: RecordType[], type: string) => void;
11
- triggerPaste?: (pastedRows: RecordType[], pastedColumnsArray: string[], newData: RecordType[]) => void;
11
+ triggerPaste?: (pastedRows: RecordType[], pastedColumnsArray: string[], newData: RecordType[], copyRows: RecordType[]) => void;
12
12
  getRowKey: GetRowKey<RecordType>;
13
13
  triggerGroupColumns?: (groupedColumns: string[]) => void;
14
14
  setTooltipContent?: any;
@@ -1047,6 +1047,9 @@ const GridEdit = props => {
1047
1047
  };
1048
1048
  // return { row, col, value: '' };
1049
1049
  });
1050
+ const copyRows = selectedArray.map(it => ({
1051
+ ...(0, _hooks.flattenData)(childrenColumnName, dataSource)[it.row]
1052
+ }));
1050
1053
 
1051
1054
  // Xác định min/max row và col để sắp xếp dữ liệu
1052
1055
  const minRow = Math.min(...selectedArray.map(cell => cell.row));
@@ -1119,7 +1122,7 @@ const GridEdit = props => {
1119
1122
  pastedRows.push(newData[targetRow]);
1120
1123
  });
1121
1124
  const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1122
- triggerPaste?.(pastedRows, pastedColumnsArray, newData);
1125
+ triggerPaste?.(pastedRows, pastedColumnsArray, newData, copyRows);
1123
1126
  }
1124
1127
 
1125
1128
  /// cập nhật cell class
@@ -1149,11 +1152,7 @@ const GridEdit = props => {
1149
1152
  };
1150
1153
  const handlePasted = (record, indexCol, rowNumber, pasteData) => {
1151
1154
  const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
1152
- console.log('rows', rows);
1153
- console.log('record', record);
1154
1155
  if (!record?.parentId) {
1155
- console.log('1');
1156
-
1157
1156
  // Cập nhật data mới
1158
1157
  const newData = [...dataSource];
1159
1158
 
@@ -1228,12 +1227,8 @@ const GridEdit = props => {
1228
1227
  pastedRows.push(newData[targetRow]);
1229
1228
  });
1230
1229
  const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1231
- console.log('pastedRows', pastedRows);
1232
- console.log('pastedColumnsArray', pastedColumnsArray);
1233
- console.log('newData', newData);
1234
- triggerPaste?.(pastedRows, pastedColumnsArray, newData);
1230
+ triggerPaste?.(pastedRows, pastedColumnsArray, newData, []);
1235
1231
  } else {
1236
- console.log('2');
1237
1232
  // Cập nhật data mới
1238
1233
  const newData = [...dataSource];
1239
1234
  const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
@@ -1286,13 +1281,12 @@ const GridEdit = props => {
1286
1281
  children: childData
1287
1282
  };
1288
1283
  const newDataSource = (0, _hooks.updateArrayByKey)(newData, newRowData, rowKey);
1289
- triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
1284
+ triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
1290
1285
  }
1291
1286
  };
1292
1287
  const handlePaste = (record, indexCol, rowNumber, e) => {
1293
1288
  // const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
1294
1289
  const pasteData = e.clipboardData.getData("text/plain");
1295
- console.log('pasteData', pasteData);
1296
1290
 
1297
1291
  // Chuyển đổi dữ liệu từ clipboard thành mảng
1298
1292
  const rowsPasted = pasteData.split("\n").map(row =>
@@ -1326,7 +1320,6 @@ const GridEdit = props => {
1326
1320
  // ),
1327
1321
  });
1328
1322
  } else {
1329
- console.log('5555');
1330
1323
  handlePasted(record, indexCol, rowNumber, rowsPasted);
1331
1324
  }
1332
1325
 
@@ -2250,7 +2243,6 @@ const GridEdit = props => {
2250
2243
  }
2251
2244
  },
2252
2245
  onPaste: event => {
2253
- console.log('aaaaaa');
2254
2246
  if (editingKey.current === '') {
2255
2247
  handlePaste(record, colIndex, rowNumber, event);
2256
2248
  event.preventDefault();
@@ -7,7 +7,7 @@ type Props<T> = GridTableProps<T> & {
7
7
  triggerChangeData?: (newData: T[], type: string) => void;
8
8
  getRowKey: GetRowKey<T>;
9
9
  triggerGroupColumns?: (groupedColumns: string[]) => void;
10
- triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[]) => void;
10
+ triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[], copyRows: T[]) => void;
11
11
  triggerFilter?: (queries: any) => void;
12
12
  setTooltipContent?: any;
13
13
  scrollHeight?: number;
@@ -10,7 +10,7 @@ type Props<T> = TableProps<T> & {
10
10
  getRowKey: GetRowKey<T>;
11
11
  triggerGroupColumns?: (groupedColumns: string[]) => void;
12
12
  setTooltipContent?: any;
13
- triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[]) => void;
13
+ triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[], copyRows: T[]) => void;
14
14
  isFilter?: boolean;
15
15
  setIsFilter?: React.Dispatch<React.SetStateAction<boolean>>;
16
16
  };
@@ -227,6 +227,7 @@ export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<Re
227
227
  rowData: any;
228
228
  }) => void;
229
229
  wrapSettings?: IWrapSettings;
230
+ actionTemplate?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
230
231
  }
231
232
  export type PaginationConfig = TablePaginationConfig & {
232
233
  currentPage?: number;
@@ -284,6 +285,7 @@ export type CellChangeArgs<T> = {
284
285
  };
285
286
  export type IOnPastedProps = {
286
287
  data: any[];
288
+ copyRows: any[];
287
289
  pastedColumns: string[];
288
290
  pasteData: any[];
289
291
  type: 'onPaste' | 'onChange' | 'onCellPaste';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.5.15",
3
+ "version": "1.5.17",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",