es-grid-template 1.8.64 → 1.8.65

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.
Files changed (125) hide show
  1. package/es/grid-component/ColumnsGroup/ColumnsGroup.js +4 -1
  2. package/es/grid-component/TempTable.js +2 -2
  3. package/es/grid-component/hooks/utils.d.ts +2 -8
  4. package/es/grid-component/hooks/utils.js +175 -144
  5. package/es/grid-component/index.d.ts +1 -1
  6. package/es/grid-component/index.js +0 -4
  7. package/es/grid-component/type.d.ts +7 -0
  8. package/es/table-component/type.d.ts +8 -0
  9. package/es/table-virtuoso/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  10. package/es/table-virtuoso/ColumnsGroup/ColumnsGroup.js +232 -0
  11. package/es/table-virtuoso/ColumnsGroup/index.d.ts +1 -0
  12. package/es/table-virtuoso/ColumnsGroup/index.js +1 -0
  13. package/es/{grid-component → table-virtuoso}/InternalTable.d.ts +2 -3
  14. package/es/table-virtuoso/InternalTable.js +413 -0
  15. package/es/table-virtuoso/body/TableBody.d.ts +14 -0
  16. package/es/table-virtuoso/body/TableBody.js +84 -0
  17. package/es/table-virtuoso/body/TableBodyCell.d.ts +14 -0
  18. package/es/table-virtuoso/body/TableBodyCell.js +466 -0
  19. package/es/table-virtuoso/body/TableBodyRow.d.ts +13 -0
  20. package/es/table-virtuoso/body/TableBodyRow.js +116 -0
  21. package/es/table-virtuoso/footer/TableFooterCell.d.ts +7 -0
  22. package/es/table-virtuoso/footer/TableFooterCell.js +54 -0
  23. package/es/table-virtuoso/header/TableHeadCell.d.ts +14 -0
  24. package/es/table-virtuoso/header/TableHeadCell.js +265 -0
  25. package/es/table-virtuoso/header/renderFilter.d.ts +20 -0
  26. package/es/table-virtuoso/header/renderFilter.js +289 -0
  27. package/es/table-virtuoso/hook/constant.d.ts +73 -0
  28. package/es/table-virtuoso/hook/constant.js +240 -0
  29. package/es/table-virtuoso/hook/convert.d.ts +1 -0
  30. package/es/table-virtuoso/hook/convert.js +28 -0
  31. package/es/table-virtuoso/hook/useColumns.d.ts +28 -0
  32. package/es/table-virtuoso/hook/useColumns.js +302 -0
  33. package/es/table-virtuoso/hook/useFilterOperator.d.ts +7 -0
  34. package/es/table-virtuoso/hook/useFilterOperator.js +33 -0
  35. package/es/table-virtuoso/hook/utils.d.ts +159 -0
  36. package/es/table-virtuoso/hook/utils.js +2263 -0
  37. package/es/table-virtuoso/index.d.ts +2 -0
  38. package/es/table-virtuoso/index.js +2 -0
  39. package/es/table-virtuoso/style.d.ts +22 -0
  40. package/es/table-virtuoso/style.js +11 -0
  41. package/es/table-virtuoso/style.scss +1440 -0
  42. package/es/table-virtuoso/table/Grid.d.ts +37 -0
  43. package/es/table-virtuoso/table/Grid.js +302 -0
  44. package/es/table-virtuoso/table/TableContainer.d.ts +49 -0
  45. package/es/table-virtuoso/table/TableContainer.js +305 -0
  46. package/es/table-virtuoso/table/TableWrapper.d.ts +20 -0
  47. package/es/table-virtuoso/table/TableWrapper.js +158 -0
  48. package/es/table-virtuoso/type.d.ts +0 -0
  49. package/es/table-virtuoso/type.js +785 -0
  50. package/es/table-virtuoso/useContext.d.ts +97 -0
  51. package/es/table-virtuoso/useContext.js +21 -0
  52. package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +4 -1
  53. package/lib/grid-component/TempTable.js +2 -2
  54. package/lib/grid-component/hooks/utils.d.ts +2 -8
  55. package/lib/grid-component/hooks/utils.js +176 -152
  56. package/lib/grid-component/index.d.ts +1 -1
  57. package/lib/grid-component/index.js +0 -3
  58. package/lib/grid-component/type.d.ts +7 -0
  59. package/lib/table-component/type.d.ts +8 -0
  60. package/lib/table-virtuoso/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  61. package/lib/table-virtuoso/ColumnsGroup/ColumnsGroup.js +243 -0
  62. package/lib/table-virtuoso/ColumnsGroup/index.d.ts +1 -0
  63. package/lib/table-virtuoso/ColumnsGroup/index.js +16 -0
  64. package/lib/{grid-component → table-virtuoso}/InternalTable.d.ts +2 -3
  65. package/lib/table-virtuoso/InternalTable.js +422 -0
  66. package/lib/table-virtuoso/body/TableBody.d.ts +14 -0
  67. package/lib/table-virtuoso/body/TableBody.js +95 -0
  68. package/lib/table-virtuoso/body/TableBodyCell.d.ts +14 -0
  69. package/lib/table-virtuoso/body/TableBodyCell.js +473 -0
  70. package/lib/table-virtuoso/body/TableBodyRow.d.ts +13 -0
  71. package/lib/table-virtuoso/body/TableBodyRow.js +124 -0
  72. package/lib/table-virtuoso/footer/TableFooterCell.d.ts +7 -0
  73. package/lib/table-virtuoso/footer/TableFooterCell.js +63 -0
  74. package/lib/table-virtuoso/header/TableHeadCell.d.ts +14 -0
  75. package/lib/table-virtuoso/header/TableHeadCell.js +274 -0
  76. package/lib/table-virtuoso/header/renderFilter.d.ts +20 -0
  77. package/lib/table-virtuoso/header/renderFilter.js +299 -0
  78. package/lib/table-virtuoso/hook/constant.d.ts +73 -0
  79. package/lib/table-virtuoso/hook/constant.js +247 -0
  80. package/lib/table-virtuoso/hook/convert.d.ts +1 -0
  81. package/lib/table-virtuoso/hook/convert.js +34 -0
  82. package/lib/table-virtuoso/hook/useColumns.d.ts +28 -0
  83. package/lib/table-virtuoso/hook/useColumns.js +315 -0
  84. package/lib/table-virtuoso/hook/useFilterOperator.d.ts +7 -0
  85. package/lib/table-virtuoso/hook/useFilterOperator.js +40 -0
  86. package/lib/table-virtuoso/hook/utils.d.ts +159 -0
  87. package/lib/table-virtuoso/hook/utils.js +2389 -0
  88. package/lib/table-virtuoso/index.d.ts +2 -0
  89. package/lib/table-virtuoso/index.js +9 -0
  90. package/lib/table-virtuoso/style.d.ts +22 -0
  91. package/lib/table-virtuoso/style.js +18 -0
  92. package/lib/table-virtuoso/style.scss +1440 -0
  93. package/lib/table-virtuoso/table/Grid.d.ts +37 -0
  94. package/lib/table-virtuoso/table/Grid.js +311 -0
  95. package/lib/table-virtuoso/table/TableContainer.d.ts +49 -0
  96. package/lib/table-virtuoso/table/TableContainer.js +313 -0
  97. package/lib/table-virtuoso/table/TableWrapper.d.ts +20 -0
  98. package/lib/table-virtuoso/table/TableWrapper.js +164 -0
  99. package/lib/table-virtuoso/type.d.ts +0 -0
  100. package/lib/table-virtuoso/type.js +786 -0
  101. package/lib/table-virtuoso/useContext.d.ts +97 -0
  102. package/lib/table-virtuoso/useContext.js +27 -0
  103. package/package.json +2 -1
  104. package/es/grid-component/ConvertColumnTable.d.ts +0 -7
  105. package/es/grid-component/ConvertColumnTable.js +0 -144
  106. package/es/grid-component/InternalTable.js +0 -1170
  107. package/es/grid-component/table/Grid.d.ts +0 -23
  108. package/es/grid-component/table/Grid.js +0 -49
  109. package/es/grid-component/table/GridEdit.d.ts +0 -23
  110. package/es/grid-component/table/GridEdit.js +0 -2726
  111. package/es/grid-component/table/Group.d.ts +0 -21
  112. package/es/grid-component/table/Group.js +0 -195
  113. package/es/grid-component/table/InfiniteTable.d.ts +0 -23
  114. package/es/grid-component/table/InfiniteTable.js +0 -101
  115. package/lib/grid-component/ConvertColumnTable.d.ts +0 -7
  116. package/lib/grid-component/ConvertColumnTable.js +0 -153
  117. package/lib/grid-component/InternalTable.js +0 -1178
  118. package/lib/grid-component/table/Grid.d.ts +0 -23
  119. package/lib/grid-component/table/Grid.js +0 -58
  120. package/lib/grid-component/table/GridEdit.d.ts +0 -23
  121. package/lib/grid-component/table/GridEdit.js +0 -2723
  122. package/lib/grid-component/table/Group.d.ts +0 -21
  123. package/lib/grid-component/table/Group.js +0 -204
  124. package/lib/grid-component/table/InfiniteTable.d.ts +0 -23
  125. package/lib/grid-component/table/InfiniteTable.js +0 -109
