es-grid-template 1.3.9 → 1.4.1
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.
- package/es/grid-component/EditableCell.js +9 -8
- package/es/grid-component/InternalTable.js +26 -4
- package/es/grid-component/TableGrid.js +44 -41
- package/es/grid-component/hooks/useColumns.d.ts +1 -0
- package/es/grid-component/hooks/useColumns.js +12 -4
- package/es/grid-component/hooks/useLazyKVMap.d.ts +4 -0
- package/es/grid-component/hooks/useLazyKVMap.js +35 -0
- package/es/grid-component/hooks/utils.d.ts +16 -1
- package/es/grid-component/hooks/utils.js +25 -4
- package/es/grid-component/styles.scss +13 -13
- package/es/grid-component/table/GridEdit.js +42 -22
- package/lib/grid-component/EditableCell.js +9 -8
- package/lib/grid-component/InternalTable.js +28 -4
- package/lib/grid-component/TableGrid.js +43 -40
- package/lib/grid-component/hooks/useColumns.d.ts +1 -0
- package/lib/grid-component/hooks/useColumns.js +11 -3
- package/lib/grid-component/hooks/useLazyKVMap.d.ts +4 -0
- package/lib/grid-component/hooks/useLazyKVMap.js +43 -0
- package/lib/grid-component/hooks/utils.d.ts +16 -1
- package/lib/grid-component/hooks/utils.js +27 -5
- package/lib/grid-component/styles.scss +13 -13
- package/lib/grid-component/table/GridEdit.js +41 -21
- package/package.json +2 -2
|
@@ -33,7 +33,10 @@ const filterTreeNode = (input, treeNode) => {
|
|
|
33
33
|
title,
|
|
34
34
|
value
|
|
35
35
|
} = treeNode;
|
|
36
|
-
|
|
36
|
+
if (typeof title === "string" || typeof title === 'number') {
|
|
37
|
+
return title.toString().toLowerCase().includes(input.toLowerCase()) || value.toLowerCase().includes(input.toLowerCase());
|
|
38
|
+
}
|
|
39
|
+
return value.toLowerCase().includes(input.toLowerCase());
|
|
37
40
|
};
|
|
38
41
|
const EditableCell = props => {
|
|
39
42
|
const {
|
|
@@ -558,19 +561,17 @@ const EditableCell = props => {
|
|
|
558
561
|
// autoFocus={true}
|
|
559
562
|
,
|
|
560
563
|
virtual: true,
|
|
561
|
-
allowClear: true
|
|
564
|
+
allowClear: true,
|
|
565
|
+
showSearch: true
|
|
562
566
|
// maxTagTextLength={column?.editSelectSettings?.showItems}
|
|
563
567
|
,
|
|
564
568
|
maxTagCount: column?.editSelectSettings?.showItems,
|
|
565
569
|
maxTagPlaceholder: 2,
|
|
566
570
|
treeTitleRender: column?.editSelectSettings?.formatOptionLabel,
|
|
567
571
|
showCheckedStrategy: SHOW_PARENT,
|
|
568
|
-
multiple: column?.editSelectSettings?.selectMode === 'checkbox' || column?.editSelectSettings?.isMulti
|
|
569
|
-
fieldNames:
|
|
570
|
-
|
|
571
|
-
value: keySelect,
|
|
572
|
-
children: 'children'
|
|
573
|
-
},
|
|
572
|
+
multiple: column?.editSelectSettings?.selectMode === 'checkbox' || column?.editSelectSettings?.isMulti
|
|
573
|
+
// fieldNames={{label: inputKey ? inputKey : 'title', value: keySelect, children: 'children'}}
|
|
574
|
+
,
|
|
574
575
|
treeCheckable: column?.editSelectSettings?.selectMode === 'checkbox',
|
|
575
576
|
filterTreeNode: filterTreeNode,
|
|
576
577
|
popupMatchSelectWidth: menuWidth ? menuWidth + 10 : undefined,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { Fragment } from 'react';
|
|
3
3
|
import { Resizable } from "react-resizable";
|
|
4
4
|
import 'react-resizable/css/styles.css';
|
|
5
5
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
@@ -26,6 +26,7 @@ import { flatColumns2 } from "./hooks/columns";
|
|
|
26
26
|
import Group from "./table/Group";
|
|
27
27
|
import Swal from "sweetalert2";
|
|
28
28
|
import withReactContent from "sweetalert2-react-content";
|
|
29
|
+
import { Tooltip } from "react-tooltip";
|
|
29
30
|
dayjs.extend(customParseFormat);
|
|
30
31
|
const MySwal = withReactContent(Swal);
|
|
31
32
|
|
|
@@ -91,8 +92,8 @@ const InternalTable = props => {
|
|
|
91
92
|
...rest
|
|
92
93
|
} = props;
|
|
93
94
|
const rowKey = React.useMemo(() => {
|
|
94
|
-
return
|
|
95
|
-
}, [
|
|
95
|
+
return propRowKey ?? 'rowId';
|
|
96
|
+
}, [propRowKey]);
|
|
96
97
|
const local = lang && lang === 'en' ? en : vi;
|
|
97
98
|
const buddhistLocale = {
|
|
98
99
|
...local,
|
|
@@ -103,6 +104,7 @@ const InternalTable = props => {
|
|
|
103
104
|
|
|
104
105
|
// const [filterStates, setFilterState] = React.useState<any>(null)
|
|
105
106
|
// const [isFilter, setIsFilter] = React.useState<boolean>(false);
|
|
107
|
+
// const [cellTooltip, seCellTooltip] = React.useState<any>(undefined);
|
|
106
108
|
|
|
107
109
|
const mergerdData = React.useMemo(() => {
|
|
108
110
|
// return filterDataByColumns2(addRowIdArray(dataSource), filterStates)
|
|
@@ -149,6 +151,11 @@ const InternalTable = props => {
|
|
|
149
151
|
// @ts-ignore
|
|
150
152
|
return record => record?.[rowKey];
|
|
151
153
|
}, [rowKey]);
|
|
154
|
+
|
|
155
|
+
// const onMouseHover = (record: any, col: ColumnTable) => {
|
|
156
|
+
//
|
|
157
|
+
// }
|
|
158
|
+
|
|
152
159
|
const [transformSelectionColumns] = useColumns({
|
|
153
160
|
locale,
|
|
154
161
|
t,
|
|
@@ -163,6 +170,7 @@ const InternalTable = props => {
|
|
|
163
170
|
groupSetting,
|
|
164
171
|
groupColumns,
|
|
165
172
|
handleResize
|
|
173
|
+
// onMouseHover
|
|
166
174
|
});
|
|
167
175
|
const mergedColumns = React.useMemo(() => {
|
|
168
176
|
return transformSelectionColumns(columns);
|
|
@@ -391,7 +399,7 @@ const InternalTable = props => {
|
|
|
391
399
|
}
|
|
392
400
|
};
|
|
393
401
|
const TableComponent = groupAble ? Group : editAble ? GridEdit : Grid;
|
|
394
|
-
return /*#__PURE__*/React.createElement(TableComponent, _extends({}, rest, {
|
|
402
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(TableComponent, _extends({}, rest, {
|
|
395
403
|
t: t,
|
|
396
404
|
locale: locale,
|
|
397
405
|
tableRef: tableRef,
|
|
@@ -426,6 +434,20 @@ const InternalTable = props => {
|
|
|
426
434
|
// isFilter={isFilter}
|
|
427
435
|
// setIsFilter={setIsFilter}
|
|
428
436
|
// onScroll={onScroll}
|
|
437
|
+
})), /*#__PURE__*/React.createElement(Tooltip, {
|
|
438
|
+
id: "tooltip-cell-content",
|
|
439
|
+
style: {
|
|
440
|
+
zIndex: 1999
|
|
441
|
+
}
|
|
442
|
+
// content={'sssss'}
|
|
443
|
+
// content={cellTooltip}
|
|
444
|
+
// render={() => {
|
|
445
|
+
// return (
|
|
446
|
+
// <span>
|
|
447
|
+
// aaaa
|
|
448
|
+
// </span>
|
|
449
|
+
// )
|
|
450
|
+
// }}
|
|
429
451
|
}));
|
|
430
452
|
};
|
|
431
453
|
export default InternalTable;
|
|
@@ -12,7 +12,7 @@ import classNames from "classnames";
|
|
|
12
12
|
import { checkDecimalSeparator, checkThousandSeparator,
|
|
13
13
|
// filterDataByColumns2,
|
|
14
14
|
// filterDataByColumns3,
|
|
15
|
-
filterDataByColumns4,
|
|
15
|
+
filterDataByColumns4, getFormat,
|
|
16
16
|
// convertFlatColumn,
|
|
17
17
|
isEmpty,
|
|
18
18
|
// newGuid,
|
|
@@ -413,46 +413,6 @@ const TableGrid = props => {
|
|
|
413
413
|
// }}
|
|
414
414
|
,
|
|
415
415
|
|
|
416
|
-
summary: () => {
|
|
417
|
-
if (typeof summary === 'function') {
|
|
418
|
-
return summary(dataSource);
|
|
419
|
-
}
|
|
420
|
-
if (!summary) {
|
|
421
|
-
return undefined;
|
|
422
|
-
}
|
|
423
|
-
return /*#__PURE__*/React.createElement(Table.Summary, {
|
|
424
|
-
fixed: true
|
|
425
|
-
}, /*#__PURE__*/React.createElement(Table.Summary.Row, null, flatColumns(!!mode ? [Table.SELECTION_COLUMN, ...columns] : [...columns]).filter(col => col.hidden !== true).map((col, index) => {
|
|
426
|
-
const cellFormat = col.format ? typeof col.format === 'function' ? col.format({}) : col.format : format;
|
|
427
|
-
const thousandSeparator = cellFormat?.thousandSeparator;
|
|
428
|
-
const decimalSeparator = cellFormat?.decimalSeparator;
|
|
429
|
-
|
|
430
|
-
// const dec = (col.format?.decimalScale || col.format?.decimalScale === 0) ? col.format?.decimalScale : format?.decimalScale
|
|
431
|
-
const dec = cellFormat?.decimalScale;
|
|
432
|
-
const sumValue = col.type === 'number' ? sumDataByField(dataSource, col?.key) : 0;
|
|
433
|
-
const value = !isEmpty(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
|
|
434
|
-
const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
|
|
435
|
-
const numericFormatProps = {
|
|
436
|
-
thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
|
|
437
|
-
decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
|
|
438
|
-
allowNegative: cellFormat?.allowNegative ?? false,
|
|
439
|
-
prefix: cellFormat?.prefix,
|
|
440
|
-
suffix: cellFormat?.suffix,
|
|
441
|
-
decimalScale: dec,
|
|
442
|
-
fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
|
|
443
|
-
};
|
|
444
|
-
return /*#__PURE__*/React.createElement(Table.Summary.Cell, {
|
|
445
|
-
key: col.key,
|
|
446
|
-
index: index,
|
|
447
|
-
align: col.align ?? 'right',
|
|
448
|
-
className: 'ui-rc-table-cell-ellipsis'
|
|
449
|
-
}, col.summaryTemplate ? col.summaryTemplate(cellValue, col.key) : numericFormatter(cellValue, numericFormatProps));
|
|
450
|
-
})));
|
|
451
|
-
},
|
|
452
|
-
pagination: !pagination || pagination && pagination?.onChange ? false : {
|
|
453
|
-
showTotal: (total, range) => `${range[0]}-${range[1]} / ${total} items`,
|
|
454
|
-
...pagination
|
|
455
|
-
},
|
|
456
416
|
onFilter: val => {
|
|
457
417
|
handleOnFilter(val);
|
|
458
418
|
// triggerFilter?.(convertFilters(val))
|
|
@@ -507,6 +467,49 @@ const TableGrid = props => {
|
|
|
507
467
|
},
|
|
508
468
|
expandable: {
|
|
509
469
|
...expandable
|
|
470
|
+
},
|
|
471
|
+
summary: () => {
|
|
472
|
+
if (typeof summary === 'function') {
|
|
473
|
+
return summary(dataSource);
|
|
474
|
+
}
|
|
475
|
+
if (!summary) {
|
|
476
|
+
return undefined;
|
|
477
|
+
}
|
|
478
|
+
return /*#__PURE__*/React.createElement(Table.Summary, {
|
|
479
|
+
fixed: true
|
|
480
|
+
}, /*#__PURE__*/React.createElement(Table.Summary.Row, null, flatColumns(!!mode ? [Table.SELECTION_COLUMN, ...columns] : [...columns]).filter(col => col.hidden !== true).map((col, index) => {
|
|
481
|
+
// const cellFormat: IFormat | undefined = col.format ? typeof col.format === 'function' ? col.format({}) : col.format : format
|
|
482
|
+
|
|
483
|
+
const colFormat = typeof col.format === 'function' ? col.format({}) : col.format;
|
|
484
|
+
const cellFormat = getFormat(colFormat, format);
|
|
485
|
+
const thousandSeparator = cellFormat?.thousandSeparator;
|
|
486
|
+
const decimalSeparator = cellFormat?.decimalSeparator;
|
|
487
|
+
|
|
488
|
+
// const dec = (col.format?.decimalScale || col.format?.decimalScale === 0) ? col.format?.decimalScale : format?.decimalScale
|
|
489
|
+
const dec = cellFormat?.decimalScale;
|
|
490
|
+
const sumValue = col.type === 'number' ? sumDataByField(dataSource, col?.key) : 0;
|
|
491
|
+
const value = !isEmpty(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
|
|
492
|
+
const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
|
|
493
|
+
const numericFormatProps = {
|
|
494
|
+
thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
|
|
495
|
+
decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
|
|
496
|
+
allowNegative: cellFormat?.allowNegative ?? false,
|
|
497
|
+
prefix: cellFormat?.prefix,
|
|
498
|
+
suffix: cellFormat?.suffix,
|
|
499
|
+
decimalScale: dec,
|
|
500
|
+
fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
|
|
501
|
+
};
|
|
502
|
+
return /*#__PURE__*/React.createElement(Table.Summary.Cell, {
|
|
503
|
+
key: col.key,
|
|
504
|
+
index: index,
|
|
505
|
+
align: col.align ?? 'right',
|
|
506
|
+
className: 'ui-rc-table-cell-ellipsis'
|
|
507
|
+
}, col.summaryTemplate ? col.summaryTemplate(cellValue, col.key) : numericFormatter(cellValue, numericFormatProps));
|
|
508
|
+
})));
|
|
509
|
+
},
|
|
510
|
+
pagination: !pagination || pagination && pagination?.onChange ? false : {
|
|
511
|
+
showTotal: (total, range) => `${range[0]}-${range[1]} / ${total} items`,
|
|
512
|
+
...pagination
|
|
510
513
|
}
|
|
511
514
|
})), /*#__PURE__*/React.createElement("div", null), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/React.createElement(Pagination
|
|
512
515
|
// style={{padding: '0.75rem 1rem'}}
|
|
@@ -13,6 +13,7 @@ interface UseColumnsConfig<RecordType> {
|
|
|
13
13
|
groupSetting?: IGroupSetting;
|
|
14
14
|
groupColumns?: string[];
|
|
15
15
|
rowKey?: any;
|
|
16
|
+
onMouseHover?: any;
|
|
16
17
|
}
|
|
17
18
|
declare const useColumns: <RecordType extends AnyObject = AnyObject>(config: UseColumnsConfig<RecordType>) => readonly [any];
|
|
18
19
|
export default useColumns;
|
|
@@ -4,7 +4,7 @@ import { Fragment, useCallback } from 'react';
|
|
|
4
4
|
// import Command from "../Command";
|
|
5
5
|
import { Button, Space } from "antd";
|
|
6
6
|
import { Select } from "rc-master-ui";
|
|
7
|
-
import { findItemPath, getTypeFilter } from "./utils";
|
|
7
|
+
import { findItemPath, getFormat, getTypeFilter } from "./utils";
|
|
8
8
|
import { booleanOperator, numberOperator, stringOperator, translateOption } from "./constant";
|
|
9
9
|
import { flatColumns2, renderContent, renderFilter } from "./columns";
|
|
10
10
|
import { SearchOutlined } from "@ant-design/icons";
|
|
@@ -37,6 +37,7 @@ const useColumns = config => {
|
|
|
37
37
|
sortMultiple,
|
|
38
38
|
format,
|
|
39
39
|
handleResize,
|
|
40
|
+
// onMouseHover,
|
|
40
41
|
groupAble,
|
|
41
42
|
groupColumns,
|
|
42
43
|
groupSetting,
|
|
@@ -273,11 +274,16 @@ const useColumns = config => {
|
|
|
273
274
|
className: classNames(transformedColumn?.onCell?.(data, index).className ?? '', {
|
|
274
275
|
'cell-group': groupColumns && data.children,
|
|
275
276
|
'cell-group-fixed': groupColumns && data.children && col.field === firstNonGroupColumn?.field
|
|
276
|
-
})
|
|
277
|
+
}),
|
|
278
|
+
'data-tooltip-id': "tooltip-cell-content"
|
|
279
|
+
// onMouseEnter: () => {
|
|
280
|
+
// onMouseHover(data, col as any)
|
|
281
|
+
// },
|
|
277
282
|
};
|
|
278
283
|
},
|
|
279
284
|
render: (value, record, rowIndex) => {
|
|
280
|
-
const
|
|
285
|
+
const colFormat = typeof col.format === 'function' ? col.format(record) : col.format;
|
|
286
|
+
const cellFormat = getFormat(colFormat, format);
|
|
281
287
|
if (groupSetting && groupSetting.hiddenColumnGroup === false) {
|
|
282
288
|
if (record.children) {
|
|
283
289
|
return renderContent(col, value, record, rowIndex, cellFormat);
|
|
@@ -301,7 +307,9 @@ const useColumns = config => {
|
|
|
301
307
|
});
|
|
302
308
|
};
|
|
303
309
|
return convertColumns(cloneColumns);
|
|
304
|
-
}, [
|
|
310
|
+
}, [groupColumns, getColumnSearchProps, sortMultiple, groupSetting, groupAble, t, dataSource, rowKey, handleResize, format]
|
|
311
|
+
// format, getColumnSearchProps, sortMultiple, groupSetting, groupAble, t, groupColumns, , handleResize, , t, cellHover
|
|
312
|
+
);
|
|
305
313
|
return [transformColumns];
|
|
306
314
|
};
|
|
307
315
|
export default useColumns;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AnyObject, GetRowKey } from "../type";
|
|
2
|
+
import type { Key } from "react";
|
|
3
|
+
declare const useLazyKVMap: <RecordType extends AnyObject = AnyObject>(data: readonly RecordType[], childrenColumnName: string, getRowKey: GetRowKey<RecordType>) => readonly [(key: Key) => RecordType];
|
|
4
|
+
export default useLazyKVMap;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
// import type { AnyObject } from '../../_util/type';
|
|
5
|
+
// import type { GetRowKey, Key } from '../interface';
|
|
6
|
+
|
|
7
|
+
const useLazyKVMap = (data, childrenColumnName, getRowKey) => {
|
|
8
|
+
const mapCacheRef = React.useRef({});
|
|
9
|
+
function getRecordByKey(key) {
|
|
10
|
+
if (!mapCacheRef.current || mapCacheRef.current.data !== data || mapCacheRef.current.childrenColumnName !== childrenColumnName || mapCacheRef.current.getRowKey !== getRowKey) {
|
|
11
|
+
const kvMap = new Map();
|
|
12
|
+
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
function dig(records) {
|
|
15
|
+
records.forEach((record, index) => {
|
|
16
|
+
const rowKey = getRowKey(record, index);
|
|
17
|
+
kvMap.set(rowKey, record);
|
|
18
|
+
if (record && typeof record === 'object' && childrenColumnName in record) {
|
|
19
|
+
dig(record[childrenColumnName] || []);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
dig(data);
|
|
24
|
+
mapCacheRef.current = {
|
|
25
|
+
data,
|
|
26
|
+
childrenColumnName,
|
|
27
|
+
kvMap,
|
|
28
|
+
getRowKey
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return mapCacheRef.current.kvMap?.get(key);
|
|
32
|
+
}
|
|
33
|
+
return [getRecordByKey];
|
|
34
|
+
};
|
|
35
|
+
export default useLazyKVMap;
|
|
@@ -21,6 +21,21 @@ export declare const getVisibleColumnKeys: (columns: any[]) => string[];
|
|
|
21
21
|
export declare function getHiddenParentKeys(columns: any[], parentKeys?: string[]): string[];
|
|
22
22
|
export declare const updateColumns: (columns: any[], includes: string[]) => any[];
|
|
23
23
|
export declare const updateColumnsByGroup: (columns: any[], columnsGroup: string[]) => any[];
|
|
24
|
+
export declare const getFormat: (colFormat?: IFormat, format?: IFormat) => {
|
|
25
|
+
thousandSeparator: string;
|
|
26
|
+
decimalSeparator: string;
|
|
27
|
+
decimalScale: number;
|
|
28
|
+
allowNegative: boolean;
|
|
29
|
+
prefix: string;
|
|
30
|
+
suffix: string;
|
|
31
|
+
fixedDecimalScale: boolean;
|
|
32
|
+
dateFormat: string;
|
|
33
|
+
datetimeFormat: string;
|
|
34
|
+
timeFormat: string;
|
|
35
|
+
weekFormat: string;
|
|
36
|
+
monthFormat: string;
|
|
37
|
+
yearFormat: string;
|
|
38
|
+
};
|
|
24
39
|
export declare const getDatepickerFormat: (type: EditType | TypeFilter | IColumnType, format?: IFormat) => string;
|
|
25
40
|
export declare const customWeekStartEndFormat: (value: any, weekFormat: string) => string;
|
|
26
41
|
export declare const getTypeFilter: (col: ColumnTable<any>) => TypeFilter;
|
|
@@ -109,7 +124,7 @@ export declare function getCellsByPosition(cellSet: any, position?: string): any
|
|
|
109
124
|
export declare const addBorderClass: (selectedCells: any, type: string, className: string, id?: string) => void;
|
|
110
125
|
export declare const removeBorderClass: (selectedCells: any, type: string, className: string, id?: string) => void;
|
|
111
126
|
export declare const removeBorderClass2: (className: string, id?: string) => void;
|
|
112
|
-
export declare const onAddBgSelectedCell: (selectedCells: any, id?: string) => void;
|
|
127
|
+
export declare const onAddBgSelectedCell: (selectedCells: any, id?: string, isFocusCellIndex?: boolean) => void;
|
|
113
128
|
export declare const onAddBorderSelectedCell: (selectedCells: any, id?: string) => void;
|
|
114
129
|
export declare const onRemoveBgSelectedCell: (selectedCells: any, id?: string, rowsSelected?: any) => void;
|
|
115
130
|
export declare const onRemoveBorderSelectedCell: (selectedCells: any, id?: string) => void;
|
|
@@ -171,6 +171,25 @@ export const updateColumnsByGroup = (columns, columnsGroup) => {
|
|
|
171
171
|
return newColumn;
|
|
172
172
|
});
|
|
173
173
|
};
|
|
174
|
+
export const getFormat = (colFormat, format) => {
|
|
175
|
+
return {
|
|
176
|
+
thousandSeparator: colFormat?.thousandSeparator ?? format?.thousandSeparator,
|
|
177
|
+
decimalSeparator: colFormat?.decimalSeparator ?? format?.decimalSeparator,
|
|
178
|
+
decimalScale: colFormat?.decimalScale ?? format?.decimalScale,
|
|
179
|
+
allowNegative: colFormat?.allowNegative ?? format?.allowNegative,
|
|
180
|
+
// check nhập số âm
|
|
181
|
+
prefix: colFormat?.prefix ?? format?.prefix,
|
|
182
|
+
suffix: colFormat?.suffix ?? format?.suffix,
|
|
183
|
+
fixedDecimalScale: colFormat?.fixedDecimalScale ?? format?.fixedDecimalScale,
|
|
184
|
+
// mặc định thêm số 0 sau số thập phân
|
|
185
|
+
dateFormat: colFormat?.dateFormat ?? format?.dateFormat,
|
|
186
|
+
datetimeFormat: colFormat?.datetimeFormat ?? format?.datetimeFormat,
|
|
187
|
+
timeFormat: colFormat?.timeFormat ?? format?.timeFormat,
|
|
188
|
+
weekFormat: colFormat?.weekFormat ?? format?.weekFormat,
|
|
189
|
+
monthFormat: colFormat?.monthFormat ?? format?.monthFormat,
|
|
190
|
+
yearFormat: colFormat?.yearFormat ?? format?.yearFormat
|
|
191
|
+
};
|
|
192
|
+
};
|
|
174
193
|
export const getDatepickerFormat = (type, format) => {
|
|
175
194
|
const typeFormat = type ? type.toLowerCase() : '';
|
|
176
195
|
switch (typeFormat) {
|
|
@@ -274,13 +293,15 @@ export const convertLabelToTitle = data => {
|
|
|
274
293
|
label,
|
|
275
294
|
title,
|
|
276
295
|
value,
|
|
296
|
+
key,
|
|
277
297
|
...rest
|
|
278
298
|
} = item;
|
|
279
299
|
const newItem = {
|
|
280
300
|
...rest,
|
|
281
301
|
value,
|
|
282
|
-
|
|
283
|
-
|
|
302
|
+
label,
|
|
303
|
+
key: key ?? value,
|
|
304
|
+
title: title ?? label
|
|
284
305
|
};
|
|
285
306
|
if (item.children) {
|
|
286
307
|
newItem.children = convertLabelToTitle(item.children);
|
|
@@ -1542,7 +1563,7 @@ export const removeBorderClass2 = (className, id) => {
|
|
|
1542
1563
|
});
|
|
1543
1564
|
}
|
|
1544
1565
|
};
|
|
1545
|
-
export const onAddBgSelectedCell = (selectedCells, id) => {
|
|
1566
|
+
export const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
|
|
1546
1567
|
const selectors = Array.from(selectedCells).map(pos => {
|
|
1547
1568
|
const [row1, col1] = pos.split('-');
|
|
1548
1569
|
return `[data-row-index="${row1}"][data-col-index="${col1}"]`;
|
|
@@ -1557,7 +1578,7 @@ export const onAddBgSelectedCell = (selectedCells, id) => {
|
|
|
1557
1578
|
const rowsArray = [...new Set([...selectedCells].map(item => item.split("-")[0]))];
|
|
1558
1579
|
const rowsSelectors = rowsArray.map(r => `.rc-ui-cell-index[data-row-index="${r}"]`).join(", ");
|
|
1559
1580
|
const cellsIndex = table && rowsSelectors.length > 0 ? table?.querySelectorAll(rowsSelectors) : null;
|
|
1560
|
-
if (cellsIndex) {
|
|
1581
|
+
if (cellsIndex && isFocusCellIndex !== false) {
|
|
1561
1582
|
cellsIndex.forEach(cell => {
|
|
1562
1583
|
cell.classList.add('focus');
|
|
1563
1584
|
});
|
|
@@ -426,7 +426,7 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
426
426
|
&.rc-ui-cell-index {
|
|
427
427
|
&.focus {
|
|
428
428
|
background-color: $cell-index-focus-bg;
|
|
429
|
-
font-weight: 500;
|
|
429
|
+
//font-weight: 500;
|
|
430
430
|
}
|
|
431
431
|
&.selected {
|
|
432
432
|
background-color: $cell-index-selected-bg !important;
|
|
@@ -681,18 +681,18 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
681
681
|
// background-color: #f0f0f0;
|
|
682
682
|
//}
|
|
683
683
|
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
}
|
|
684
|
+
//.ui-rc_cell-content--index {
|
|
685
|
+
// &.focus {
|
|
686
|
+
// background-color: $cell-index-focus-bg;
|
|
687
|
+
// //color: #fff;
|
|
688
|
+
// //font-weight: 500;
|
|
689
|
+
// }
|
|
690
|
+
// &.selected {
|
|
691
|
+
// background-color: $cell-index-selected-bg;
|
|
692
|
+
// color: #fff;
|
|
693
|
+
// //font-weight: 500;
|
|
694
|
+
// }
|
|
695
|
+
//}
|
|
696
696
|
|
|
697
697
|
.#{$prefix}-table-tbody {
|
|
698
698
|
|
|
@@ -13,7 +13,7 @@ import dayjs from "dayjs";
|
|
|
13
13
|
import 'dayjs/locale/es';
|
|
14
14
|
import 'dayjs/locale/vi';
|
|
15
15
|
import TableGrid from "../TableGrid";
|
|
16
|
-
import { addClassBorderPasteCell, addClassCellIndexSelected, addRows8, addRowsUp, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, findItemPath, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, hideDraggingPoint, isEditable, isEqualSet, isObjEmpty, newGuid, onAddBorderSelectedCell, onAddBgSelectedCell, onRemoveBorderSelectedCell, onRemoveBgSelectedCell, removeClassBorderPasteCell, removeClassCellIndexSelected, showDraggingPoint, sortedSetASC, totalFixedWidth, updateArrayByKey } from "../hooks";
|
|
16
|
+
import { addClassBorderPasteCell, addClassCellIndexSelected, addRows8, addRowsUp, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, findItemPath, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, hideDraggingPoint, isEditable, isEqualSet, isObjEmpty, newGuid, onAddBorderSelectedCell, onAddBgSelectedCell, onRemoveBorderSelectedCell, onRemoveBgSelectedCell, removeClassBorderPasteCell, removeClassCellIndexSelected, showDraggingPoint, sortedSetASC, totalFixedWidth, updateArrayByKey, getFormat } from "../hooks";
|
|
17
17
|
import Message from "../../Message/Message";
|
|
18
18
|
import { Toolbar, ConfigProvider, InputNumber } from "rc-master-ui";
|
|
19
19
|
import classnames from "classnames";
|
|
@@ -149,6 +149,9 @@ const GridEdit = props => {
|
|
|
149
149
|
// quét vùng được paste - tiếp tục hiển thị con trỏ crosshair
|
|
150
150
|
// const isPasteDragging = useRef(false);
|
|
151
151
|
|
|
152
|
+
const visibleCols = React.useMemo(() => {
|
|
153
|
+
return flatColumns2(columns.filter(it => it.visible !== false));
|
|
154
|
+
}, [columns]);
|
|
152
155
|
const id = React.useMemo(() => {
|
|
153
156
|
return tableId ?? faker.string.alpha(20);
|
|
154
157
|
// return tableId ?? newGuid()
|
|
@@ -507,7 +510,7 @@ const GridEdit = props => {
|
|
|
507
510
|
const newData = [...dataSource];
|
|
508
511
|
|
|
509
512
|
// colIndex => field
|
|
510
|
-
const colIndexToField = flatColumns2(
|
|
513
|
+
const colIndexToField = flatColumns2(visibleCols).map(col => col.field);
|
|
511
514
|
|
|
512
515
|
// Duyệt qua mỗi ô cần xóa
|
|
513
516
|
for (const cell of selectedCells.current) {
|
|
@@ -859,7 +862,9 @@ const GridEdit = props => {
|
|
|
859
862
|
};
|
|
860
863
|
const triggerDragPaste = pastesArray => {
|
|
861
864
|
const mergedSet = new Set([...selectedCells.current, ...pastesArray]);
|
|
862
|
-
const tmpCols =
|
|
865
|
+
const tmpCols = {
|
|
866
|
+
...visibleCols
|
|
867
|
+
};
|
|
863
868
|
const rowSelectedFirst = getFirstSelectCell(selectedCells.current).row;
|
|
864
869
|
const rowPasteLast = getLastSelectCell(pasteCells.current).row;
|
|
865
870
|
const selectedArray = Array.from(selectedCells.current).map(key => {
|
|
@@ -1250,7 +1255,7 @@ const GridEdit = props => {
|
|
|
1250
1255
|
col
|
|
1251
1256
|
};
|
|
1252
1257
|
const newSelectedCells = new Set();
|
|
1253
|
-
const tCols = editAbleColumns(
|
|
1258
|
+
const tCols = editAbleColumns(visibleCols);
|
|
1254
1259
|
for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
|
|
1255
1260
|
for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
|
|
1256
1261
|
newSelectedCells.add(`${r}-${c}`);
|
|
@@ -1270,7 +1275,7 @@ const GridEdit = props => {
|
|
|
1270
1275
|
hideDraggingPoint(selectedCells.current, id);
|
|
1271
1276
|
selectedCells.current = newSelectedCells;
|
|
1272
1277
|
rowsSelected.current = new Set([`${row}-${col}`]);
|
|
1273
|
-
onAddBgSelectedCell(newSelectedCells, id);
|
|
1278
|
+
onAddBgSelectedCell(newSelectedCells, id, false);
|
|
1274
1279
|
onAddBorderSelectedCell(newSelectedCells, id);
|
|
1275
1280
|
addClassCellIndexSelected(new Set([`${row}-${col}`]), id);
|
|
1276
1281
|
};
|
|
@@ -1412,13 +1417,13 @@ const GridEdit = props => {
|
|
|
1412
1417
|
}
|
|
1413
1418
|
rowValues.forEach((cellValue, colIndex) => {
|
|
1414
1419
|
const targetCol = startCol + colIndex;
|
|
1415
|
-
if (targetCol >=
|
|
1420
|
+
if (targetCol >= visibleCols.length) {
|
|
1416
1421
|
// Không vượt quá số cột
|
|
1417
1422
|
return;
|
|
1418
1423
|
}
|
|
1419
|
-
if (
|
|
1424
|
+
if (visibleCols[targetCol].editEnable) {
|
|
1420
1425
|
// @ts-ignore
|
|
1421
|
-
const columnKey =
|
|
1426
|
+
const columnKey = visibleCols[targetCol].field;
|
|
1422
1427
|
|
|
1423
1428
|
// @ts-ignore
|
|
1424
1429
|
newData[targetRow] = {
|
|
@@ -1461,13 +1466,13 @@ const GridEdit = props => {
|
|
|
1461
1466
|
}
|
|
1462
1467
|
rowValues.forEach((cellValue, colIndex) => {
|
|
1463
1468
|
const targetCol = startCol + colIndex;
|
|
1464
|
-
if (targetCol >=
|
|
1469
|
+
if (targetCol >= visibleCols.length) {
|
|
1465
1470
|
// Không vượt quá số cột
|
|
1466
1471
|
return;
|
|
1467
1472
|
}
|
|
1468
|
-
if (
|
|
1473
|
+
if (visibleCols[targetCol].editEnable) {
|
|
1469
1474
|
// @ts-ignore
|
|
1470
|
-
const columnKey =
|
|
1475
|
+
const columnKey = visibleCols[targetCol].field;
|
|
1471
1476
|
|
|
1472
1477
|
// @ts-ignore
|
|
1473
1478
|
childData[targetRow] = {
|
|
@@ -1783,7 +1788,7 @@ const GridEdit = props => {
|
|
|
1783
1788
|
// }, []);
|
|
1784
1789
|
|
|
1785
1790
|
const scrollToCell = (rowIndex, colIndex, cell, scrollType) => {
|
|
1786
|
-
const fixedWidth = totalFixedWidth(
|
|
1791
|
+
const fixedWidth = totalFixedWidth(visibleCols, 'left', selectionSettings);
|
|
1787
1792
|
if (scrollType === 'horizontal') {
|
|
1788
1793
|
if (tableRef.current) {
|
|
1789
1794
|
tableRef.current.scrollTo({
|
|
@@ -1904,7 +1909,7 @@ const GridEdit = props => {
|
|
|
1904
1909
|
setEditingKey('');
|
|
1905
1910
|
}
|
|
1906
1911
|
},
|
|
1907
|
-
tabIndex: (rowIndex ?? 0) *
|
|
1912
|
+
tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex
|
|
1908
1913
|
};
|
|
1909
1914
|
},
|
|
1910
1915
|
render: (value, record) => {
|
|
@@ -1930,6 +1935,7 @@ const GridEdit = props => {
|
|
|
1930
1935
|
onCell: (record, rowIndex) => {
|
|
1931
1936
|
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
1932
1937
|
return {
|
|
1938
|
+
...column?.onCell?.(record, rowIndex),
|
|
1933
1939
|
onKeyDown: event => {
|
|
1934
1940
|
const key = getRowKey(record, dataSource.indexOf(record));
|
|
1935
1941
|
if (event.key === 'Control' && event.ctrlKey) {} else {
|
|
@@ -1970,14 +1976,18 @@ const GridEdit = props => {
|
|
|
1970
1976
|
}
|
|
1971
1977
|
}
|
|
1972
1978
|
if (event.key === 'Tab') {
|
|
1973
|
-
if (
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1979
|
+
if (editingKey) {} else {
|
|
1980
|
+
if (colIndex + 1 !== visibleCols.length) {
|
|
1981
|
+
// console.log('bbbbb')
|
|
1982
|
+
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1983
|
+
} else {
|
|
1984
|
+
// console.log('fffff')
|
|
1985
|
+
event.stopPropagation();
|
|
1986
|
+
event.preventDefault();
|
|
1987
|
+
}
|
|
1978
1988
|
}
|
|
1979
1989
|
}
|
|
1980
|
-
if (event.key === 'ArrowRight' && colIndex + 1 !==
|
|
1990
|
+
if (event.key === 'ArrowRight' && colIndex + 1 !== visibleCols.length) {
|
|
1981
1991
|
if (editingKey !== '') {} else {
|
|
1982
1992
|
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1983
1993
|
}
|
|
@@ -2050,9 +2060,17 @@ const GridEdit = props => {
|
|
|
2050
2060
|
rowsSelected.current = new Set();
|
|
2051
2061
|
}
|
|
2052
2062
|
},
|
|
2063
|
+
// onMouseEnter: () => {
|
|
2064
|
+
//
|
|
2065
|
+
// },
|
|
2066
|
+
|
|
2053
2067
|
onClick: () => {
|
|
2054
2068
|
if (record[rowKey] !== editingKey && editingKey !== '') {
|
|
2055
2069
|
setEditingKey('');
|
|
2070
|
+
} else {
|
|
2071
|
+
if (editingKey) {
|
|
2072
|
+
handleCellClick(rowNumber, record, column);
|
|
2073
|
+
}
|
|
2056
2074
|
}
|
|
2057
2075
|
},
|
|
2058
2076
|
className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : `rc-ui-cell-editable cell-editable ${!isEditable(column, record) ? 'disable' : ''}`,
|
|
@@ -2065,14 +2083,14 @@ const GridEdit = props => {
|
|
|
2065
2083
|
title: getValueCell(column, record[column.field], format),
|
|
2066
2084
|
'data-col-index': colIndex,
|
|
2067
2085
|
'data-row-index': rowNumber,
|
|
2068
|
-
|
|
2086
|
+
'data-tooltip-id': "tooltip-cell-content",
|
|
2069
2087
|
// 'data-tooltip-content': 'tooltip-cell-content',
|
|
2070
2088
|
// 'data-tooltip-delay-show': 1000,
|
|
2071
2089
|
// 'data-tooltip-content': getValueCell(column, record[column.field as any], format),
|
|
2072
2090
|
editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record),
|
|
2073
2091
|
cellEditing,
|
|
2074
2092
|
t,
|
|
2075
|
-
tabIndex: (rowIndex ?? 0) *
|
|
2093
|
+
tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex,
|
|
2076
2094
|
style: isPasteDragging ? {
|
|
2077
2095
|
cursor: "crosshair"
|
|
2078
2096
|
} : {}
|
|
@@ -2103,6 +2121,8 @@ const GridEdit = props => {
|
|
|
2103
2121
|
},
|
|
2104
2122
|
render: (value, record, rowIndex) => {
|
|
2105
2123
|
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
2124
|
+
const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
|
|
2125
|
+
const cellFormat = getFormat(colFormat, format);
|
|
2106
2126
|
return /*#__PURE__*/React.createElement("div", {
|
|
2107
2127
|
className: classNames('ui-rc_cell-content', {
|
|
2108
2128
|
// disable: !isEditable(column as any, record)
|
|
@@ -2124,7 +2144,7 @@ const GridEdit = props => {
|
|
|
2124
2144
|
// }}
|
|
2125
2145
|
}, /*#__PURE__*/React.createElement("div", {
|
|
2126
2146
|
className: 'ui-rc_content'
|
|
2127
|
-
}, renderContent(column, value, record, rowIndex,
|
|
2147
|
+
}, renderContent(column, value, record, rowIndex, cellFormat)),
|
|
2128
2148
|
// selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
|
|
2129
2149
|
// getLastSelectCell(selectedCells.current).col === colIndex &&
|
|
2130
2150
|
// isEditable(column as any, record) &&
|