es-grid-template 1.8.78 → 1.8.80

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.
@@ -224,6 +224,7 @@ export type TableProps<RecordType = AnyObject> = {
224
224
  rowKey?: string;
225
225
  infiniteScroll?: boolean;
226
226
  next?: () => void;
227
+ onEndReachedThreshold?: number;
227
228
  locale?: Locale;
228
229
  groupAble?: boolean;
229
230
  groupColumns?: string[];
@@ -247,6 +248,7 @@ export type TableProps<RecordType = AnyObject> = {
247
248
  contextMenuOpen?: (args: Omit<ContextInfo<RecordType>, 'item'>) => void;
248
249
  contextMenuClick?: (args: ContextInfo<RecordType>) => void;
249
250
  recordDoubleClick?: (args: RecordDoubleClickEventArgs<RecordType>) => void;
251
+ recordClick?: (args: RecordDoubleClickEventArgs<RecordType>) => void;
250
252
  toolbarItems?: ToolbarItem[];
251
253
  showColumnChoose?: boolean;
252
254
  showAdvanceFilter?: boolean;
@@ -165,7 +165,7 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
165
165
  type?: IColumnType;
166
166
  haveSum?: boolean;
167
167
  isSummary?: boolean;
168
- summaryTemplate?: (data: number, key: string) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
168
+ summaryTemplate?: (data: number, key: string) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode;
169
169
  format?: IFormat | ((rowData: any) => IFormat);
170
170
  allowFiltering?: boolean;
171
171
  sorter?: boolean;
@@ -180,18 +180,18 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
180
180
  headerText?: string;
181
181
  hidden?: boolean;
182
182
  visible?: boolean;
183
- headerTooltip?: string | boolean | (() => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
183
+ headerTooltip?: string | boolean | (() => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
184
184
  columnGroupText?: string;
185
185
  align?: import("./../../grid-component/type").ITextAlign;
186
186
  textAlign?: import("./../../grid-component/type").ITextAlign;
187
187
  headerTextAlign?: import("./../../grid-component/type").ITextAlign;
188
- template?: import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
188
+ template?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
189
189
  showTooltip?: boolean;
190
190
  tooltipDescription?: string | ((args: {
191
191
  value: any;
192
192
  rowData: RecordType;
193
- }) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
194
- headerTemplate?: import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | ((column: ColumnTable<RecordType>) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
193
+ }) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
194
+ headerTemplate?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode | ((column: ColumnTable<RecordType>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
195
195
  commandItems?: import("./../../grid-component/type").CommandItem[];
196
196
  children?: ColumnTable<RecordType>[];
197
197
  editType?: EditType | ((rowData?: RecordType) => EditType);
@@ -211,9 +211,9 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
211
211
  ellipsis?: boolean;
212
212
  allowResizing?: boolean;
213
213
  allowSelection?: boolean | ((rowData: RecordType) => boolean);
214
- onCellStyles?: Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width">);
215
- onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width">);
216
- onCellFooterStyles?: Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width">);
214
+ onCellStyles?: Omit<CSSProperties, "position" | "display" | "left" | "minWidth" | "right" | "width"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "position" | "display" | "left" | "minWidth" | "right" | "width">);
215
+ onCellHeaderStyles?: Omit<CSSProperties, "position" | "display" | "left" | "minWidth" | "right" | "width"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "position" | "display" | "left" | "minWidth" | "right" | "width">);
216
+ onCellFooterStyles?: Omit<CSSProperties, "position" | "display" | "left" | "minWidth" | "right" | "width"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "position" | "display" | "left" | "minWidth" | "right" | "width">);
217
217
  sumGroup?: boolean;
218
218
  onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
219
219
  }[];
@@ -73,7 +73,9 @@ const TableContainer = props => {
73
73
  title,
74
74
  dataSourceFilter,
75
75
  onExpandClick,
76
- setIsExpandClick
76
+ setIsExpandClick,
77
+ recordClick,
78
+ ...rest
77
79
  } = props;
78
80
  const [paginationLocal] = useLocale('Pagination');
79
81
  const [tableLocal] = useLocale('Table');
@@ -266,6 +268,7 @@ const TableContainer = props => {
266
268
  // triggerFilter,
267
269
  wrapSettings,
268
270
  recordDoubleClick,
271
+ recordClick,
269
272
  selectionSettings,
270
273
  isSelectionChange,
271
274
  setIsSelectionChange,
@@ -286,7 +289,7 @@ const TableContainer = props => {
286
289
  onExpandClick,
287
290
  setIsExpandClick
288
291
  }
289
- }, /*#__PURE__*/React.createElement(TableWrapper, {
292
+ }, /*#__PURE__*/React.createElement(TableWrapper, _extends({}, rest, {
290
293
  contextMenuItems: contextMenuItems,
291
294
  height: tableHeight,
292
295
  minHeight: minHeight,
@@ -310,7 +313,7 @@ const TableContainer = props => {
310
313
  virtualPaddingRight: virtualPaddingRight,
311
314
  fixedLeftColumns: fixedLeftColumns,
312
315
  fixedRightColumns: fixedRightColumns
313
- })), /*#__PURE__*/React.createElement("div", {
316
+ }))), /*#__PURE__*/React.createElement("div", {
314
317
  ref: bottomToolbarRef
315
318
  }, pagination && !infiniteScroll && /*#__PURE__*/React.createElement(Pagination, _extends({
316
319
  pageSizeOptions: [20, 50, 100, 1000, 10000],
@@ -176,7 +176,8 @@ const TableBodyCell = props => {
176
176
  selectionSettings,
177
177
  wrapSettings,
178
178
  pagination,
179
- onExpandClick
179
+ onExpandClick,
180
+ recordClick
180
181
  // dataSource
181
182
  } = React.useContext(TableContext);
182
183
  const expandIconColumnIndex = expandable?.expandIconColumnIndex ?? 0;
@@ -428,6 +429,11 @@ const TableBodyCell = props => {
428
429
  }
429
430
  },
430
431
  onClick: e => {
432
+ recordClick?.({
433
+ e,
434
+ rowData: record,
435
+ rowIndex: rowNumber
436
+ });
431
437
  const selection = window.getSelection();
432
438
  const text = selection ? selection.toString() : "";
433
439
  if (text.length > 0 || enableClick === false) {} else {
@@ -95,11 +95,14 @@ export const renderFilter = args => {
95
95
  format: dateRangeFormat,
96
96
  value: dateRangeValue,
97
97
  onChange: value => {
98
- console.log('value', value);
99
98
  const newDateRangeValue = value ? [value[0] ? moment(value[0]).format() : '', value[1] ? moment(value[1]).format() : ''] : [];
100
- console.log('newDateRangeValue', newDateRangeValue);
101
99
  setSelectedKeys(newDateRangeValue);
102
- },
100
+ }
101
+
102
+ // onSelect={(val) => {
103
+ // }}
104
+ ,
105
+
103
106
  menuClassName: "rc-menu-popup",
104
107
  placement: "auto"
105
108
  }))));
@@ -23,6 +23,7 @@ type Props<T> = {
23
23
  dataSource: T[];
24
24
  pagination?: false | PaginationConfig;
25
25
  infiniteScroll?: boolean;
26
+ onEndReachedThreshold?: number;
26
27
  columnVirtualizer: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
27
28
  virtualPaddingLeft: number | undefined;
28
29
  virtualPaddingRight: number | undefined;
@@ -7,6 +7,7 @@ import { Tooltip } from "react-tooltip";
7
7
  import ContextMenu from "../ContextMenu";
8
8
  import React, { useContext } from "react";
9
9
  import { TableContext } from "../useContext";
10
+ import { isNullOrUndefined } from "../hook/utils";
10
11
  const TableWrapper = props => {
11
12
  const {
12
13
  id,
@@ -28,6 +29,7 @@ const TableWrapper = props => {
28
29
  dataSource,
29
30
  pagination,
30
31
  infiniteScroll,
32
+ onEndReachedThreshold,
31
33
  columnVirtualizer,
32
34
  fixedLeftColumns,
33
35
  fixedRightColumns,
@@ -93,7 +95,9 @@ const TableWrapper = props => {
93
95
  scrollTop,
94
96
  clientHeight
95
97
  } = e.currentTarget;
96
- const isEnd = scrollTop + clientHeight >= tbScrollHeight - 50;
98
+ const abc = clientHeight * (isNullOrUndefined(onEndReachedThreshold) ? 0.1 : onEndReachedThreshold ?? 0);
99
+ // const isEnd = scrollTop + clientHeight >= tbScrollHeight - 50;
100
+ const isEnd = scrollTop + clientHeight >= tbScrollHeight - abc;
97
101
  if (isEnd && !loadingRef.current && hasMoreRef.current && dataSource?.length > 0) {
98
102
  handleNext();
99
103
  }
@@ -19,6 +19,7 @@ export interface IContext<T> {
19
19
  setExpanded: Dispatch<SetStateAction<ExpandedState>>;
20
20
  expanded: ExpandedState;
21
21
  recordDoubleClick?: (args: RecordDoubleClickEventArgs<T>) => void;
22
+ recordClick?: (args: RecordDoubleClickEventArgs<T>) => void;
22
23
  selectionSettings?: SelectionSettings;
23
24
  isSelectionChange?: {
24
25
  isChange: boolean;
@@ -398,7 +398,8 @@ const InternalTable = props => {
398
398
  columnSizing: columnSizing,
399
399
  columnSizingInfo: columnSizingInfo,
400
400
  setColumnSizing: setColumnSizing,
401
- rowSelection: rowSelection
401
+ rowSelection: rowSelection,
402
+ pagination: pagination
402
403
  })))));
403
404
  };
404
405
  export default InternalTable;
@@ -347,8 +347,12 @@ const TableBodyCell = props => {
347
347
  ...getCommonPinningStyles(cell.column)
348
348
  },
349
349
  onMouseEnter: e => {
350
- if (e.target.firstChild?.clientWidth < e.target.firstChild?.scrollWidth) {
350
+ if (e.target?.firstChild?.className === 'ui-rc_cell-content' && e.target.firstChild?.clientWidth < e.target.firstChild?.scrollWidth) {
351
351
  setIsOpenTooltip(true);
352
+ } else {
353
+ if (e.target?.clientWidth < e.target?.scrollWidth) {
354
+ setIsOpenTooltip(true);
355
+ }
352
356
  }
353
357
  },
354
358
  onKeyDown: e => {
@@ -73,7 +73,8 @@ const TableContainer = props => {
73
73
  onRowFooterStyles,
74
74
  onRowHeaderStyles,
75
75
  title,
76
- groupSetting
76
+ groupSetting,
77
+ ...rest
77
78
  } = props;
78
79
  const [paginationLocal] = useLocale('Pagination');
79
80
  const [tableLocal] = useLocale('Table');
@@ -250,7 +251,7 @@ const TableContainer = props => {
250
251
  pagination,
251
252
  groupSetting
252
253
  }
253
- }, /*#__PURE__*/React.createElement(TableWrapper, {
254
+ }, /*#__PURE__*/React.createElement(TableWrapper, _extends({}, rest, {
254
255
  tableContainerRef: tableContainerRef,
255
256
  prefix: prefix,
256
257
  id: id,
@@ -260,7 +261,7 @@ const TableContainer = props => {
260
261
  table: table,
261
262
  columns: columns,
262
263
  commandClick: triggerCommandClick
263
- })), /*#__PURE__*/React.createElement("div", {
264
+ }))), /*#__PURE__*/React.createElement("div", {
264
265
  ref: bottomToolbarRef
265
266
  }, pagination && !infiniteScroll && /*#__PURE__*/React.createElement(Pagination, _extends({
266
267
  pageSizeOptions: [20, 50, 100, 1000, 10000],
@@ -14,7 +14,8 @@ import { TableContext } from "../useContext";
14
14
  import classNames from 'classnames';
15
15
  import TableBodyRow from "../body/TableBodyRow";
16
16
  import TableFooterCell from "../footer/TableFooterCell";
17
-
17
+ import { Tooltip } from 'react-tooltip';
18
+ import ContextMenu from "../../table-component/ContextMenu";
18
19
  // import type { ColumnsTable, TableProps } from '../type';
19
20
 
20
21
  // type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
@@ -25,19 +26,103 @@ const TableWrapper = props => {
25
26
  height,
26
27
  id,
27
28
  commandClick,
28
- editAble
29
+ editAble,
30
+ contextMenuItems: propContextMenuItems,
31
+ contextMenuHidden,
32
+ contextMenuClick,
33
+ contextMenuOpen
29
34
  } = props;
35
+ const menuRef = React.useRef(null);
30
36
  const {
31
37
  prefix,
32
38
  editingKey,
33
- rowEditable
39
+ rowEditable,
40
+ windowSize
34
41
  } = useContext(TableContext); //onRowHeaderStyles
42
+ // const { windowSize } = useContext(TableContext)
35
43
 
36
44
  // ref cho scroll container
37
45
  const scrollRef = useRef(null);
38
46
  const {
39
47
  rows
40
48
  } = table.getRowModel();
49
+ const [menuVisible, setMenuVisible] = React.useState(false);
50
+ const [selectedRowData, setSelectedRowData] = React.useState(null);
51
+ const [position, setPosition] = React.useState({
52
+ x: 0,
53
+ y: 0,
54
+ viewportWidth: windowSize.innerWidth,
55
+ viewportHeight: windowSize.innerHeight
56
+ });
57
+ const contextMenuItems = React.useMemo(() => {
58
+ if (typeof contextMenuHidden === 'function' && propContextMenuItems && selectedRowData) {
59
+ const hiddenItems = contextMenuHidden({
60
+ rowInfo: {
61
+ rowData: selectedRowData
62
+ }
63
+ });
64
+ return propContextMenuItems.filter(item => !hiddenItems.includes(item?.key));
65
+ }
66
+ if (contextMenuHidden && typeof contextMenuHidden !== 'function' && propContextMenuItems) {
67
+ return propContextMenuItems.filter(item => !contextMenuHidden.includes(item?.key));
68
+ }
69
+ return propContextMenuItems;
70
+ }, [propContextMenuItems, contextMenuHidden, selectedRowData]);
71
+ const onContextMenu = data => event => {
72
+ event.preventDefault(); // Ngăn chặn menu mặc định của trình duyệt
73
+
74
+ setSelectedRowData(data);
75
+ contextMenuOpen?.({
76
+ rowInfo: {
77
+ rowData: data
78
+ },
79
+ event
80
+ });
81
+ setMenuVisible(true);
82
+
83
+ // Đợi DOM cập nhật và lấy kích thước menu
84
+ setTimeout(() => {
85
+ const menuElement = menuRef.current; // Lấy menu từ DOM
86
+ const menuWidth = menuElement?.offsetWidth || 200; // Mặc định 200px nếu chưa render
87
+ const menuHeight = menuElement?.offsetHeight; // Mặc định 450px nếu chưa render
88
+
89
+ // Điều chỉnh vị trí menu
90
+ let x = event.clientX;
91
+ let y = event.clientY;
92
+ if (x + menuWidth > windowSize.innerWidth) {
93
+ x = x - menuWidth - 10; // Cách cạnh phải 10px
94
+ }
95
+ if (y + menuHeight > windowSize.innerHeight) {
96
+ if (y < menuHeight) {
97
+ y = 10;
98
+ } else {
99
+ y = y - 10 - menuHeight; // Cách cạnh dưới 10px
100
+ }
101
+ }
102
+ setPosition(prevState => ({
103
+ ...prevState,
104
+ x,
105
+ y
106
+ }));
107
+ }, 100);
108
+ if (!menuVisible) {
109
+ document.addEventListener(`click`, function onClickOutside(e) {
110
+ const element = e.target;
111
+ const menuContainer = document.querySelector('.popup-context-menu');
112
+ const isInsideContainer = element.closest('.popup-context-menu') && menuContainer;
113
+ if (isInsideContainer) {
114
+ return;
115
+ }
116
+ setMenuVisible(false);
117
+ setPosition(prevState => ({
118
+ ...prevState,
119
+ x: undefined,
120
+ y: undefined
121
+ }));
122
+ document.removeEventListener(`click`, onClickOutside);
123
+ });
124
+ }
125
+ };
41
126
  return /*#__PURE__*/React.createElement("div", {
42
127
  className: classNames(`${prefix}-grid-container`, {})
43
128
  }, /*#__PURE__*/React.createElement("div", {
@@ -102,7 +187,9 @@ const TableWrapper = props => {
102
187
  rowheight: editAble ? 37 : rowheight,
103
188
  isEditing: isEditing,
104
189
  isRowEditable: isRowEditable,
105
- editAble: editAble
190
+ editAble: editAble,
191
+ onContextMenu: onContextMenu,
192
+ contextMenuItems: contextMenuItems
106
193
  }, rest));
107
194
  }
108
195
  },
@@ -159,6 +246,27 @@ const TableWrapper = props => {
159
246
  });
160
247
  }));
161
248
  }
162
- })));
249
+ })), /*#__PURE__*/React.createElement(Tooltip, {
250
+ id: `${id}-tooltip-content`,
251
+ style: {
252
+ zIndex: 1999,
253
+ maxWidth: 450
254
+ },
255
+ delayShow: 100
256
+ }), /*#__PURE__*/React.createElement(Tooltip, {
257
+ id: `${id}-tooltip-error`,
258
+ style: {
259
+ zIndex: 1999,
260
+ maxWidth: 450
261
+ }
262
+ }), menuVisible && /*#__PURE__*/React.createElement(ContextMenu, {
263
+ open: menuVisible,
264
+ pos: position,
265
+ setOpen: setMenuVisible,
266
+ menuRef: menuRef,
267
+ contextMenuItems: contextMenuItems,
268
+ contextMenuClick: contextMenuClick,
269
+ rowData: selectedRowData
270
+ }));
163
271
  };
