es-grid-template 1.5.8 → 1.5.9

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.
@@ -13,7 +13,7 @@ getDatepickerFormat, getTemplate, isDisable, isEmpty, isNullOrUndefined, customW
13
13
  // import dayjs from "dayjs";
14
14
  // import {TreeSelect} from "antd";
15
15
  import classNames from "classnames";
16
- import { NumericFormat, numericFormatter } from "react-numeric-component";
16
+ import { NumericFormat } from "react-numeric-component";
17
17
  import { TableContext } from "./useContext";
18
18
  import dayjs from "dayjs";
19
19
  import moment from "moment";
@@ -872,7 +872,7 @@ const EditableCell = props => {
872
872
  // let floatValue = value
873
873
 
874
874
  const numericFormatProps = {
875
- // value,
875
+ value,
876
876
  thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
877
877
  decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
878
878
  decimalScale: cellFormat?.decimalScale ?? undefined,
@@ -882,8 +882,8 @@ const EditableCell = props => {
882
882
  suffix: cellFormat?.suffix ?? undefined
883
883
  };
884
884
  return /*#__PURE__*/React.createElement(NumericFormat, _extends({
885
- id: `col${indexCol}-record${indexRow}`,
886
- value: value ? numericFormatter(value.toString(), numericFormatProps) : ''
885
+ id: `col${indexCol}-record${indexRow}`
886
+ // value={value ? numericFormatter(value.toString(), numericFormatProps) : ''}
887
887
  // value={value}
888
888
  }, numericFormatProps, {
889
889
  min: column.min,
@@ -36,6 +36,7 @@ import { arrayMove, horizontalListSortingStrategy, SortableContext, useSortable
36
36
  // import {CSS} from "@dnd-kit/utilities";
37
37
  import { Resizable } from "react-resizable";
38
38
  import { faker } from "@faker-js/faker";
39
+ import InfiniteTable from "./table/InfiniteTable";
39
40
  dayjs.extend(customParseFormat);
40
41
  const MySwal = withReactContent(Swal);
41
42
  const ASCEND = 'ascend';
@@ -177,6 +178,7 @@ const InternalTable = props => {
177
178
  pagination,
178
179
  height: propsHeight,
179
180
  summary,
181
+ infiniteScroll,
180
182
  ...rest
181
183
  } = props;
182
184
  const id = React.useMemo(() => {
@@ -807,7 +809,7 @@ const InternalTable = props => {
807
809
  triggerChangeData(newData);
808
810
  }
809
811
  };
810
- const TableComponent = groupAble ? Group : editAble ? GridEdit : Grid;
812
+ const TableComponent = infiniteScroll ? InfiniteTable : groupAble ? Group : editAble ? GridEdit : Grid;
811
813
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(DndContext, {
812
814
  sensors: sensors,
813
815
  modifiers: [restrictToHorizontalAxis],
@@ -4,6 +4,6 @@ import type { TableLocale } from "rc-master-ui/lib/table/interface";
4
4
  import type { ColumnsTable } from "../../type";
5
5
  export declare function flatColumns<RecordType>(columns: ColumnsTable<RecordType>, parentKey?: string): ColumnsTable<RecordType>;
6
6
  export declare const flatColumns2: <RecordType>(columns: ColumnsTable<RecordType>) => ColumnsTable<RecordType>;
7
- export declare const getValueCell: <T>(column: ColumnTable<T>, value: any, format?: IFormat) => any;
7
+ export declare const getValueCell: <T>(column: ColumnTable<T>, value: any, record: T, format?: IFormat) => any;
8
8
  export declare const renderContent: <T>(column: ColumnTable<T>, value: any, record: any, index: number, format?: IFormat) => React.JSX.Element;
9
9
  export declare const renderFilter: <RecordType>(column: ColumnTable<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any, format?: IFormat, dateRangeLocale?: any) => React.JSX.Element;
@@ -1,4 +1,4 @@
1
- import { checkDecimalSeparator, checkThousandSeparator, convertDateToDayjs, convertDayjsToDate, convertFormat, getDatepickerFormat, getDateString, getTypeFilter, isColor, isEmpty } from "../utils";
1
+ import { checkDecimalSeparator, checkThousandSeparator, convertDateToDayjs, convertDayjsToDate, convertFormat, getDatepickerFormat, getDateRangeFormat, getDateString, getFormat, getTypeFilter, isColor, isEmpty } from "../utils";
2
2
  import { numericFormatter } from "react-numeric-component";
3
3
  import dayjs from "dayjs";
4
4
  import moment from "moment/moment";
@@ -55,27 +55,29 @@ export const flatColumns2 = columns => {
55
55
  }];
56
56
  }, []);
57
57
  };
58
- export const getValueCell = (column, value, format) => {
58
+ export const getValueCell = (column, value, record, format) => {
59
59
  switch (column?.type) {
60
60
  case 'number':
61
- const thousandSeparator = format?.thousandSeparator;
62
- const decimalSeparator = format?.decimalSeparator;
63
- const dec = format?.decimalScale;
61
+ const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
62
+ const cellFormat = getFormat(colFormat, format);
63
+ const thousandSeparator = cellFormat?.thousandSeparator;
64
+ const decimalSeparator = cellFormat?.decimalSeparator;
65
+ const dec = cellFormat?.decimalScale;
64
66
 
65
67
  // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? parseFloat(Number(value).toFixed(dec)).toString() : value.toString()) : '0'
66
68
 
67
69
  const tmpval = typeof value === 'string' ? Number(value) : value;
70
+ const contentNumber = !isEmpty(value) ? dec || dec === 0 ? parseFloat(tmpval.toFixed(dec)).toString() : tmpval.toString() : '0';
71
+ // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? tmpval.toString() : tmpval.toString()) : '0'
68
72
 
69
- // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? parseFloat(tmpval.toFixed(dec)).toString() : tmpval.toString()) : '0'
70
- const contentNumber = !isEmpty(value) ? dec || dec === 0 ? tmpval.toString() : tmpval.toString() : '0';
71
73
  const numericFormatProps = {
72
74
  thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
73
75
  decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
74
- allowNegative: format?.allowNegative ?? true,
75
- prefix: format?.prefix,
76
- suffix: format?.suffix,
76
+ allowNegative: cellFormat?.allowNegative ?? true,
77
+ prefix: cellFormat?.prefix,
78
+ suffix: cellFormat?.suffix,
77
79
  decimalScale: dec,
78
- fixedDecimalScale: format?.fixedDecimalScale ?? false
80
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
79
81
  };
80
82
  return !isEmpty(contentNumber) ? numericFormatter(contentNumber, numericFormatProps) : '';
81
83
  case 'date':
@@ -117,7 +119,7 @@ export const getValueCell = (column, value, format) => {
117
119
  };
118
120
  export const renderContent = (column, value, record, index, format) => {
119
121
  const cellValue = value instanceof Date ? getDateString(column, value) : value;
120
- const content = getValueCell(column, cellValue, format);
122
+ const content = getValueCell(column, cellValue, record, format);
121
123
  return /*#__PURE__*/React.createElement(Fragment, null, column?.template ? typeof column.template === "function" ? column.template({
122
124
  value,
123
125
  index,
@@ -129,7 +131,7 @@ export const renderFilter = (column, selectedKeys, setSelectedKeys, confirm, vis
129
131
  const cellFormat = column.format ? typeof column.format === 'function' ? column.format({}) : column.format : format;
130
132
  const type = getTypeFilter(column);
131
133
  const dateFormat = getDatepickerFormat(column?.typeFilter ?? column?.type, cellFormat) ?? 'DD/MM/YYYY';
132
- const dateRangeFormat = convertFormat(getDatepickerFormat(column?.type, cellFormat) ?? 'DD/MM/YYYY');
134
+ const dateRangeFormat = convertFormat(getDateRangeFormat(column?.type, cellFormat) ?? 'dd/MM/yyyy');
133
135
  const find = dataSourceFilter?.find(it => it.key === column?.field);
134
136
  const options = find ? find.data : [];
135
137
  switch (type) {
@@ -16,7 +16,7 @@ const HeaderContent = props => {
16
16
  return columnGroupText ?? headerText;
17
17
  }, [columnGroupText, headerText]);
18
18
  const tooltip = React.useMemo(() => {
19
- return headerTooltip ?? t ? t(columnGroupText ?? headerText) : columnGroupText ?? headerText;
19
+ return headerTooltip ?? t ? t?.(columnGroupText ?? headerText) : columnGroupText ?? headerText;
20
20
  }, [columnGroupText, headerText, headerTooltip, t]);
21
21
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
22
22
  className: classnames('', {}),
@@ -175,7 +175,7 @@ export const getFormat = (colFormat, format) => {
175
175
  return {
176
176
  thousandSeparator: colFormat?.thousandSeparator ?? format?.thousandSeparator,
177
177
  decimalSeparator: colFormat?.decimalSeparator ?? format?.decimalSeparator,
178
- decimalScale: colFormat?.decimalScale ?? format?.decimalScale,
178
+ decimalScale: colFormat?.decimalScale ?? format?.decimalScale ? Number(colFormat?.decimalScale ?? format?.decimalScale) : colFormat?.decimalScale ?? format?.decimalScale,
179
179
  allowNegative: colFormat?.allowNegative ?? format?.allowNegative,
180
180
  // check nhập số âm
181
181
  prefix: colFormat?.prefix ?? format?.prefix,
@@ -217,21 +217,21 @@ export const getDatepickerFormat = (type, format) => {
217
217
  switch (typeFormat) {
218
218
  case "date":
219
219
  case "daterange":
220
- return format?.dateFormat ?? 'dd/MM/YYYY';
220
+ return format?.dateFormat ?? 'DD/MM/YYYY';
221
221
  case "datetime":
222
- return format?.datetimeFormat ?? 'dd/MM/YYYY HH:mm';
222
+ return format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm';
223
223
  case "week":
224
- return format?.weekFormat ?? 'dd/MM';
224
+ return format?.weekFormat ?? 'DD/MM';
225
225
  case "month":
226
226
  return format?.monthFormat ?? 'MM/YYYY';
227
227
  case "quarter":
228
- return format?.dateFormat ?? 'dd/MM/YYYY';
228
+ return format?.dateFormat ?? 'DD/MM/YYYY';
229
229
  case "year":
230
230
  return format?.yearFormat ?? 'YYYY';
231
231
  case "time":
232
232
  return format?.timeFormat ?? 'HH:mm';
233
233
  default:
234
- return 'dd/MM/YYYY';
234
+ return 'DD/MM/YYYY';
235
235
  }
236
236
  };
237
237
  export const getDateRangeFormat = (type, format) => {
@@ -239,21 +239,21 @@ export const getDateRangeFormat = (type, format) => {
239
239
  switch (typeFormat) {
240
240
  case "date":
241
241
  case "daterange":
242
- return convertFormat(format?.dateFormat ?? 'DD/MM/YYYY');
242
+ return convertFormat(format?.dateFormat ?? 'dd/MM/yyyy');
243
243
  case "datetime":
244
- return format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm';
244
+ return format?.datetimeFormat ?? 'dd/MM/yyyy HH:mm';
245
245
  case "week":
246
- return format?.weekFormat ?? 'DD/MM';
246
+ return format?.weekFormat ?? 'dd/MM';
247
247
  case "month":
248
- return format?.monthFormat ?? 'MM/YYYY';
248
+ return format?.monthFormat ?? 'MM/yyyy';
249
249
  case "quarter":
250
- return format?.dateFormat ?? 'DD/MM/YYYY';
250
+ return format?.dateFormat ?? 'dd/MM/yyyy';
251
251
  case "year":
252
- return format?.yearFormat ?? 'YYYY';
252
+ return format?.yearFormat ?? 'yyyy';
253
253
  case "time":
254
254
  return format?.timeFormat ?? 'HH:mm';
255
255
  default:
256
- return 'DD/MM/YYYY';
256
+ return 'dd/MM/yyyy';
257
257
  }
258
258
  };
259
259
  export const customWeekStartEndFormat = (value, weekFormat) => {
@@ -412,7 +412,7 @@ const GridEdit = props => {
412
412
  }, [rangeCells]);
413
413
  const contextMenuItems = React.useMemo(() => {
414
414
  const a = showDefaultContext !== false ? [...defaultContext] : [];
415
- const b = propsContext ? [...propsContext, {
415
+ const b = propsContext && propsContext.length > 0 ? [...propsContext, {
416
416
  type: 'divider'
417
417
  }] : [];
418
418
  return [...b, ...a];
@@ -2270,7 +2270,7 @@ const GridEdit = props => {
2270
2270
  dataIndex: column.dataIndex,
2271
2271
  indexRow: rowNumber,
2272
2272
  indexCol: colIndex,
2273
- title: getValueCell(column, record[column.field], format),
2273
+ title: getValueCell(column, record[column.field], record, format),
2274
2274
  'data-col-index': colIndex,
2275
2275
  'data-row-index': rowNumber,
2276
2276
  // 'data-tooltip-id': "tooltip-cell-content",
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import type { ColumnsTable, GetRowKey } from "../type";
3
+ import type { TableProps } from "../type";
4
+ type Props<T> = TableProps<T> & {
5
+ scrollHeight?: number;
6
+ tableRef: any;
7
+ triggerFilter?: (queries: any) => void;
8
+ triggerChangeColumns?: (columns: ColumnsTable<T>, type: string) => void;
9
+ triggerChangeData?: (newData: T[], type: string) => void;
10
+ getRowKey: GetRowKey<T>;
11
+ triggerGroupColumns?: (groupedColumns: string[]) => void;
12
+ setTooltipContent?: any;
13
+ triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[]) => void;
14
+ isFilter?: boolean;
15
+ setIsFilter?: React.Dispatch<React.SetStateAction<boolean>>;
16
+ };
17
+ declare const InfiniteTable: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
18
+ export default InfiniteTable;
@@ -0,0 +1,96 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import React, { Fragment, useRef } from 'react';
3
+ import { GridStyle } from "../GridStyle";
4
+ import { ConfigProvider } from "rc-master-ui";
5
+ import TableGrid from "../TableGrid";
6
+
7
+ // type Props = {
8
+ // columns: any[]
9
+ // data: any[]
10
+ // currentPage: number
11
+ // pageSize: number
12
+ // total: number
13
+ // loading?: boolean
14
+ // next?: () => void
15
+ // }
16
+
17
+ const InfiniteTable = props => {
18
+ const {
19
+ next,
20
+ loading
21
+ } = props;
22
+ const {
23
+ id,
24
+ height,
25
+ scrollHeight,
26
+ rowHoverable,
27
+ pagination,
28
+ ...rest
29
+ } = props;
30
+ const {
31
+ currentPage,
32
+ pageSize,
33
+ total
34
+ } = pagination ?? {};
35
+ const loadingRef = useRef(false);
36
+ const hasMoreRef = useRef(true);
37
+ const loadData = page => {
38
+ if (!hasMoreRef.current || loadingRef.current || loading) return;
39
+ loadingRef.current = true;
40
+ setTimeout(() => {
41
+ next?.();
42
+ if (page * pageSize >= total) {
43
+ hasMoreRef.current = false;
44
+ }
45
+ loadingRef.current = false;
46
+ }, 10);
47
+ };
48
+ const handleNext = () => {
49
+ loadData(currentPage + 1);
50
+ };
51
+ const handleScroll = e => {
52
+ if (loadingRef.current || loading) {
53
+ e.stopPropagation();
54
+ e.preventDefault();
55
+ return;
56
+ }
57
+ const {
58
+ scrollHeight: tbScrollHeight,
59
+ scrollTop,
60
+ clientHeight
61
+ } = e.currentTarget;
62
+ const isEnd = scrollTop + clientHeight >= tbScrollHeight - 50;
63
+ if (isEnd && !loadingRef.current && hasMoreRef.current) {
64
+ handleNext();
65
+ }
66
+ };
67
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
68
+ $heightTable: height,
69
+ $heightScroll: scrollHeight,
70
+ style: {
71
+ position: 'relative'
72
+ },
73
+ id: id
74
+ }, /*#__PURE__*/React.createElement(ConfigProvider, {
75
+ theme: {
76
+ components: {
77
+ Table: {
78
+ rowHoverBg: '#eb461912',
79
+ rowSelectedBg: '#eb4619',
80
+ rowSelectedHoverBg: '#eb4619',
81
+ cellFontSize: 12,
82
+ cellFontSizeSM: 13,
83
+ headerBg: '#ffffff',
84
+ cellPaddingBlockSM: 7
85
+ }
86
+ }
87
+ }
88
+ }, /*#__PURE__*/React.createElement(TableGrid, _extends({}, rest, {
89
+ id: id,
90
+ pagination: false,
91
+ virtual: true,
92
+ onScroll: handleScroll,
93
+ loading: loading
94
+ })))));
95
+ };
96
+ export default InfiniteTable;
@@ -142,6 +142,8 @@ export type ColumnTemplate<RecordType> = {
142
142
  export type ColumnsTable<RecordType = AnyObject> = ColumnTable<RecordType>[];
143
143
  export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<RecordType>, 'columns' | 'rowSelection' | 'loading' | 'dataSource' | 'summary' | 'pagination'> {
144
144
  editAble?: boolean;
145
+ infiniteScroll?: boolean;
146
+ next?: () => void;
145
147
  groupAble?: boolean;
146
148
  groupColumns?: string[];
147
149
  groupSetting?: IGroupSetting;
@@ -874,7 +874,7 @@ const EditableCell = props => {
874
874
  // let floatValue = value
875
875
 
876
876
  const numericFormatProps = {
877
- // value,
877
+ value,
878
878
  thousandSeparator: (0, _hooks.checkThousandSeparator)(thousandSeparator, decimalSeparator),
879
879
  decimalSeparator: (0, _hooks.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
880
880
  decimalScale: cellFormat?.decimalScale ?? undefined,
@@ -884,8 +884,8 @@ const EditableCell = props => {
884
884
  suffix: cellFormat?.suffix ?? undefined
885
885
  };
886
886
  return /*#__PURE__*/_react.default.createElement(_reactNumericComponent.NumericFormat, (0, _extends2.default)({
887
- id: `col${indexCol}-record${indexRow}`,
888
- value: value ? (0, _reactNumericComponent.numericFormatter)(value.toString(), numericFormatProps) : ''
887
+ id: `col${indexCol}-record${indexRow}`
888
+ // value={value ? numericFormatter(value.toString(), numericFormatProps) : ''}
889
889
  // value={value}
890
890
  }, numericFormatProps, {
891
891
  min: column.min,
@@ -36,6 +36,7 @@ var _core = require("@dnd-kit/core");
36
36
  var _sortable = require("@dnd-kit/sortable");
37
37
  var _reactResizable = require("react-resizable");
38
38
  var _faker = require("@faker-js/faker");
39
+ var _InfiniteTable = _interopRequireDefault(require("./table/InfiniteTable"));
39
40
  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); }
40
41
  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; }
41
42
  // import {Resizable} from "react-resizable";
@@ -188,6 +189,7 @@ const InternalTable = props => {
188
189
  pagination,
189
190
  height: propsHeight,
190
191
  summary,
192
+ infiniteScroll,
191
193
  ...rest
192
194
  } = props;
193
195
  const id = _react.default.useMemo(() => {
@@ -818,7 +820,7 @@ const InternalTable = props => {
818
820
  triggerChangeData(newData);
819
821
  }
820
822
  };
821
- const TableComponent = groupAble ? _Group.default : editAble ? _GridEdit.default : _Grid.default;
823
+ const TableComponent = infiniteScroll ? _InfiniteTable.default : groupAble ? _Group.default : editAble ? _GridEdit.default : _Grid.default;
822
824
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.DndContext, {
823
825
  sensors: sensors,
824
826
  modifiers: [_modifiers.restrictToHorizontalAxis],
@@ -4,6 +4,6 @@ import type { TableLocale } from "rc-master-ui/lib/table/interface";
4
4
  import type { ColumnsTable } from "../../type";
5
5
  export declare function flatColumns<RecordType>(columns: ColumnsTable<RecordType>, parentKey?: string): ColumnsTable<RecordType>;
6
6
  export declare const flatColumns2: <RecordType>(columns: ColumnsTable<RecordType>) => ColumnsTable<RecordType>;
7
- export declare const getValueCell: <T>(column: ColumnTable<T>, value: any, format?: IFormat) => any;
7
+ export declare const getValueCell: <T>(column: ColumnTable<T>, value: any, record: T, format?: IFormat) => any;
8
8
  export declare const renderContent: <T>(column: ColumnTable<T>, value: any, record: any, index: number, format?: IFormat) => React.JSX.Element;
9
9
  export declare const renderFilter: <RecordType>(column: ColumnTable<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any, format?: IFormat, dateRangeLocale?: any) => React.JSX.Element;
@@ -66,27 +66,29 @@ const flatColumns2 = columns => {
66
66
  }, []);
67
67
  };
68
68
  exports.flatColumns2 = flatColumns2;
69
- const getValueCell = (column, value, format) => {
69
+ const getValueCell = (column, value, record, format) => {
70
70
  switch (column?.type) {
71
71
  case 'number':
72
- const thousandSeparator = format?.thousandSeparator;
73
- const decimalSeparator = format?.decimalSeparator;
74
- const dec = format?.decimalScale;
72
+ const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
73
+ const cellFormat = (0, _utils.getFormat)(colFormat, format);
74
+ const thousandSeparator = cellFormat?.thousandSeparator;
75
+ const decimalSeparator = cellFormat?.decimalSeparator;
76
+ const dec = cellFormat?.decimalScale;
75
77
 
76
78
  // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? parseFloat(Number(value).toFixed(dec)).toString() : value.toString()) : '0'
77
79
 
78
80
  const tmpval = typeof value === 'string' ? Number(value) : value;
81
+ const contentNumber = !(0, _utils.isEmpty)(value) ? dec || dec === 0 ? parseFloat(tmpval.toFixed(dec)).toString() : tmpval.toString() : '0';
82
+ // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? tmpval.toString() : tmpval.toString()) : '0'
79
83
 
80
- // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? parseFloat(tmpval.toFixed(dec)).toString() : tmpval.toString()) : '0'
81
- const contentNumber = !(0, _utils.isEmpty)(value) ? dec || dec === 0 ? tmpval.toString() : tmpval.toString() : '0';
82
84
  const numericFormatProps = {
83
85
  thousandSeparator: (0, _utils.checkThousandSeparator)(thousandSeparator, decimalSeparator),
84
86
  decimalSeparator: (0, _utils.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
85
- allowNegative: format?.allowNegative ?? true,
86
- prefix: format?.prefix,
87
- suffix: format?.suffix,
87
+ allowNegative: cellFormat?.allowNegative ?? true,
88
+ prefix: cellFormat?.prefix,
89
+ suffix: cellFormat?.suffix,
88
90
  decimalScale: dec,
89
- fixedDecimalScale: format?.fixedDecimalScale ?? false
91
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
90
92
  };
91
93
  return !(0, _utils.isEmpty)(contentNumber) ? (0, _reactNumericComponent.numericFormatter)(contentNumber, numericFormatProps) : '';
92
94
  case 'date':
@@ -129,7 +131,7 @@ const getValueCell = (column, value, format) => {
129
131
  exports.getValueCell = getValueCell;
130
132
  const renderContent = (column, value, record, index, format) => {
131
133
  const cellValue = value instanceof Date ? (0, _utils.getDateString)(column, value) : value;
132
- const content = getValueCell(column, cellValue, format);
134
+ const content = getValueCell(column, cellValue, record, format);
133
135
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, column?.template ? typeof column.template === "function" ? column.template({
134
136
  value,
135
137
  index,
@@ -142,7 +144,7 @@ const renderFilter = (column, selectedKeys, setSelectedKeys, confirm, visible, s
142
144
  const cellFormat = column.format ? typeof column.format === 'function' ? column.format({}) : column.format : format;
143
145
  const type = (0, _utils.getTypeFilter)(column);
144
146
  const dateFormat = (0, _utils.getDatepickerFormat)(column?.typeFilter ?? column?.type, cellFormat) ?? 'DD/MM/YYYY';
145
- const dateRangeFormat = (0, _utils.convertFormat)((0, _utils.getDatepickerFormat)(column?.type, cellFormat) ?? 'DD/MM/YYYY');
147
+ const dateRangeFormat = (0, _utils.convertFormat)((0, _utils.getDateRangeFormat)(column?.type, cellFormat) ?? 'dd/MM/yyyy');
146
148
  const find = dataSourceFilter?.find(it => it.key === column?.field);
147
149
  const options = find ? find.data : [];
148
150
  switch (type) {
@@ -25,7 +25,7 @@ const HeaderContent = props => {
25
25
  return columnGroupText ?? headerText;
26
26
  }, [columnGroupText, headerText]);
27
27
  const tooltip = _react.default.useMemo(() => {
28
- return headerTooltip ?? t ? t(columnGroupText ?? headerText) : columnGroupText ?? headerText;
28
+ return headerTooltip ?? t ? t?.(columnGroupText ?? headerText) : columnGroupText ?? headerText;
29
29
  }, [columnGroupText, headerText, headerTooltip, t]);
30
30
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
31
31
  className: (0, _classnames.default)('', {}),
@@ -226,7 +226,7 @@ const getFormat = (colFormat, format) => {
226
226
  return {
227
227
  thousandSeparator: colFormat?.thousandSeparator ?? format?.thousandSeparator,
228
228
  decimalSeparator: colFormat?.decimalSeparator ?? format?.decimalSeparator,
229
- decimalScale: colFormat?.decimalScale ?? format?.decimalScale,
229
+ decimalScale: colFormat?.decimalScale ?? format?.decimalScale ? Number(colFormat?.decimalScale ?? format?.decimalScale) : colFormat?.decimalScale ?? format?.decimalScale,
230
230
  allowNegative: colFormat?.allowNegative ?? format?.allowNegative,
231
231
  // check nhập số âm
232
232
  prefix: colFormat?.prefix ?? format?.prefix,
@@ -269,21 +269,21 @@ const getDatepickerFormat = (type, format) => {
269
269
  switch (typeFormat) {
270
270
  case "date":
271
271
  case "daterange":
272
- return format?.dateFormat ?? 'dd/MM/YYYY';
272
+ return format?.dateFormat ?? 'DD/MM/YYYY';
273
273
  case "datetime":
274
- return format?.datetimeFormat ?? 'dd/MM/YYYY HH:mm';
274
+ return format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm';
275
275
  case "week":
276
- return format?.weekFormat ?? 'dd/MM';
276
+ return format?.weekFormat ?? 'DD/MM';
277
277
  case "month":
278
278
  return format?.monthFormat ?? 'MM/YYYY';
279
279
  case "quarter":
280
- return format?.dateFormat ?? 'dd/MM/YYYY';
280
+ return format?.dateFormat ?? 'DD/MM/YYYY';
281
281
  case "year":
282
282
  return format?.yearFormat ?? 'YYYY';
283
283
  case "time":
284
284
  return format?.timeFormat ?? 'HH:mm';
285
285
  default:
286
- return 'dd/MM/YYYY';
286
+ return 'DD/MM/YYYY';
287
287
  }
288
288
  };
289
289
  exports.getDatepickerFormat = getDatepickerFormat;
@@ -292,21 +292,21 @@ const getDateRangeFormat = (type, format) => {
292
292
  switch (typeFormat) {
293
293
  case "date":
294
294
  case "daterange":
295
- return convertFormat(format?.dateFormat ?? 'DD/MM/YYYY');
295
+ return convertFormat(format?.dateFormat ?? 'dd/MM/yyyy');
296
296
  case "datetime":
297
- return format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm';
297
+ return format?.datetimeFormat ?? 'dd/MM/yyyy HH:mm';
298
298
  case "week":
299
- return format?.weekFormat ?? 'DD/MM';
299
+ return format?.weekFormat ?? 'dd/MM';
300
300
  case "month":
301
- return format?.monthFormat ?? 'MM/YYYY';
301
+ return format?.monthFormat ?? 'MM/yyyy';
302
302
  case "quarter":
303
- return format?.dateFormat ?? 'DD/MM/YYYY';
303
+ return format?.dateFormat ?? 'dd/MM/yyyy';
304
304
  case "year":
305
- return format?.yearFormat ?? 'YYYY';
305
+ return format?.yearFormat ?? 'yyyy';
306
306
  case "time":
307
307
  return format?.timeFormat ?? 'HH:mm';
308
308
  default:
309
- return 'DD/MM/YYYY';
309
+ return 'dd/MM/yyyy';
310
310
  }
311
311
  };
312
312
  exports.getDateRangeFormat = getDateRangeFormat;
@@ -416,7 +416,7 @@ const GridEdit = props => {
416
416
  }, [rangeCells]);
417
417
  const contextMenuItems = _react.default.useMemo(() => {
418
418
  const a = showDefaultContext !== false ? [...defaultContext] : [];
419
- const b = propsContext ? [...propsContext, {
419
+ const b = propsContext && propsContext.length > 0 ? [...propsContext, {
420
420
  type: 'divider'
421
421
  }] : [];
422
422
  return [...b, ...a];
@@ -2274,7 +2274,7 @@ const GridEdit = props => {
2274
2274
  dataIndex: column.dataIndex,
2275
2275
  indexRow: rowNumber,
2276
2276
  indexCol: colIndex,
2277
- title: (0, _columns.getValueCell)(column, record[column.field], format),
2277
+ title: (0, _columns.getValueCell)(column, record[column.field], record, format),
2278
2278
  'data-col-index': colIndex,
2279
2279
  'data-row-index': rowNumber,
2280
2280
  // 'data-tooltip-id': "tooltip-cell-content",
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import type { ColumnsTable, GetRowKey } from "../type";
3
+ import type { TableProps } from "../type";
4
+ type Props<T> = TableProps<T> & {
5
+ scrollHeight?: number;
6
+ tableRef: any;
7
+ triggerFilter?: (queries: any) => void;
8
+ triggerChangeColumns?: (columns: ColumnsTable<T>, type: string) => void;
9
+ triggerChangeData?: (newData: T[], type: string) => void;
10
+ getRowKey: GetRowKey<T>;
11
+ triggerGroupColumns?: (groupedColumns: string[]) => void;
12
+ setTooltipContent?: any;
13
+ triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[]) => void;
14
+ isFilter?: boolean;
15
+ setIsFilter?: React.Dispatch<React.SetStateAction<boolean>>;
16
+ };
17
+ declare const InfiniteTable: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
18
+ export default InfiniteTable;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _GridStyle = require("../GridStyle");
11
+ var _rcMasterUi = require("rc-master-ui");
12
+ var _TableGrid = _interopRequireDefault(require("../TableGrid"));
13
+ 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); }
14
+ 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; }
15
+ // type Props = {
16
+ // columns: any[]
17
+ // data: any[]
18
+ // currentPage: number
19
+ // pageSize: number
20
+ // total: number
21
+ // loading?: boolean
22
+ // next?: () => void
23
+ // }
24
+
25
+ const InfiniteTable = props => {
26
+ const {
27
+ next,
28
+ loading
29
+ } = props;
30
+ const {
31
+ id,
32
+ height,
33
+ scrollHeight,
34
+ rowHoverable,
35
+ pagination,
36
+ ...rest
37
+ } = props;
38
+ const {
39
+ currentPage,
40
+ pageSize,
41
+ total
42
+ } = pagination ?? {};
43
+ const loadingRef = (0, _react.useRef)(false);
44
+ const hasMoreRef = (0, _react.useRef)(true);
45
+ const loadData = page => {
46
+ if (!hasMoreRef.current || loadingRef.current || loading) return;
47
+ loadingRef.current = true;
48
+ setTimeout(() => {
49
+ next?.();
50
+ if (page * pageSize >= total) {
51
+ hasMoreRef.current = false;
52
+ }
53
+ loadingRef.current = false;
54
+ }, 10);
55
+ };
56
+ const handleNext = () => {
57
+ loadData(currentPage + 1);
58
+ };
59
+ const handleScroll = e => {
60
+ if (loadingRef.current || loading) {
61
+ e.stopPropagation();
62
+ e.preventDefault();
63
+ return;
64
+ }
65
+ const {
66
+ scrollHeight: tbScrollHeight,
67
+ scrollTop,
68
+ clientHeight
69
+ } = e.currentTarget;
70
+ const isEnd = scrollTop + clientHeight >= tbScrollHeight - 50;
71
+ if (isEnd && !loadingRef.current && hasMoreRef.current) {
72
+ handleNext();
73
+ }
74
+ };
75
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_GridStyle.GridStyle, {
76
+ $heightTable: height,
77
+ $heightScroll: scrollHeight,
78
+ style: {
79
+ position: 'relative'
80
+ },
81
+ id: id
82
+ }, /*#__PURE__*/_react.default.createElement(_rcMasterUi.ConfigProvider, {
83
+ theme: {
84
+ components: {
85
+ Table: {
86
+ rowHoverBg: '#eb461912',
87
+ rowSelectedBg: '#eb4619',
88
+ rowSelectedHoverBg: '#eb4619',
89
+ cellFontSize: 12,
90
+ cellFontSizeSM: 13,
91
+ headerBg: '#ffffff',
92
+ cellPaddingBlockSM: 7
93
+ }
94
+ }
95
+ }
96
+ }, /*#__PURE__*/_react.default.createElement(_TableGrid.default, (0, _extends2.default)({}, rest, {
97
+ id: id,
98
+ pagination: false,
99
+ virtual: true,
100
+ onScroll: handleScroll,
101
+ loading: loading
102
+ })))));
103
+ };
104
+ var _default = exports.default = InfiniteTable;
@@ -142,6 +142,8 @@ export type ColumnTemplate<RecordType> = {
142
142
  export type ColumnsTable<RecordType = AnyObject> = ColumnTable<RecordType>[];
143
143
  export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<RecordType>, 'columns' | 'rowSelection' | 'loading' | 'dataSource' | 'summary' | 'pagination'> {
144
144
  editAble?: boolean;
145
+ infiniteScroll?: boolean;
146
+ next?: () => void;
145
147
  groupAble?: boolean;
146
148
  groupColumns?: string[];
147
149
  groupSetting?: IGroupSetting;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.5.8",
3
+ "version": "1.5.9",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",