@@ -0,0 +1,232 @@
1
+ import { Group } from "becoxy-icons";
2
+ import React, { useRef, useState } from "react";
3
+ // import {
4
+ // // groupArrayByColumns,
5
+ // // ungroupArray,
6
+ // // useOnClickOutside
7
+ // } from "../../hooks"
8
+
9
+ import { Button, Popover, Tooltip } from "antd";
10
+ // import {SettingOutlined} from "@ant-design/icons";
11
+ import { Select } from "rc-master-ui";
12
+ import styled from "styled-components";
13
+ import { customFilterOption } from "../../grid-component/hooks";
14
+ const BoxAction = styled.div.withConfig({
15
+ displayName: "BoxAction",
16
+ componentId: "es-grid-template__sc-z2q149-0"
17
+ })(["padding-top:.75rem;display:flex;justify-content:end;gap:10px;.btn-action{background:none !important;border:none !important;&.btn-action-submit{color:#df4318;&:disabled{background-color:#f0f0f0 !important;}&:hover{color:#df4318 !important;}}&:hover{background-color:#f0f0f0 !important;}}"]);
18
+ export const ColumnsGroup = props => {
19
+ const {
20
+ columns,
21
+ columnsGrouped,
22
+ onSubmit,
23
+ unClearableLevel,
24
+ defaultGroupColumns,
25
+ t
26
+ } = props;
27
+ const menuRef = useRef();
28
+ const [tempGroup, setTempGroup] = useState([]);
29
+ const [clicked, setClicked] = useState(false);
30
+ console.log('columns', columns);
31
+ console.log('columnsGrouped', columnsGrouped);
32
+ const rsCol = React.useMemo(() => {
33
+ return columns.filter(it => it.visible !== false && !tempGroup.includes(it.field) && it.field !== '#' && it.field !== 'selection_column' && it.field !== 'command');
34
+ }, [columns, tempGroup]);
35
+ console.log('rsCol', rsCol);
36
+ const options = React.useMemo(() => {
37
+ return rsCol.map(it => ({
38
+ ...it,
39
+ value: it.field,
40
+ label: t ? t(it?.columnGroupText ?? it?.headerText) : it?.columnGroupText ?? it?.headerText
41
+ }));
42
+ }, [rsCol, t]);
43
+
44
+ // React.useEffect(() => {
45
+ // if(columnsGrouped) {
46
+ // setTempGroup([...columnsGrouped])
47
+ // }
48
+ //
49
+ // }, [!!columnsGrouped])
50
+
51
+ const onChangeGroupColumns = (option, index) => {
52
+ // if (option) {
53
+ // tempGroup[index] = option
54
+ // } else {
55
+ // tempGroup.splice(index, 1)
56
+ // }
57
+ // setTempGroup([...tempGroup])
58
+
59
+ const cloneTemp = [...tempGroup];
60
+ if (option) {
61
+ cloneTemp[index] = option;
62
+ } else {
63
+ cloneTemp.splice(index, 1);
64
+ }
65
+ setTempGroup([...cloneTemp]);
66
+ };
67
+ const handleGroup = () => {
68
+ // setColumnsGrouped([...tempGroup])
69
+ setClicked(false);
70
+ // const dt = ungroupArray(dataSource)
71
+
72
+ // const rs = groupArrayByColumns(dt, [...tempGroup])
73
+
74
+ // setResource([...rs])
75
+ onSubmit([...tempGroup]);
76
+ };
77
+ const handleClear = () => {
78
+ // setColumnsGrouped([])
79
+ setTempGroup(defaultGroupColumns ? defaultGroupColumns : []);
80
+ // setIsOpen(false)
81
+ setClicked(false);
82
+ // const dt = ungroupArray(dataSource)
83
+
84
+ // const rs = groupArrayByColumns(dt, [])
85
+
86
+ // setResource([...rs])
87
+ onSubmit(defaultGroupColumns ? defaultGroupColumns : []);
88
+ };
89
+ const handleClickChange = open => {
90
+ setClicked(open);
91
+ if (open) {
92
+ if (columnsGrouped) {
93
+ setTempGroup([...columnsGrouped]);
94
+ }
95
+ }
96
+ if (!open) {
97
+ setTempGroup([]);
98
+ }
99
+ };
100
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Popover, {
101
+ placement: 'bottomLeft',
102
+ content: /*#__PURE__*/React.createElement("div", {
103
+ style: {
104
+ minWidth: 250
105
+ }
106
+ }, /*#__PURE__*/React.createElement("div", {
107
+ ref: menuRef,
108
+ style: {
109
+ position: 'relative'
110
+ }
111
+ }, /*#__PURE__*/React.createElement("p", {
112
+ className: 'fw-bold'
113
+ }, "Nh\xF3m d\u1EEF li\u1EC7u theo c\u1ED9t"), /*#__PURE__*/React.createElement("div", {
114
+ className: 'mb-1',
115
+ style: {
116
+ marginBottom: '1rem'
117
+ }
118
+ }, /*#__PURE__*/React.createElement("p", {
119
+ className: 'm-0',
120
+ style: {
121
+ margin: 0
122
+ }
123
+ }, "M\u1EE9c 1"), /*#__PURE__*/React.createElement(Select, {
124
+ style: {
125
+ width: '100%'
126
+ },
127
+ showSearch: true
128
+ // labelInValue={true}
129
+ // options={columns.filter((it: any) => !tempGroup.includes(it.field))}
130
+ // options={columns && columns.length > 0 ? options : []}
131
+ ,
132
+ options: options,
133
+ value: tempGroup?.[0],
134
+ onChange: val => onChangeGroupColumns(val, 0),
135
+ allowClear: !tempGroup?.[1] && !(unClearableLevel && unClearableLevel - 1 >= 0)
136
+ // fieldNames={{
137
+ // value: 'field',
138
+ // label: 'headerText'
139
+ // }}
140
+ ,
141
+ labelRender: labelProps => {
142
+ const it = columns.find(col => col.field === labelProps.value);
143
+ return t ? t(it?.columnGroupText ?? it?.headerText) : it?.columnGroupText ?? it?.headerText;
144
+ },
145
+ filterOption: customFilterOption
146
+ // hideSelectedOptions
147
+ })), /*#__PURE__*/React.createElement("div", {
148
+ className: 'mb-1',
149
+ style: {
150
+ marginBottom: '1rem'
151
+ }
152
+ }, /*#__PURE__*/React.createElement("p", {
153
+ className: 'm-0',
154
+ style: {
155
+ margin: 0
156
+ }
157
+ }, "M\u1EE9c 2"), /*#__PURE__*/React.createElement(Select, {
158
+ showSearch: true,
159
+ style: {
160
+ width: '100%'
161
+ },
162
+ options: options,
163
+ value: tempGroup?.[1],
164
+ onChange: val => onChangeGroupColumns(val, 1),
165
+ allowClear: !tempGroup?.[2] && !(unClearableLevel && unClearableLevel - 2 >= 0)
166
+ // hideSelectedOptions
167
+ // fieldNames={{
168
+ // value: 'field',
169
+ // label: 'headerText'
170
+ // }}
171
+ ,
172
+ labelRender: labelProps => {
173
+ const it = columns.find(col => col.field === labelProps.value);
174
+ return t ? t(it?.columnGroupText ?? it?.headerText) : it?.columnGroupText ?? it?.headerText;
175
+ },
176
+ filterOption: customFilterOption
177
+ })), /*#__PURE__*/React.createElement("div", {
178
+ className: 'mb-1',
179
+ style: {
180
+ marginBottom: '1rem'
181
+ }
182
+ }, /*#__PURE__*/React.createElement("p", {
183
+ className: 'm-0',
184
+ style: {
185
+ margin: 0
186
+ }
187
+ }, "M\u1EE9c 3"), /*#__PURE__*/React.createElement(Select, {
188
+ style: {
189
+ width: '100%'
190
+ },
191
+ options: options,
192
+ showSearch: true,
193
+ value: tempGroup?.[2],
194
+ onChange: val => onChangeGroupColumns(val, 2),
195
+ allowClear: !!tempGroup?.[2] && !(unClearableLevel && unClearableLevel - 3 >= 0)
196
+ // fieldNames={{
197
+ // value: 'field',
198
+ // label: 'headerText'
199
+ // }}
200
+ ,
201
+ labelRender: labelProps => {
202
+ const it = columns.find(col => col.field === labelProps.value);
203
+ return t ? t(it?.columnGroupText ?? it?.headerText) : it?.columnGroupText ?? it?.headerText;
204
+ },
205
+ filterOption: customFilterOption
206
+ }))), /*#__PURE__*/React.createElement(BoxAction, {
207
+ className: 'px-1'
208
+ }, /*#__PURE__*/React.createElement(Button
209
+ // className={classnames('btn-action btn-action-submit', {
210
+ // // disable: !columns.find((item) => item.visible !== false || item.visible)
211
+ // })}
212
+ , {
213
+ onClick: handleGroup
214
+ // disabled={!columns.find((item) => item.visible !== false || item.visible)}
215
+ }, t ? t('Thực hiện') : 'Thực hiện'), /*#__PURE__*/React.createElement(Button, {
216
+ className: 'btn-action btn-action-cancel',
217
+ onClick: handleClear
218
+ }, t ? t('Clear') : 'Clear'))),
219
+ trigger: "click",
220
+ open: clicked,
221
+ onOpenChange: handleClickChange,
222
+ arrow: false
223
+ }, /*#__PURE__*/React.createElement(Tooltip, {
224
+ arrow: false,
225
+ title: 'Nhóm dữ liệu'
226
+ }, /*#__PURE__*/React.createElement(Group, {
227
+ fontSize: 18,
228
+ style: {
229
+ cursor: 'pointer'
230
+ }
231
+ }))));
232
+ };
@@ -0,0 +1 @@
1
+ export * from './ColumnsGroup';
@@ -0,0 +1 @@
1
+ export * from "./ColumnsGroup";
@@ -1,9 +1,8 @@
1
1
  import React from 'react';