164
272
  export default TableWrapper;
@@ -224,6 +224,7 @@ export type TableProps<RecordType = AnyObject> = {
224
224
  rowKey?: string;
225
225
  infiniteScroll?: boolean;
226
226
  next?: () => void;
227
+ onEndReachedThreshold?: number;
227
228
  locale?: Locale;
228
229
  groupAble?: boolean;
229
230
  groupColumns?: string[];
@@ -247,6 +248,7 @@ export type TableProps<RecordType = AnyObject> = {
247
248
  contextMenuOpen?: (args: Omit<ContextInfo<RecordType>, 'item'>) => void;
248
249
  contextMenuClick?: (args: ContextInfo<RecordType>) => void;
249
250
  recordDoubleClick?: (args: RecordDoubleClickEventArgs<RecordType>) => void;
251
+ recordClick?: (args: RecordDoubleClickEventArgs<RecordType>) => void;
250
252
  toolbarItems?: ToolbarItem[];
251
253
  showColumnChoose?: boolean;
252
254
  showAdvanceFilter?: boolean;
@@ -80,7 +80,9 @@ const TableContainer = props => {
80
80
  title,
81
81
  dataSourceFilter,
82
82
  onExpandClick,
83
- setIsExpandClick
83
+ setIsExpandClick,
84
+ recordClick,
85
+ ...rest
84
86
  } = props;
85
87
  const [paginationLocal] = (0, _locale.useLocale)('Pagination');
86
88
  const [tableLocal] = (0, _locale.useLocale)('Table');
@@ -273,6 +275,7 @@ const TableContainer = props => {
273
275
  // triggerFilter,
274
276
  wrapSettings,
275
277
  recordDoubleClick,
278
+ recordClick,
276
279
  selectionSettings,
277
280
  isSelectionChange,
278
281
  setIsSelectionChange,
@@ -293,7 +296,7 @@ const TableContainer = props => {
293
296
  onExpandClick,
294
297
  setIsExpandClick
295
298
  }
296
- }, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, {
299
+ }, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, (0, _extends2.default)({}, rest, {
297
300
  contextMenuItems: contextMenuItems,
298
301
  height: tableHeight,
299
302
  minHeight: minHeight,
@@ -317,7 +320,7 @@ const TableContainer = props => {
317
320
  virtualPaddingRight: virtualPaddingRight,
318
321
  fixedLeftColumns: fixedLeftColumns,
319
322
  fixedRightColumns: fixedRightColumns
320
- })), /*#__PURE__*/_react.default.createElement("div", {
323
+ }))), /*#__PURE__*/_react.default.createElement("div", {
321
324
  ref: bottomToolbarRef
322
325
  }, pagination && !infiniteScroll && /*#__PURE__*/_react.default.createElement(_pagination.default, (0, _extends2.default)({
323
326
  pageSizeOptions: [20, 50, 100, 1000, 10000],
@@ -183,7 +183,8 @@ const TableBodyCell = props => {
183
183
  selectionSettings,
184
184
  wrapSettings,
185
185
  pagination,
186
- onExpandClick
186
+ onExpandClick,
187
+ recordClick
187
188
  // dataSource
188
189
  } = _react.default.useContext(_useContext.TableContext);
189
190
  const expandIconColumnIndex = expandable?.expandIconColumnIndex ?? 0;
@@ -435,6 +436,11 @@ const TableBodyCell = props => {
435
436
  }
436
437
  },
437
438
  onClick: e => {
439
+ recordClick?.({
440
+ e,
441
+ rowData: record,
442
+ rowIndex: rowNumber
443
+ });
438
444
  const selection = window.getSelection();
439
445
  const text = selection ? selection.toString() : "";
440
446
  if (text.length > 0 || enableClick === false) {} else {
@@ -104,11 +104,14 @@ const renderFilter = args => {
104
104
  format: dateRangeFormat,
105
105
  value: dateRangeValue,
106
106
  onChange: value => {
107
- console.log('value', value);
108
107
  const newDateRangeValue = value ? [value[0] ? (0, _moment.default)(value[0]).format() : '', value[1] ? (0, _moment.default)(value[1]).format() : ''] : [];
109
- console.log('newDateRangeValue', newDateRangeValue);
110
108
  setSelectedKeys(newDateRangeValue);
111
- },
109
+ }
110
+
111
+ // onSelect={(val) => {
112
+ // }}
113
+ ,
114
+
112
115
  menuClassName: "rc-menu-popup",
113
116
  placement: "auto"
114
117
  }))));
