es-grid-template 1.7.34 → 1.7.35

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.
@@ -51,8 +51,8 @@ export const SELECTION_COLUMN = {};
51
51
  const InternalTable = props => {
52
52
  const {
53
53
  t,
54
- // columns: propsColumns,
55
- columns,
54
+ columns: propsColumns,
55
+ // columns,
56
56
  lang,
57
57
  locale,
58
58
  dataSource,
@@ -126,6 +126,10 @@ const InternalTable = props => {
126
126
  const [filterStates, setFilterState] = React.useState(null);
127
127
  const [sorterStates, setSorterStates] = React.useState([]);
128
128
  const [isFullScreen, setIsFullScreen] = React.useState(false);
129
+ const [columns, setColumns] = React.useState([]);
130
+ React.useEffect(() => {
131
+ setColumns(propsColumns);
132
+ }, [propsColumns]);
129
133
  const [expanded, setExpanded] = React.useState({});
130
134
  const convertData = React.useMemo(() => {
131
135
  if (groupAble && groupSetting && groupSetting.client !== false) {
@@ -169,10 +173,14 @@ const InternalTable = props => {
169
173
  const [columnsHiddenKeys, setColumnsHiddenKeys] = useMergedState(undefined, {
170
174
  value: undefined
171
175
  });
172
- const triggerChangeColumns = (cols, keys) => {
173
- const aa = flatColumns2(columns).map(it => it.field);
174
- const rsss = getDiffent2Array(aa, keys);
175
- setColumnsHiddenKeys(rsss);
176
+ const triggerChangeColumns = (cols, keys, type) => {
177
+ if (type === 'cellClick') {
178
+ setColumns(cols);
179
+ } else {
180
+ const aa = flatColumns2(columns).map(it => it.field);
181
+ const rsss = getDiffent2Array(aa, keys);
182
+ setColumnsHiddenKeys(rsss);
183
+ }
176
184
  };
177
185
 
178
186
  // const contextMenuItems = React.useMemo(() => {
@@ -116,7 +116,8 @@ const TableContainerEdit = props => {
116
116
  contextMenuHidden,
117
117
  showDefaultContext,
118
118
  commandSettings,
119
- isDataTree
119
+ isDataTree,
120
+ onCellClick
120
121
  } = props;
121
122
  const containerRef = React.useRef(null);
122
123
  const bottomToolbarRef = React.useRef(null);
@@ -1442,6 +1443,33 @@ const TableContainerEdit = props => {
1442
1443
  }
1443
1444
  contextMenuClick?.(args);
1444
1445
  };
1446
+ const handleCellClick = (rowNumber, record, column, rowId, cellValue) => {
1447
+ const cellClickCallback = newOptions => {
1448
+ if (newOptions) {
1449
+ const newElem = {
1450
+ ...column,
1451
+ editSelectSettings: {
1452
+ ...(column?.editSelectSettings ? {
1453
+ ...column?.editSelectSettings
1454
+ } : {}),
1455
+ options: newOptions
1456
+ }
1457
+ };
1458
+ const rrr = updateArrayByKey([...columns], newElem, 'field');
1459
+ triggerChangeColumns?.(rrr, 'click');
1460
+ }
1461
+ };
1462
+ if (onCellClick) {
1463
+ onCellClick({
1464
+ index: rowNumber,
1465
+ rowId,
1466
+ cellValue,
1467
+ type: "Editing",
1468
+ field: column.field,
1469
+ rowData: record
1470
+ }, cellClickCallback);
1471
+ }
1472
+ };
1445
1473
  return /*#__PURE__*/React.createElement("div", {
1446
1474
  ref: containerRef,
1447
1475
  id: id
@@ -1554,7 +1582,8 @@ const TableContainerEdit = props => {
1554
1582
  handleDeleteContent,
1555
1583
  handleAddMulti,
1556
1584
  dataErrors,
1557
- windowSize
1585
+ windowSize,
1586
+ handleCellClick
1558
1587
  }
1559
1588
  }, /*#__PURE__*/React.createElement(TableWrapper, {
1560
1589
  contextMenuItems: contextMenuItems,
@@ -128,7 +128,8 @@ const TableBodyCellEdit = props => {
128
128
  expanded,
129
129
  setExpanded,
130
130
  expandable,
131
- isDataTree
131
+ isDataTree,
132
+ handleCellClick
132
133
  } = React.useContext(TableContext);
133
134
  const expandIconColumnIndex = expandable?.expandIconColumnIndex;
134
135
  const record = cell.row.original;
@@ -415,6 +416,7 @@ const TableBodyCellEdit = props => {
415
416
  setEditingKey?.(record[rowKey]);
416
417
  // setTooltipContent('')
417
418
 
419
+ handleCellClick?.(rowNumber, record, columnMeta, record[rowKey], record[columnMeta.field ?? '']);
418
420
  reset?.();
419
421
 
420
422
  // const formattedRecord = { ...record };
@@ -875,6 +877,9 @@ const TableBodyCellEdit = props => {
875
877
  rowId: cell.row.id,
876
878
  colId: cell.column.id
877
879
  });
880
+ if (canEdit) {
881
+ handleCellClick?.(rowNumber, record, columnMeta, record[rowKey], record[columnMeta.field ?? '']);
882
+ }
878
883
  } else {
879
884
  handleMouseDown(cell.row.id, cell.column.id);
880
885
  if (editingKey) {
@@ -40,7 +40,7 @@ export declare function groupArrayByColumns(arr: any[], columns: string[] | unde
40
40
  export declare const flatColumns2: <RecordType>(columns: ColumnsTable<RecordType>) => ColumnsTable<RecordType>;
41
41
  export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
42
42
  export declare const checkDecimalSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
43
- export declare function getFixedFields(columns: ColumnTable[], type: 'left' | 'right'): string[];
43
+ export declare const getFixedFields: <T>(columns: ColumnsTable<T>, type: 'left' | 'right') => string[];
44
44
  export declare function areStringArraysEqual(a: string[], b: string[]): boolean;
45
45
  export declare const getDefaultOperator: (col: ColumnTable) => FilterOperator;
46
46
  export declare function isEqualSet(setA: any, setB: any): boolean;
@@ -305,7 +305,7 @@ export const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
305
305
  return '.';
306
306
  }
307
307
  };
308
- export function getFixedFields(columns, type) {
308
+ export const getFixedFields = (columns, type) => {
309
309
  const result = [];
310
310
  function traverse(cols) {
311
311
  for (const col of cols) {
@@ -319,7 +319,7 @@ export function getFixedFields(columns, type) {
319
319
  }
320
320
  traverse(columns);
321
321
  return result;
322
- }
322
+ };
323
323
  export function areStringArraysEqual(a, b) {
324
324
  if (a.length !== b.length) return false;
325
325
  const sortedA = [...a].sort();
@@ -7,7 +7,7 @@ type Props<T> = Omit<TableProps<T>, 'columns'> & {
7
7
  rowKey: string;
8
8
  prefix: string;
9
9
  columns: ColumnDef<T>[];
10
- propsColumns: ColumnsTable;
10
+ propsColumns: ColumnsTable<T>;
11
11
  columnHidden: VisibilityState;
12
12
  expanded: ExpandedState;
13
13
  setExpanded: any;
@@ -20,7 +20,7 @@ type Props<T> = Omit<TableProps<T>, 'columns'> & {
20
20
  triggerFilter: Dispatch<SetStateAction<any>>;
21
21
  triggerSorter: Dispatch<SetStateAction<Sorter[]>>;
22
22
  onContextMenu?: (data: T) => (event: any) => void;
23
- triggerChangeColumns?: (args: any, keys: any) => void;
23
+ triggerChangeColumns?: (args: any, keys: any, type: string) => void;
24
24
  windowSize: any;
25
25
  isDataTree: boolean;
26
26
  };
@@ -1,5 +1,5 @@
1
1
  import type { Dispatch, SetStateAction } from 'react';
2
- import type { ExpandableConfig, IFormat, IWrapSettings, Locale, RangeState, RecordDoubleClickEventArgs, SelectionSettings } from "./type";
2
+ import type { ColumnTable, ExpandableConfig, IFormat, IWrapSettings, Locale, RangeState, RecordDoubleClickEventArgs, SelectionSettings } from "./type";
3
3
  import type { SubmitHandler } from "react-hook-form";
4
4
  import type { ExpandedState } from '@tanstack/react-table';
5
5
  export type IPositionCell = {
@@ -66,6 +66,7 @@ export interface IContext<T> {
66
66
  handleAddMulti?: (item: any, n: number, id?: string) => void;
67
67
  dataErrors?: any[];
68
68
  isDataTree: boolean;
69
+ handleCellClick?: (rowNumber: number, record: T, column: ColumnTable, rowId: string, cellValue: any) => void;
69
70
  }
70
71
  export declare const TableContext: import("react").Context<IContext<any>>;
71
72
  export type ContextCellChange = {
@@ -16,5 +16,6 @@ export const TableContext = /*#__PURE__*/createContext({
16
16
  setIsSelectionChange: () => {},
17
17
  setSorterChange: () => {},
18
18
  setFilterChange: () => {},
19
- setExpanded: () => {}
19
+ setExpanded: () => {},
20
+ handleCellClick: () => {}
20
21
  });
@@ -57,8 +57,8 @@ const SELECTION_COLUMN = exports.SELECTION_COLUMN = {};
57
57
  const InternalTable = props => {
58
58
  const {
59
59
  t,
60
- // columns: propsColumns,
61
- columns,
60
+ columns: propsColumns,
61
+ // columns,
62
62
  lang,
63
63
  locale,
64
64
  dataSource,
@@ -132,6 +132,10 @@ const InternalTable = props => {
132
132
  const [filterStates, setFilterState] = _react.default.useState(null);
133
133
  const [sorterStates, setSorterStates] = _react.default.useState([]);
134
134
  const [isFullScreen, setIsFullScreen] = _react.default.useState(false);
135
+ const [columns, setColumns] = _react.default.useState([]);
136
+ _react.default.useEffect(() => {
137
+ setColumns(propsColumns);
138
+ }, [propsColumns]);
135
139
  const [expanded, setExpanded] = _react.default.useState({});
136
140
  const convertData = _react.default.useMemo(() => {
137
141
  if (groupAble && groupSetting && groupSetting.client !== false) {
@@ -175,10 +179,14 @@ const InternalTable = props => {
175
179
  const [columnsHiddenKeys, setColumnsHiddenKeys] = (0, _useMergedState.default)(undefined, {
176
180
  value: undefined
177
181
  });
178
- const triggerChangeColumns = (cols, keys) => {
179
- const aa = (0, _utils.flatColumns2)(columns).map(it => it.field);
180
- const rsss = (0, _utils.getDiffent2Array)(aa, keys);
181
- setColumnsHiddenKeys(rsss);
182
+ const triggerChangeColumns = (cols, keys, type) => {
183
+ if (type === 'cellClick') {
184
+ setColumns(cols);
185
+ } else {
186
+ const aa = (0, _utils.flatColumns2)(columns).map(it => it.field);
187
+ const rsss = (0, _utils.getDiffent2Array)(aa, keys);
188
+ setColumnsHiddenKeys(rsss);
189
+ }
182
190
  };
183
191
 
184
192
  // const contextMenuItems = React.useMemo(() => {
@@ -123,7 +123,8 @@ const TableContainerEdit = props => {
123
123
  contextMenuHidden,
124
124
  showDefaultContext,
125
125
  commandSettings,
126
- isDataTree
126
+ isDataTree,
127
+ onCellClick
127
128
  } = props;
128
129
  const containerRef = _react.default.useRef(null);
129
130
  const bottomToolbarRef = _react.default.useRef(null);
@@ -1449,6 +1450,33 @@ const TableContainerEdit = props => {
1449
1450
  }
1450
1451
  contextMenuClick?.(args);
1451
1452
  };
1453
+ const handleCellClick = (rowNumber, record, column, rowId, cellValue) => {
1454
+ const cellClickCallback = newOptions => {
1455
+ if (newOptions) {
1456
+ const newElem = {
1457
+ ...column,
1458
+ editSelectSettings: {
1459
+ ...(column?.editSelectSettings ? {
1460
+ ...column?.editSelectSettings
1461
+ } : {}),
1462
+ options: newOptions
1463
+ }
1464
+ };
1465
+ const rrr = (0, _utils.updateArrayByKey)([...columns], newElem, 'field');
1466
+ triggerChangeColumns?.(rrr, 'click');
1467
+ }
1468
+ };
1469
+ if (onCellClick) {
1470
+ onCellClick({
1471
+ index: rowNumber,
1472
+ rowId,
1473
+ cellValue,
1474
+ type: "Editing",
1475
+ field: column.field,
1476
+ rowData: record
1477
+ }, cellClickCallback);
1478
+ }
1479
+ };
1452
1480
  return /*#__PURE__*/_react.default.createElement("div", {
1453
1481
  ref: containerRef,
1454
1482
  id: id
@@ -1561,7 +1589,8 @@ const TableContainerEdit = props => {
1561
1589
  handleDeleteContent,
1562
1590
  handleAddMulti,
1563
1591
  dataErrors,
1564
- windowSize
1592
+ windowSize,
1593
+ handleCellClick
1565
1594
  }
1566
1595
  }, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, {
1567
1596
  contextMenuItems: contextMenuItems,
@@ -135,7 +135,8 @@ const TableBodyCellEdit = props => {
135
135
  expanded,
136
136
  setExpanded,
137
137
  expandable,
138
- isDataTree
138
+ isDataTree,
139
+ handleCellClick
139
140
  } = _react.default.useContext(_useContext.TableContext);
140
141
  const expandIconColumnIndex = expandable?.expandIconColumnIndex;
141
142
  const record = cell.row.original;
@@ -422,6 +423,7 @@ const TableBodyCellEdit = props => {
422
423
  setEditingKey?.(record[rowKey]);
423
424
  // setTooltipContent('')
424
425
 
426
+ handleCellClick?.(rowNumber, record, columnMeta, record[rowKey], record[columnMeta.field ?? '']);
425
427
  reset?.();
426
428
 
427
429
  // const formattedRecord = { ...record };
@@ -882,6 +884,9 @@ const TableBodyCellEdit = props => {
882
884
  rowId: cell.row.id,
883
885
  colId: cell.column.id
884
886
  });
887
+ if (canEdit) {
888
+ handleCellClick?.(rowNumber, record, columnMeta, record[rowKey], record[columnMeta.field ?? '']);
889
+ }
885
890
  } else {
886
891
  handleMouseDown(cell.row.id, cell.column.id);
887
892
  if (editingKey) {
@@ -40,7 +40,7 @@ export declare function groupArrayByColumns(arr: any[], columns: string[] | unde
40
40
  export declare const flatColumns2: <RecordType>(columns: ColumnsTable<RecordType>) => ColumnsTable<RecordType>;
41
41
  export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
42
42
  export declare const checkDecimalSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
43
- export declare function getFixedFields(columns: ColumnTable[], type: 'left' | 'right'): string[];
43
+ export declare const getFixedFields: <T>(columns: ColumnsTable<T>, type: 'left' | 'right') => string[];
44
44
  export declare function areStringArraysEqual(a: string[], b: string[]): boolean;
45
45
  export declare const getDefaultOperator: (col: ColumnTable) => FilterOperator;
46
46
  export declare function isEqualSet(setA: any, setB: any): boolean;
@@ -23,9 +23,7 @@ exports.filterDataByColumns = filterDataByColumns;
23
23
  exports.getAllVisibleKeys1 = exports.getAllVisibleKeys = exports.getAllRowKey = exports.genPresets = exports.flattenData = exports.flattenArray = exports.flatColumns2 = exports.findItemByKey = void 0;
24
24
  exports.getCellsByPosition = getCellsByPosition;
25
25
  exports.getColIdsBetween = getColIdsBetween;
26
- exports.getEditType = exports.getDiffent2Array = exports.getDefaultValue = exports.getDefaultOperator = exports.getDatepickerFormat = exports.getDateRangeFormat = exports.getCommonPinningStyles = void 0;
27
- exports.getFixedFields = getFixedFields;
28
- exports.getFormat = void 0;
26
+ exports.getFormat = exports.getFixedFields = exports.getEditType = exports.getDiffent2Array = exports.getDefaultValue = exports.getDefaultOperator = exports.getDatepickerFormat = exports.getDateRangeFormat = exports.getCommonPinningStyles = void 0;
29
27
  exports.getHiddenParentKeys = getHiddenParentKeys;
30
28
  exports.getHiddenParentKeys1 = getHiddenParentKeys1;
31
29
  exports.getInvisibleColumns = getInvisibleColumns;
@@ -367,7 +365,7 @@ const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
367
365
  }
368
366
  };
369
367
  exports.checkDecimalSeparator = checkDecimalSeparator;
370
- function getFixedFields(columns, type) {
368
+ const getFixedFields = (columns, type) => {
371
369
  const result = [];
372
370
  function traverse(cols) {
373
371
  for (const col of cols) {
@@ -381,7 +379,8 @@ function getFixedFields(columns, type) {
381
379
  }
382
380
  traverse(columns);
383
381
  return result;
384
- }
382
+ };
383
+ exports.getFixedFields = getFixedFields;
385
384
  function areStringArraysEqual(a, b) {
386
385
  if (a.length !== b.length) return false;
387
386
  const sortedA = [...a].sort();
@@ -7,7 +7,7 @@ type Props<T> = Omit<TableProps<T>, 'columns'> & {
7
7
  rowKey: string;
8
8
  prefix: string;
9
9
  columns: ColumnDef<T>[];
10
- propsColumns: ColumnsTable;
10
+ propsColumns: ColumnsTable<T>;
11
11
  columnHidden: VisibilityState;
12
12
  expanded: ExpandedState;
13
13
  setExpanded: any;
@@ -20,7 +20,7 @@ type Props<T> = Omit<TableProps<T>, 'columns'> & {
20
20
  triggerFilter: Dispatch<SetStateAction<any>>;
21
21
  triggerSorter: Dispatch<SetStateAction<Sorter[]>>;
22
22
  onContextMenu?: (data: T) => (event: any) => void;
23
- triggerChangeColumns?: (args: any, keys: any) => void;
23
+ triggerChangeColumns?: (args: any, keys: any, type: string) => void;
24
24
  windowSize: any;
25
25
  isDataTree: boolean;
26
26
  };
@@ -1,5 +1,5 @@
1
1
  import type { Dispatch, SetStateAction } from 'react';
2
- import type { ExpandableConfig, IFormat, IWrapSettings, Locale, RangeState, RecordDoubleClickEventArgs, SelectionSettings } from "./type";
2
+ import type { ColumnTable, ExpandableConfig, IFormat, IWrapSettings, Locale, RangeState, RecordDoubleClickEventArgs, SelectionSettings } from "./type";
3
3
  import type { SubmitHandler } from "react-hook-form";
4
4
  import type { ExpandedState } from '@tanstack/react-table';
5
5
  export type IPositionCell = {
@@ -66,6 +66,7 @@ export interface IContext<T> {
66
66
  handleAddMulti?: (item: any, n: number, id?: string) => void;
67
67
  dataErrors?: any[];
68
68
  isDataTree: boolean;
69
+ handleCellClick?: (rowNumber: number, record: T, column: ColumnTable, rowId: string, cellValue: any) => void;
69
70
  }
70
71
  export declare const TableContext: import("react").Context<IContext<any>>;
71
72
  export type ContextCellChange = {
@@ -22,5 +22,6 @@ const TableContext = exports.TableContext = /*#__PURE__*/(0, _react.createContex
22
22
  setIsSelectionChange: () => {},
23
23
  setSorterChange: () => {},
24
24
  setFilterChange: () => {},
25
- setExpanded: () => {}
25
+ setExpanded: () => {},
26
+ handleCellClick: () => {}
26
27
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.7.34",
3
+ "version": "1.7.35",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",