2
2
  import 'react-resizable/css/styles.css';
3
- import type { GridTableProps } from "./type";
4
3
  import 'dayjs/locale/es';
5
4
  import 'dayjs/locale/vi';
6
- import './styles.scss';
5
+ import type { TableProps } from '../table-component/type';
7
6
  export declare const SELECTION_COLUMN: {};
8
- declare const InternalTable: <RecordType extends object>(props: GridTableProps<RecordType>) => React.JSX.Element;
7
+ declare const InternalTable: <RecordType extends object>(props: TableProps<RecordType>) => React.JSX.Element;
9
8
  export default InternalTable;
@@ -0,0 +1,413 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
3
+ import React, { Fragment, useState } from 'react';
4
+ import 'react-resizable/css/styles.css';
5
+ import dayjs from 'dayjs';
6
+ import 'dayjs/locale/es';
7
+ import 'dayjs/locale/vi';
8
+
9
+ // import './style.scss'
10
+
11
+ import { faker } from '@faker-js/faker';
12
+ import useMergedState from "rc-util/es/hooks/useMergedState";
13
+ import { getCoreRowModel, getExpandedRowModel, getGroupedRowModel, getPaginationRowModel, useReactTable } from '@tanstack/react-table';
14
+ import { addRowIdArray, convertFlatColumn1, convertToObj, convertToObjTrue, filterDataByColumns, findAllChildrenKeys2, flatColumns2, getAllRowKey, getDiffent2Array, getFixedFields, getInvisibleColumns, groupArrayByColumns, isTreeArray, removeKeys } from "./hook/utils";
15
+ import { convertToTanStackColumns } from "./hook/useColumns";
16
+ // import { convertColumns } from './hook/convert'
17
+ import { removeInvisibleColumns } from "../grid-component/hooks";
18
+ import Grid from "./table/Grid";
19
+ import { removeColumns } from "../table-component/hook/utils";
20
+ import { OperatorFeature } from "../table-component/features/operator";
21
+ // import { ColumnsGroup } from '../grid-component/ColumnsGroup'
22
+
23
+ dayjs.extend(customParseFormat);
24
+ export const SELECTION_COLUMN = {};
25
+ const InternalTable = props => {
26
+ const {
27
+ t,
28
+ columns: propsColumns,
29
+ // columns,
30
+ lang,
31
+ locale,
32
+ dataSource,
33
+ editAble,
34
+ format,
35
+ groupAble,
36
+ groupSetting,
37
+ groupColumns,
38
+ selectionSettings,
39
+ expandable,
40
+ onChooseColumns,
41
+ height,
42
+ pagination,
43
+ allowResizing,
44
+ infiniteScroll,
45
+ sortMultiple,
46
+ allowSortering,
47
+ allowFiltering,
48
+ ...rest
49
+ } = props;
50
+ const id = React.useMemo(() => {
51
+ return faker.string.alpha(20);
52
+ }, []);
53
+ const {
54
+ defaultExpandedRowKeys,
55
+ defaultExpandAllRows
56
+ } = expandable || {};
57
+ const rowKey = 'rowId';
58
+ const prefix = 'ui-rc';
59
+ const getWindowSize = () => {
60
+ const {
61
+ innerWidth,
62
+ innerHeight
63
+ } = window;
64
+ return {
65
+ innerWidth,
66
+ innerHeight
67
+ };
68
+ };
69
+ const [windowSize, setWindowSize] = useState(getWindowSize());
70
+ React.useEffect(() => {
71
+ const handleWindowResize = () => {
72
+ setWindowSize(getWindowSize());
73
+ };
74
+ window.addEventListener('resize', handleWindowResize);
75
+ return () => {
76
+ window.removeEventListener('resize', handleWindowResize);
77
+ };
78
+ }, []);
79
+ const [columnResizeMode] = React.useState('onChange');
80
+ const [columnResizeDirection] = React.useState('ltr');
81
+ const [rowSelection, setRowSelection] = React.useState({});
82
+
83
+ // const [grouping, setGrouping] = React.useState<GroupingState>([])
84
+
85
+ const [paginationState, setPagination] = React.useState({
86
+ pageIndex: pagination && pagination.currentPage ? pagination.currentPage - 1 : 0,
87
+ pageSize: pagination && pagination.pageSize ? pagination.pageSize : 20
88
+ });
89
+ const [columnSizing, setColumnSizing] = React.useState({});
90
+ const [columnSizingInfo, setColumnSizingInfo] = React.useState({});
91
+
92
+ // const [columnOrder, setColumnOrder] = React.useState<string[]>(() => columns.map(c => c.id!))
93
+
94
+ const [columnFilters, setColumnFilters] = React.useState([]);
95
+ const [operator, setOperator] = React.useState([]);
96
+ const [sorting, setSorting] = React.useState([]);
97
+ const [filterStates, setFilterState] = React.useState(null);
98
+ const [sorterStates, setSorterStates] = React.useState([]);
99
+ const [isFullScreen, setIsFullScreen] = React.useState(false);
100
+ const [columns, setColumns] = React.useState([]);
101
+ const [tableData, setTableData] = React.useState([]);
102
+ const [expanded, setExpanded] = React.useState({});
103
+
104
+ // const [visible, setVisible] = React.useState({visible: false, column: ''})
105
+
106
+ const [columnVisibility, setColumnVisibility] = React.useState({});
107
+ const originData = React.useMemo(() => {
108
+ return addRowIdArray(dataSource);
109
+ }, [dataSource]);
110
+ const isDataOriginTree = React.useMemo(() => {
111
+ return isTreeArray(originData);
112
+ }, [originData]);
113
+ React.useEffect(() => {
114
+ if (groupColumns && groupColumns.length > 0 && groupSetting?.client !== false && isDataOriginTree === false) {
115
+ const abc = groupArrayByColumns(originData, groupColumns);
116
+ const rs = filterDataByColumns(abc, filterStates, sorterStates, []);
117
+ setTableData(rs);
118
+ } else {
119
+ const rs = filterDataByColumns(originData, filterStates, sorterStates, []);
120
+ setTableData(rs);
121
+ }
122
+ }, [groupColumns, originData, filterStates, sorterStates, groupSetting?.client, isDataOriginTree]);
123
+ // }, [groupColumns, originData, filterStates, sorterStates, groupSetting?.client])
124
+
125
+ React.useEffect(() => {
126
+ // setColumns(updateWidthsByOther(propsColumns, columns))
127
+ setColumns(propsColumns);
128
+ }, [propsColumns]);
129
+
130
+ // const convertData = React.useMemo(() => {
131
+
132
+ // if (groupAble && groupSetting && groupSetting.client !== false) {
133
+
134
+ // const bbc = addRowIdArray(dataSource)
135
+
136
+ // const abc = groupArrayByColumns(bbc, groupColumns)
137
+
138
+ // return abc
139
+ // } else {
140
+
141
+ // return addRowIdArray(dataSource)
142
+
143
+ // }
144
+
145
+ // }, [dataSource, groupAble, groupColumns, groupSetting])
146
+
147
+ const mergedColumns = React.useMemo(() => {
148
+ return convertToTanStackColumns({
149
+ t,
150
+ columns,
151
+ format,
152
+ editAble
153
+ });
154
+
155
+ // return convertToTanStackColumns<RecordType>(columns)
156
+ }, [t, columns, format, editAble]);
157
+ const isDataTree = React.useMemo(() => {
158
+ return isTreeArray(tableData);
159
+ }, [tableData]);
160
+ const columnPinning = React.useMemo(() => {
161
+ return {
162
+ left: getFixedFields(columns, 'left'),
163
+ right: getFixedFields(columns, 'right')
164
+ };
165
+ }, [columns]);
166
+
167
+ // ========================= Keys =========================
168
+ const [mergedFilterKeys, setMergedFilterKeys] = useMergedState(getAllRowKey(originData), {
169
+ value: undefined
170
+ });
171
+
172
+ // ========================= Keys =========================
173
+
174
+ const {
175
+ selectedRowKeys,
176
+ defaultSelectedRowKeys
177
+ } = selectionSettings ?? {};
178
+ const [mergedSelectedKeys] = useMergedState(selectedRowKeys || defaultSelectedRowKeys || [], {
179
+ value: selectedRowKeys
180
+ });
181
+
182
+ // const mergedData = React.useMemo(() => {
183
+
184
+ // return filterDataByColumns(tableData, filterStates, sorterStates, mergedFilterKeys)
185
+
186
+ // }, [tableData, filterStates, mergedFilterKeys, sorterStates])
187
+
188
+ // const columnVisibility = React.useMemo(() => {
189
+ // return getInvisibleColumns(columns)
190
+ // }, [columns])
191
+
192
+ React.useEffect(() => {
193
+ const a = getInvisibleColumns(columns);
194
+ setColumnVisibility(a);
195
+ }, [columns]);
196
+ const [columnsHiddenKeys, setColumnsHiddenKeys] = useMergedState(undefined, {
197
+ value: undefined
198
+ });
199
+ const triggerChangeColumns = (cols, keys, type) => {
200
+ if (type === 'cellClick') {
201
+ setColumns(cols);
202
+ } else {
203
+ const aa = flatColumns2(columns).map(it => it.field);
204
+ const rsss = getDiffent2Array(aa, keys);
205
+ setColumnsHiddenKeys(rsss);
206
+ onChooseColumns?.({
207
+ showColumns: removeInvisibleColumns([...cols]),
208
+ columns: [...cols],
209
+ flattenColumns: convertFlatColumn1([...cols])
210
+ });
211
+ }
212
+ };
213
+ const table = useReactTable({
214
+ _features: [OperatorFeature],
215
+ data: tableData,
216
+ // data: mergedData,
217
+ columns: mergedColumns,
218
+ state: {
219
+ rowSelection,
220
+ expanded,
221
+ columnPinning,
222
+ columnVisibility: columnsHiddenKeys ? convertToObj(columnsHiddenKeys) : columnVisibility,
223
+ pagination: pagination && !infiniteScroll ? paginationState : undefined,
224
+ // grouping,
225
+ columnSizing,
226
+ // columnOrder,
227
+ columnFilters,
228
+ operator,
229
+ sorting,
230
+ columnSizingInfo
231
+ },
232
+ getCoreRowModel: getCoreRowModel(),
233
+ getRowId(originalRow) {
234
+ return originalRow.rowId;
235
+ },
236
+ getSubRows: row => row.children,
237
+ // --------------RowSelection -----------------
238
+ enableSubRowSelection: selectionSettings && selectionSettings.mode === 'checkbox' && selectionSettings.type !== 'single',
239
+ enableMultiRowSelection: selectionSettings && (selectionSettings.mode === 'checkbox' || selectionSettings.type !== 'single'),
240
+ enableRowSelection: row => {
241
+ if (selectionSettings?.getCheckboxProps) {
242
+ return !selectionSettings?.getCheckboxProps(row.original)?.disabled;
243
+ }
244
+ return true;
245
+ },
246
+ onRowSelectionChange: setRowSelection,
247
+ // --------------RowSelection END-----------------
248
+
249
+ // ColumnSizing
250
+ enableColumnResizing: allowResizing !== false,
251
+ columnResizeMode,
252
+ columnResizeDirection,
253
+ onColumnSizingChange: setColumnSizing,
254
+ onColumnSizingInfoChange: setColumnSizingInfo,
255
+ // ColumnSizing
256
+
257
+ // ColumnSorting
258
+ // getSortedRowModel: getSortedRowModel(),
259
+ onSortingChange: setSorting,
260
+ enableMultiSort: sortMultiple !== false,
261
+ isMultiSortEvent: () => sortMultiple === false ? false : true,
262
+ enableSorting: allowSortering !== false,
263
+ // ColumnSorting
264
+
265
+ enableFilters: allowFiltering !== false,
266
+ onColumnFiltersChange: setColumnFilters,
267
+ onColumnOperatorChange: setOperator,
268
+ // getFilteredRowModel: getFilteredRowModel(),
269
+
270
+ // onColumnOrderChange: setColumnOrder,
271
+
272
+ // onGroupingChange: setGrouping,
273
+ getGroupedRowModel: getGroupedRowModel(),
274
+ // onExpandedChange: setExpanded,
275
+ getExpandedRowModel: getExpandedRowModel(),
276
+ getPaginationRowModel: pagination && !infiniteScroll ? getPaginationRowModel() : undefined,
277
+ onPaginationChange: setPagination,
278
+ onColumnVisibilityChange: setColumnVisibility
279
+ // onColumnPinningChange,
280
+
281
+ // debugTable: true
282
+ });
283
+ React.useEffect(() => {
284
+ if (defaultExpandAllRows) {
285
+ const allKeys = findAllChildrenKeys2(tableData, rowKey, 'children');
286
+ setExpanded(convertToObjTrue(allKeys));
287
+ } else {
288
+ if (defaultExpandedRowKeys) {
289
+ setExpanded(convertToObjTrue(defaultExpandedRowKeys ?? []));
290
+ }
291
+ }
292
+ }, [defaultExpandAllRows, defaultExpandedRowKeys, tableData, table]);
293
+ const triggerGroupColumns = groupedColumns => {
294
+ // const abc = updateColumnsByGroup(columns, groupedColumns)
295
+
296
+ const bcd = convertToObj(groupedColumns);
297
+
298
+ // const a = getInvisibleColumns(columns)
299
+
300
+ const prev = groupColumns ?? [];
301
+ const bbb = prev.filter(item => !groupedColumns.includes(item));
302
+ const ccc = removeKeys(columnVisibility, bbb);
303
+ const rs = {
304
+ ...ccc,
305
+ ...bcd
306
+ };
307
+ setColumnVisibility(rs);
308
+
309
+ // table.setColumnVisibility(rs)
310
+
311
+ if (groupSetting) {
312
+ if (groupSetting.onGroup) {
313
+ groupSetting.onGroup({
314
+ columnGrouped: groupedColumns,
315
+ columns: removeColumns(columns, groupedColumns),
316
+ flattenColumns: flatColumns2(removeColumns(columns, groupedColumns))
317
+ });
318
+ }
319
+ if (groupSetting.client === false) {
320
+
321
+ // group server => không xử lý gì
322
+ } else {
323
+ // group client
324
+
325
+ table.resetRowSelection();
326
+ table.resetExpanded();
327
+ setRowSelection({});
328
+ setExpanded({});
329
+ }
330
+ }
331
+ };
332
+
333
+ // useEffect(() => {
334
+
335
+ // table.toggleAllRowsExpanded(true)
336
+
337
+ // }, [tableData ])
338
+
339
+ const triggerFilter = args => {
340
+ // table.resetRowSelection()
341
+ // table.resetExpanded()
342
+
343
+ // setRowSelection({})
344
+ setExpanded({});
345
+ setFilterState(args);
346
+
347
+ // const rs = filterDataByColumns(originData, args, sorterStates, [])
348
+
349
+ // const allKeys = findAllChildrenKeys2<RecordType>(rs, rowKey, 'children')
350
+
351
+ // setExpanded(convertToObjTrue(allKeys))
352
+
353
+ // setTableData(rs)
354
+ };
355
+ const triggerSorter = args => {
356
+ // table.resetRowSelection()
357
+ // table.resetExpanded()
358
+
359
+ // setRowSelection({})
360
+ // setExpanded({})
361
+
362
+ setSorterStates(args);
363
+
364
+ // const rs = filterDataByColumns(originData, filterStates, args, [])
365
+ // setTableData(rs)
366
+ };
367
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Grid, _extends({}, rest, {
368
+ t: t,
369
+ id: id,
370
+ table: table,
371
+ prefix: prefix,
372
+ originData: originData
373
+ // dataSource={mergedData}
374
+ ,
375
+ dataSource: tableData,
376
+ locale: locale,
377
+ format: format
378
+ // columns={convertColumns(mergedColumns)}
379
+ ,
380
+ columns: mergedColumns,
381
+ propsColumns: columns,
382
+ rowKey: rowKey,
383
+ groupSetting: groupSetting,
384
+ groupAble: groupAble,
385
+ groupColumns: groupColumns,
386
+ columnPinning: columnPinning,
387
+ columnHidden: columnsHiddenKeys ? convertToObj(columnsHiddenKeys) : columnVisibility,
388
+ triggerFilter: triggerFilter,
389
+ triggerSorter: triggerSorter,
390
+ setMergedFilterKeys: setMergedFilterKeys,
391
+ mergedFilterKeys: mergedFilterKeys,
392
+ editAble: isFullScreen ? false : editAble,
393
+ triggerChangeColumns: triggerChangeColumns,
394
+ triggerGroupColumns: triggerGroupColumns,
395
+ expanded: expanded,
396
+ setExpanded: setExpanded,
397
+ isFullScreen: isFullScreen,
398
+ setIsFullScreen: setIsFullScreen,
399
+ windowSize: windowSize,
400
+ height: height,
401
+ isDataTree: isDataTree,
402
+ selectionSettings: selectionSettings,
403
+ mergedSelectedKeys: mergedSelectedKeys,
404
+ expandable: expandable,
405
+ setColumns: setColumns,
406
+ columnFilters: columnFilters,
407
+ columnSizing: columnSizing,
408
+ columnSizingInfo: columnSizingInfo,
409
+ setColumnSizing: setColumnSizing,
410
+ rowSelection: rowSelection
411
+ })));
412
+ };
413
+ export default InternalTable;
@@ -0,0 +1,14 @@
1
+ import { type Table } from "@tanstack/react-table";
2
+ import type { CommandClick } from "../../table-component/type";
3
+ import React from "react";
4
+ interface TableBodyProps<T> {
5
+ table: Table<T>;
6
+ tableContainerRef: React.RefObject<HTMLDivElement>;
7
+ commandClick?: (args: CommandClick<T>) => void;
8
+ editAble?: boolean;
9
+ tableId: string;
10
+ showEmptyText?: boolean;
11
+ [key: string]: any;
12
+ }
13
+ declare const TableBody: <RecordType extends object>({ columnVirtualizer, table, tableContainerRef, virtualPaddingLeft, virtualPaddingRight, fixedLeftColumns, fixedRightColumns, tableId, showEmptyText, ...rest }: TableBodyProps<RecordType>) => React.JSX.Element;
14
+ export default TableBody;