@@ -23,6 +23,7 @@ type Props<T> = {
23
23
  dataSource: T[];
24
24
  pagination?: false | PaginationConfig;
25
25
  infiniteScroll?: boolean;
26
+ onEndReachedThreshold?: number;
26
27
  columnVirtualizer: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
27
28
  virtualPaddingLeft: number | undefined;
28
29
  virtualPaddingRight: number | undefined;
@@ -14,6 +14,7 @@ var _reactTooltip = require("react-tooltip");
14
14
  var _ContextMenu = _interopRequireDefault(require("../ContextMenu"));
15
15
  var _react = _interopRequireWildcard(require("react"));
16
16
  var _useContext = require("../useContext");
17
+ var _utils = require("../hook/utils");
17
18
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
18
19
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
20
  const TableWrapper = props => {
@@ -37,6 +38,7 @@ const TableWrapper = props => {
37
38
  dataSource,
38
39
  pagination,
39
40
  infiniteScroll,
41
+ onEndReachedThreshold,
40
42
  columnVirtualizer,
41
43
  fixedLeftColumns,
42
44
  fixedRightColumns,
@@ -102,7 +104,9 @@ const TableWrapper = props => {
102
104
  scrollTop,
103
105
  clientHeight
104
106
  } = e.currentTarget;
105
- const isEnd = scrollTop + clientHeight >= tbScrollHeight - 50;
107
+ const abc = clientHeight * ((0, _utils.isNullOrUndefined)(onEndReachedThreshold) ? 0.1 : onEndReachedThreshold ?? 0);
108
+ // const isEnd = scrollTop + clientHeight >= tbScrollHeight - 50;
109
+ const isEnd = scrollTop + clientHeight >= tbScrollHeight - abc;
106
110
  if (isEnd && !loadingRef.current && hasMoreRef.current && dataSource?.length > 0) {
107
111
  handleNext();
108
112
  }
@@ -19,6 +19,7 @@ export interface IContext<T> {
19
19
  setExpanded: Dispatch<SetStateAction<ExpandedState>>;
20
20
  expanded: ExpandedState;
21
21
  recordDoubleClick?: (args: RecordDoubleClickEventArgs<T>) => void;
22
+ recordClick?: (args: RecordDoubleClickEventArgs<T>) => void;
22
23
  selectionSettings?: SelectionSettings;
23
24
  isSelectionChange?: {
24
25
  isChange: boolean;
@@ -408,7 +408,8 @@ const InternalTable = props => {
408
408
  columnSizing: columnSizing,
409
409
  columnSizingInfo: columnSizingInfo,
410
410
  setColumnSizing: setColumnSizing,
411
- rowSelection: rowSelection
411
+ rowSelection: rowSelection,
412
+ pagination: pagination
412
413
  })))));
413
414
  };
414
415
  var _default = exports.default = InternalTable;
@@ -354,8 +354,12 @@ const TableBodyCell = props => {
354
354
  ...(0, _utils.getCommonPinningStyles)(cell.column)
355
355
  },
356
356
  onMouseEnter: e => {
357
- if (e.target.firstChild?.clientWidth < e.target.firstChild?.scrollWidth) {
357
+ if (e.target?.firstChild?.className === 'ui-rc_cell-content' && e.target.firstChild?.clientWidth < e.target.firstChild?.scrollWidth) {
358
358
  setIsOpenTooltip(true);
359
+ } else {
360
+ if (e.target?.clientWidth < e.target?.scrollWidth) {
361
+ setIsOpenTooltip(true);
362
+ }
359
363
  }
360
364
  },
361
365
  onKeyDown: e => {
@@ -81,7 +81,8 @@ const TableContainer = props => {
81
81
  onRowFooterStyles,
82
82
  onRowHeaderStyles,
83
83
  title,
84
- groupSetting
84
+ groupSetting,
85
+ ...rest
85
86
  } = props;
86
87
  const [paginationLocal] = (0, _locale.useLocale)('Pagination');
87
88
  const [tableLocal] = (0, _locale.useLocale)('Table');
@@ -258,7 +259,7 @@ const TableContainer = props => {
258
259
  pagination,
259
260
  groupSetting
260
261
  }
261
- }, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, {
262
+ }, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, (0, _extends2.default)({}, rest, {
262
263
  tableContainerRef: tableContainerRef,
263
264
  prefix: prefix,
264
265
  id: id,
@@ -268,7 +269,7 @@ const TableContainer = props => {
268
269
  table: table,
269
270
  columns: columns,
270
271
  commandClick: triggerCommandClick
271
- })), /*#__PURE__*/_react.default.createElement("div", {
272
+ }))), /*#__PURE__*/_react.default.createElement("div", {
272
273
  ref: bottomToolbarRef
273
274
  }, pagination && !infiniteScroll && /*#__PURE__*/_react.default.createElement(_pagination.default, (0, _extends2.default)({
274
275
  pageSizeOptions: [20, 50, 100, 1000, 10000],
@@ -14,6 +14,8 @@ var _useContext = require("../useContext");
14
14
  var _classnames = _interopRequireDefault(require("classnames"));
15
15
  var _TableBodyRow = _interopRequireDefault(require("../body/TableBodyRow"));
16
16
  var _TableFooterCell = _interopRequireDefault(require("../footer/TableFooterCell"));
17
+ var _reactTooltip = require("react-tooltip");
18
+ var _ContextMenu = _interopRequireDefault(require("../../table-component/ContextMenu"));
17
19
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
18
20
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
21
  /* eslint-disable @typescript-eslint/no-shadow */
@@ -30,19 +32,103 @@ const TableWrapper = props => {
30
32
  height,
31
33
  id,
32
34
  commandClick,
33
- editAble
35
+ editAble,
36
+ contextMenuItems: propContextMenuItems,
37
+ contextMenuHidden,
38
+ contextMenuClick,
39
+ contextMenuOpen
34
40
  } = props;
41
+ const menuRef = _react.default.useRef(null);
35
42
  const {
36
43
  prefix,
37
44
  editingKey,
38
- rowEditable
45
+ rowEditable,
46
+ windowSize
39
47
  } = (0, _react.useContext)(_useContext.TableContext); //onRowHeaderStyles
48
+ // const { windowSize } = useContext(TableContext)
40
49
 
41
50
  // ref cho scroll container
42
51
  const scrollRef = (0, _react.useRef)(null);
43
52
  const {
44
53
  rows
45
54
  } = table.getRowModel();
55
+ const [menuVisible, setMenuVisible] = _react.default.useState(false);
56
+ const [selectedRowData, setSelectedRowData] = _react.default.useState(null);
57
+ const [position, setPosition] = _react.default.useState({
58
+ x: 0,
59
+ y: 0,
60
+ viewportWidth: windowSize.innerWidth,
61
+ viewportHeight: windowSize.innerHeight
62
+ });
63
+ const contextMenuItems = _react.default.useMemo(() => {
64
+ if (typeof contextMenuHidden === 'function' && propContextMenuItems && selectedRowData) {
65
+ const hiddenItems = contextMenuHidden({
66
+ rowInfo: {
67
+ rowData: selectedRowData
68
+ }
69
+ });
70
+ return propContextMenuItems.filter(item => !hiddenItems.includes(item?.key));
71
+ }
72
+ if (contextMenuHidden && typeof contextMenuHidden !== 'function' && propContextMenuItems) {
73
+ return propContextMenuItems.filter(item => !contextMenuHidden.includes(item?.key));
74
+ }
75
+ return propContextMenuItems;
76
+ }, [propContextMenuItems, contextMenuHidden, selectedRowData]);
77
+ const onContextMenu = data => event => {
78
+ event.preventDefault(); // Ngăn chặn menu mặc định của trình duyệt
79
+
80
+ setSelectedRowData(data);
81
+ contextMenuOpen?.({
82
+ rowInfo: {
83
+ rowData: data
84
+ },
85
+ event
86
+ });
87
+ setMenuVisible(true);
88
+
89
+ // Đợi DOM cập nhật và lấy kích thước menu
90
+ setTimeout(() => {
91
+ const menuElement = menuRef.current; // Lấy menu từ DOM
92
+ const menuWidth = menuElement?.offsetWidth || 200; // Mặc định 200px nếu chưa render
93
+ const menuHeight = menuElement?.offsetHeight; // Mặc định 450px nếu chưa render
94
+
95
+ // Điều chỉnh vị trí menu
96
+ let x = event.clientX;
97
+ let y = event.clientY;
98
+ if (x + menuWidth > windowSize.innerWidth) {
99
+ x = x - menuWidth - 10; // Cách cạnh phải 10px
100
+ }
101
+ if (y + menuHeight > windowSize.innerHeight) {
102
+ if (y < menuHeight) {
103
+ y = 10;
104
+ } else {
105
+ y = y - 10 - menuHeight; // Cách cạnh dưới 10px
106
+ }
107
+ }
108
+ setPosition(prevState => ({
109
+ ...prevState,
110
+ x,
111
+ y
112
+ }));
113
+ }, 100);
114
+ if (!menuVisible) {
115
+ document.addEventListener(`click`, function onClickOutside(e) {
116
+ const element = e.target;
117
+ const menuContainer = document.querySelector('.popup-context-menu');
118
+ const isInsideContainer = element.closest('.popup-context-menu') && menuContainer;
119
+ if (isInsideContainer) {
120
+ return;
121
+ }
122
+ setMenuVisible(false);
123
+ setPosition(prevState => ({
124
+ ...prevState,
125
+ x: undefined,
126
+ y: undefined
127
+ }));
128
+ document.removeEventListener(`click`, onClickOutside);
129
+ });
130
+ }
131
+ };
46
132
  return /*#__PURE__*/_react.default.createElement("div", {
47
133
  className: (0, _classnames.default)(`${prefix}-grid-container`, {})
48
134
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -107,7 +193,9 @@ const TableWrapper = props => {
107
193
  rowheight: editAble ? 37 : rowheight,
108
194
  isEditing: isEditing,
109
195
  isRowEditable: isRowEditable,
110
- editAble: editAble
196
+ editAble: editAble,
197
+ onContextMenu: onContextMenu,
198
+ contextMenuItems: contextMenuItems
111
199
  }, rest));
112
200
  }
113
201
  },
@@ -164,6 +252,27 @@ const TableWrapper = props => {
164
252
  });
165
253
  }));
166
254
  }
167
- })));
255
+ })), /*#__PURE__*/_react.default.createElement(_reactTooltip.Tooltip, {
256
+ id: `${id}-tooltip-content`,
257
+ style: {
258
+ zIndex: 1999,
259
+ maxWidth: 450
260
+ },
261
+ delayShow: 100
262
+ }), /*#__PURE__*/_react.default.createElement(_reactTooltip.Tooltip, {
263
+ id: `${id}-tooltip-error`,
264
+ style: {
265
+ zIndex: 1999,
266
+ maxWidth: 450
267
+ }
268
+ }), menuVisible && /*#__PURE__*/_react.default.createElement(_ContextMenu.default, {
269
+ open: menuVisible,
270
+ pos: position,
271
+ setOpen: setMenuVisible,
272
+ menuRef: menuRef,
273
+ contextMenuItems: contextMenuItems,
274
+ contextMenuClick: contextMenuClick,
275
+ rowData: selectedRowData
276
+ }));
168
277
  };
169
278
  var _default = exports.default = TableWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.8.78",
3
+ "version": "1.8.80",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",