es-grid-template 1.1.7 → 1.2.0

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 (31) hide show
  1. package/es/grid-component/ColumnsChoose.js +1 -1
  2. package/es/grid-component/GridStyle.js +1 -1
  3. package/es/grid-component/InternalTable.js +94 -107
  4. package/es/grid-component/TableGrid.d.ts +4 -2
  5. package/es/grid-component/TableGrid.js +17 -7
  6. package/es/grid-component/hooks/constant.js +14 -14
  7. package/es/grid-component/hooks/useColumns/index.d.ts +5 -3
  8. package/es/grid-component/hooks/useColumns/index.js +29 -1
  9. package/es/grid-component/hooks/utils.d.ts +6 -2
  10. package/es/grid-component/hooks/utils.js +44 -2
  11. package/es/grid-component/styles.scss +766 -701
  12. package/es/grid-component/table/Grid.d.ts +3 -0
  13. package/es/grid-component/table/Grid.js +3 -3
  14. package/es/grid-component/table/GridEdit.js +234 -168
  15. package/es/grid-component/type.d.ts +6 -2
  16. package/lib/grid-component/ColumnsChoose.js +1 -1
  17. package/lib/grid-component/GridStyle.js +1 -1
  18. package/lib/grid-component/InternalTable.js +92 -103
  19. package/lib/grid-component/TableGrid.d.ts +4 -2
  20. package/lib/grid-component/TableGrid.js +17 -7
  21. package/lib/grid-component/hooks/constant.js +14 -14
  22. package/lib/grid-component/hooks/useColumns/index.d.ts +5 -3
  23. package/lib/grid-component/hooks/useColumns/index.js +30 -1
  24. package/lib/grid-component/hooks/utils.d.ts +6 -2
  25. package/lib/grid-component/hooks/utils.js +51 -5
  26. package/lib/grid-component/styles.scss +766 -701
  27. package/lib/grid-component/table/Grid.d.ts +3 -0
  28. package/lib/grid-component/table/Grid.js +3 -3
  29. package/lib/grid-component/table/GridEdit.js +228 -164
  30. package/lib/grid-component/type.d.ts +6 -2
  31. package/package.json +105 -105
@@ -154,7 +154,7 @@ export const ColumnsChoose = props => {
154
154
  style: {
155
155
  marginBottom: 8
156
156
  },
157
- placeholder: "Search",
157
+ placeholder: t ? t("Search") : 'Search',
158
158
  prefix: /*#__PURE__*/React.createElement(SearchOutlined, null),
159
159
  onChange: onChange
160
160
  }), /*#__PURE__*/React.createElement(Tree, {
@@ -2,4 +2,4 @@ import styled from "styled-components";
2
2
  export const GridStyle = styled.div.withConfig({
3
3
  displayName: "GridStyle",
4
4
  componentId: "es-grid-template__sc-sueu2e-0"
5
- })([".ui-rc-pagination{border-bottom:1px solid #e0e0e0;border-top:1px solid #e0e0e0;margin:0;padding:.75rem 1rem;.ui-rc-pagination-total-text{order:2;margin-left:auto;}&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:", ";bottom:0;left:0;z-index:-1;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:", ";bottom:0;visibility:visible;right:0;z-index:-1;}}.react-resizable{position:relative;background-clip:padding-box;}.react-resizable-handle{position:absolute;right:0px;bottom:0;z-index:1;width:5px;height:100%;cursor:col-resize;&.none{cursor:auto;display:none;}}"], props => props.heightTable ? typeof props.heightTable === 'string' ? props.heightTable : `${props.heightTable}px` : undefined, props => props.heightTable ? `${props.heightTable}px` : undefined);
5
+ })([".ui-rc-pagination{border-bottom:1px solid #e0e0e0;border-top:1px solid #e0e0e0;margin:0;padding:.75rem 1rem;.ui-rc-pagination-total-text{order:2;margin-left:auto;}&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:50px;bottom:0;left:0;z-index:-1;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:50px;bottom:0;visibility:visible;right:0;z-index:-1;}&.pagination-template{&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:", ";bottom:0;left:0;z-index:-1;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:", ";bottom:0;visibility:visible;right:0;z-index:-1;}}}.react-resizable{position:relative;background-clip:padding-box;}.react-resizable-handle{position:absolute;right:0px;bottom:0;z-index:1;width:5px;height:100%;cursor:col-resize;&.none{cursor:auto;display:none;}}"], props => props.heightTable ? typeof props.heightTable === 'string' ? props.heightTable : `${props.heightTable}px` : '50px', props => props.heightTable ? `${props.heightTable}px` : '50px');
@@ -5,11 +5,9 @@ import { Button, Space } from "antd";
5
5
  import { SearchOutlined } from "@ant-design/icons";
6
6
  import { Resizable } from "react-resizable";
7
7
  import customParseFormat from 'dayjs/plugin/customParseFormat';
8
- import {
9
- // findAllChildrenKeys,
10
- numberOperator, translateOption, updateArrayByKey } from "./hooks";
8
+ import { booleanOperator, getTypeFilter, numberOperator, stringOperator, translateOption, updateArrayByKey } from "./hooks";
11
9
  import { FilterFill } from "becoxy-icons";
12
- import { renderContent, renderFilter } from "./hooks/useColumns";
10
+ import { flatColumns2, renderContent, renderFilter } from "./hooks/useColumns";
13
11
  import dayjs from "dayjs";
14
12
  import 'dayjs/locale/es';
15
13
  import 'dayjs/locale/vi';
@@ -82,8 +80,6 @@ const InternalTable = props => {
82
80
  // },
83
81
  // );
84
82
 
85
- // console.log('mergedColumns', mergedColumns)
86
-
87
83
  const tableRef = useRef(null);
88
84
  const [data, setData] = useState([]);
89
85
  const [columns, setColumns] = useState([]);
@@ -91,7 +87,7 @@ const InternalTable = props => {
91
87
  // const [expandKeys, setExpandKeys] = useState<string[]>([]);
92
88
  const [dataSourceFilter, setDataSourceFilter] = useState(propDataSourceFilter ?? []);
93
89
  useEffect(() => {
94
- const rs = propsColumns ? [Table.SELECTION_COLUMN, ...propsColumns] : [];
90
+ const rs = propsColumns && propsColumns.length > 0 ? [Table.SELECTION_COLUMN, ...propsColumns] : [];
95
91
  // const rs = propsColumns ? [...propsColumns] : []
96
92
  setColumns(rs);
97
93
  }, [propsColumns]);
@@ -147,13 +143,17 @@ const InternalTable = props => {
147
143
  setSelectedKeys,
148
144
  selectedKeys,
149
145
  confirm,
150
- close,
146
+ // close,
151
147
  setOperatorKey,
152
148
  operatorKey,
153
149
  visible,
154
150
  searchValue,
155
151
  setSearchValue
156
152
  }) => {
153
+ const type = getTypeFilter(column);
154
+ // const operatorOptions = !type || type === 'Text' ? stringOperator : numberOperator
155
+ // const operatorOptions = type === 'Checkbox' || type === 'Dropdown' || type === 'DropTree' || ty
156
+ const operatorOptions = type === ('Checkbox' || 'Dropdown' || 'DropTree' || 'CheckboxDropdown') ? booleanOperator : !type || type === 'Text' ? stringOperator : numberOperator;
157
157
  return /*#__PURE__*/React.createElement("div", {
158
158
  style: {
159
159
  padding: 8,
@@ -163,7 +163,7 @@ const InternalTable = props => {
163
163
  }, column?.showOperator !== false && column?.typeFilter !== 'DateRange' && column?.typeFilter !== 'NumberRange' && /*#__PURE__*/React.createElement("div", {
164
164
  className: 'mb-1'
165
165
  }, /*#__PURE__*/React.createElement(Select, {
166
- options: translateOption(numberOperator, t),
166
+ options: translateOption(operatorOptions, t),
167
167
  style: {
168
168
  width: '100%',
169
169
  marginBottom: 8
@@ -194,13 +194,17 @@ const InternalTable = props => {
194
194
  style: {
195
195
  width: 90
196
196
  }
197
- }, "Filter"), /*#__PURE__*/React.createElement(Button, {
197
+ }, t ? t('Filter') : 'Filter'), /*#__PURE__*/React.createElement(Button, {
198
198
  type: "link",
199
199
  size: "small",
200
200
  onClick: () => {
201
- close();
201
+ // setSearchValue('')
202
+ setSelectedKeys([]);
203
+ confirm();
204
+ // handleSearch()
205
+ // close()
202
206
  }
203
- }, "close")));
207
+ }, t ? t("Clear") : 'Clear')));
204
208
  },
205
209
  filterIcon: filtered => /*#__PURE__*/React.createElement(FilterFill, {
206
210
  fontSize: 12,
@@ -219,117 +223,100 @@ const InternalTable = props => {
219
223
  }
220
224
  }
221
225
  }), [buddhistLocale, dataSourceFilter, onFilterCallback, onFilterClick, t]);
222
- const handleResize = indexPath => (e, {
226
+ const handleResize = column => (e, {
223
227
  size
224
228
  }) => {
225
- const updateColumns = (cols, path) => {
226
- const [currentIndex, ...restPath] = path;
227
- return cols.map((col, idx) => {
228
- if (idx === currentIndex) {
229
- if (restPath.length === 0) {
230
- // Cập nhật width của cột cuối cùng trong path
231
- // return { ...col, width: size.width }
232
-
233
- // Kiểm tra minWidth trước khi cập nhật width
234
- if (col.minWidth && size.width < col.minWidth) {
235
- e.preventDefault();
236
- return col; // Không cập nhật nếu nhỏ hơn minWidth
237
- }
238
-
239
- // Kiểm tra minWidth trước khi cập nhật width
240
- if (col.maxWidth && size.width > col.maxWidth) {
241
- e.preventDefault();
242
- return col; // Không cập nhật nếu nhỏ hơn minWidth
243
- }
244
- return {
245
- ...col,
246
- width: size.width
247
- };
248
- } else if (col.children) {
249
- // Tiếp tục cập nhật các cấp con
250
- return {
251
- ...col,
252
- children: updateColumns(col.children, restPath)
253
- };
254
- }
255
- }
256
- // e.preventDefault()
257
- return col;
258
- });
229
+ const newColumn = {
230
+ ...column,
231
+ width: size.width
259
232
  };
260
- setColumns(prevColumns => updateColumns(prevColumns, indexPath));
233
+ const newColumns = updateArrayByKey(columns, newColumn, 'field');
234
+ setColumns(newColumns);
261
235
  };
262
- const transformColumns = React.useCallback((cols, parentPath = []) => {
263
- return cols.map((col, index) => {
264
- const currentPath = [...parentPath, index];
265
- // @ts-ignore
266
- if (!col?.dataIndex && !col.key && !col.field) {
267
- return col;
268
- }
269
- const transformedColumn = {
270
- ...col,
271
- dataIndex: col.field ?? col.dataIndex,
272
- key: col.field ?? col.dataIndex ?? col.key,
273
- title: t ? t(col.headerText ?? col.title) : col.headerText ?? col.title,
274
- ellipsis: col.ellipsis !== false,
275
- align: col.textAlign ?? col.align,
276
- fixed: col.frozen ? col.frozen.toLowerCase() : col.fixed
236
+ const convertColumns = flatColumns2(columns).map((column, colIndex) => {
237
+ if (!column?.dataIndex && !column.key && !column.field) {
238
+ return column;
239
+ }
240
+ const transformedColumn = {
241
+ ...column,
242
+ dataIndex: column.field ?? column.dataIndex,
243
+ key: column.field ?? column.dataIndex ?? column.key,
244
+ title: t ? t(column.headerText ?? column.title) : column.headerText ?? column.title,
245
+ ellipsis: column.ellipsis !== false,
246
+ align: column.textAlign ?? column.align,
247
+ fixed: column.frozen ? column.frozen.toLowerCase() : column.fixed
248
+ };
249
+
250
+ // @ts-ignore
251
+ if (["index", "#"].includes(transformedColumn.dataIndex)) {
252
+ return {
253
+ ...transformedColumn,
254
+ onCell: () => ({
255
+ className: 'cell-number'
256
+ }),
257
+ render: (_, __, rowIndex) => rowIndex + 1
277
258
  };
278
- if (col.children) {
279
- return {
280
- ...transformedColumn,
281
- children: transformColumns(col.children, currentPath)
282
- };
259
+ }
260
+ if (column.field === 'command') {
261
+ return {
262
+ ...transformedColumn,
263
+ onCell: () => ({
264
+ className: column.field === 'command' ? "ui-rc-cell-command" : ''
265
+ }),
266
+ onHeaderCell: () => ({
267
+ width: column.width,
268
+ onResize: handleResize(column)
269
+ })
270
+ };
271
+ }
272
+ return {
273
+ ...(column.allowFiltering === false ? {} : {
274
+ ...getColumnSearchProps(column)
275
+ }),
276
+ ...transformedColumn,
277
+ onFilter: value => {
278
+ return value;
279
+ },
280
+ sorter: column.sorter === false ? undefined : {
281
+ compare: a => a,
282
+ multiple: sortMultiple ? colIndex : undefined
283
+ },
284
+ onHeaderCell: () => ({
285
+ width: column.width,
286
+ onResize: handleResize(column)
287
+ }),
288
+ render: (value, record, rowIndex) => renderContent(column, value, record, rowIndex, format)
289
+ };
290
+ });
291
+ const transformColumns = React.useCallback(cols => {
292
+ // @ts-ignore
293
+ return cols.map(column => {
294
+ const find = convertColumns.find(it => it.key === column.field);
295
+ if (!column?.field && !column?.key) {
296
+ return column;
283
297
  }
284
-
285
- // @ts-ignore
286
- if (["index", "#"].includes(transformedColumn.dataIndex)) {
298
+ if (find) {
287
299
  return {
288
- ...transformedColumn,
289
- onCell: () => ({
290
- className: 'cell-number'
291
- }),
292
- render: (_, __, rowIndex) => rowIndex + 1
300
+ ...find
293
301
  };
294
302
  }
295
- if (col.field === 'command') {
303
+
304
+ // Xử lý đệ quy cho children
305
+ if (column.children?.length) {
296
306
  return {
297
- ...transformedColumn,
298
- onCell: () => ({
299
- className: col.field === 'command' ? "ui-rc-cell-command" : ''
300
- }),
301
- onHeaderCell: () => ({
302
- width: col.width,
303
- onResize: handleResize(currentPath)
304
- })
307
+ ...column,
308
+ key: column.field ?? column.dataIndex ?? column.key,
309
+ title: t ? t(column.headerText ?? column.title) : column.headerText ?? column.title,
310
+ ellipsis: column.ellipsis !== false,
311
+ align: column.textAlign ?? column.align,
312
+ children: transformColumns(column.children)
305
313
  };
306
314
  }
307
- return {
308
- ...(col.allowFiltering === false ? {} : {
309
- ...getColumnSearchProps(col)
310
- }),
311
- ...transformedColumn,
312
- onFilter: value => {
313
- return value;
314
- },
315
- sorter: col.sorter === false ? undefined : {
316
- compare: a => a,
317
- multiple: sortMultiple ? index : undefined
318
- },
319
- onHeaderCell: () => ({
320
- width: col.width,
321
- onResize: handleResize(currentPath)
322
- }),
323
- render: (value, record, rowIndex) => renderContent(col, value, record, rowIndex, format)
324
- };
325
315
  });
326
- }, [getColumnSearchProps]);
316
+ }, [convertColumns]);
327
317
  const mergedColumns = React.useMemo(() => {
328
318
  return transformColumns(columns);
329
319
  }, [transformColumns, columns]);
330
-
331
- // console.log('mergedColumns', mergedColumns)
332
-
333
320
  const triggerChangeColumns = newColumns => {
334
321
  setColumns(newColumns);
335
322
  };
@@ -1,11 +1,13 @@
1
1
  import React from 'react';
2
2
  import 'dayjs/locale/es';
3
3
  import 'dayjs/locale/vi';
4
- import type { ColumnsTable, GridTableProps } from "./type";
4
+ import type { ColumnsTable, GetRowKey, GridTableProps } from "./type";
5
5
  type GridProps<T> = GridTableProps<T> & {
6
6
  triggerChangeColumns?: (columns: ColumnsTable<T>, type: string) => void;
7
- triggerChangeData?: () => void;
7
+ triggerChangeData?: (newData: T[], type: string) => void;
8
8
  tableRef: any;
9
+ bottomToolbar?: () => React.ReactElement;
10
+ getRowKey?: GetRowKey<T>;
9
11
  };
10
12
  declare const TableGrid: <RecordType extends object>(props: GridProps<RecordType>) => React.JSX.Element;
11
13
  export default TableGrid;
@@ -90,6 +90,7 @@ const TableGrid = props => {
90
90
  dataSource,
91
91
  locale,
92
92
  expandable,
93
+ rowHoverable,
93
94
  // mergedData,
94
95
  title,
95
96
  format,
@@ -118,6 +119,7 @@ const TableGrid = props => {
118
119
  summary,
119
120
  showToolbar,
120
121
  onSorter,
122
+ bottomToolbar,
121
123
  ...rest
122
124
  } = props;
123
125
  const {
@@ -316,6 +318,7 @@ const TableGrid = props => {
316
318
  },
317
319
  loading: {
318
320
  spinning: columns && columns.length === 0 || loading === true,
321
+ // spinning: loading === true,
319
322
  indicator: /*#__PURE__*/React.createElement(ComponentSpinner, null)
320
323
  },
321
324
  dataSource: dataSource
@@ -328,7 +331,7 @@ const TableGrid = props => {
328
331
  virtual: virtual,
329
332
  columns: columns,
330
333
  rowKey: rowKey,
331
- rowHoverable: true,
334
+ rowHoverable: rowHoverable,
332
335
  size: "small",
333
336
  scroll: scroll ? scroll : {
334
337
  y: 500
@@ -341,7 +344,7 @@ const TableGrid = props => {
341
344
  onContextMenu: onContextMenu(data)
342
345
  };
343
346
  },
344
- rowSelection: {
347
+ rowSelection: columns && columns.length === 0 ? undefined : {
345
348
  ...selectionSettings,
346
349
  type: selectionSettings?.mode === 'checkbox' || type === 'multiple' ? 'checkbox' : "radio",
347
350
  columnWidth: !mode ? 0.0000001 : columnWidth ?? 50,
@@ -350,7 +353,9 @@ const TableGrid = props => {
350
353
  selectedRowKeys: mergedSelectedKeys,
351
354
  defaultSelectedRowKeys: selectionSettings?.defaultSelectedRowKeys,
352
355
  preserveSelectedRowKeys: true,
353
- ...rowSelection,
356
+ // ...rowSelection,
357
+ // checkStrictly: false,
358
+
354
359
  hideSelectAll: !type || type === 'single' || selectionSettings?.mode === 'radio' ? true : hideSelectAll ?? type !== 'multiple'
355
360
  },
356
361
  onScroll: () => {
@@ -408,9 +413,9 @@ const TableGrid = props => {
408
413
  // @ts-ignore
409
414
  , {
410
415
  style: {
411
- width: `calc(100% - 650px`
416
+ width: pagination && pagination.onChange && pagination?.position && pagination?.position[0] === 'topRight' ? `calc(100% - 650px` : `calc(100% - 25px`
412
417
  },
413
- items: toolbarItems ?? [],
418
+ items: (toolbarItems ?? []).filter(it => it.position !== 'Bottom'),
414
419
  mode: 'scroll'
415
420
  }), /*#__PURE__*/React.createElement("div", {
416
421
  style: {
@@ -445,7 +450,7 @@ const TableGrid = props => {
445
450
  } = args;
446
451
 
447
452
  // @ts-ignore
448
- if (record?.children && record?.children?.length > 0 || record?.isChildren) {
453
+ if (record?.children?.length > 0 || record?.isChildren) {
449
454
  return expanded ? /*#__PURE__*/React.createElement("button", {
450
455
  onClick: e => {
451
456
  e.preventDefault();
@@ -461,12 +466,17 @@ const TableGrid = props => {
461
466
  },
462
467
  className: 'ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed'
463
468
  });
469
+ } else {
470
+ return /*#__PURE__*/React.createElement("button", {
471
+ className: 'ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced'
472
+ });
464
473
  }
465
474
  }
466
475
  }
467
- })), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/React.createElement(Pagination
476
+ })), bottomToolbar?.(), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/React.createElement(Pagination
468
477
  // style={{padding: '0.75rem 1rem'}}
469
478
  , _extends({
479
+ rootClassName: 'pagination-template',
470
480
  showSizeChanger: true,
471
481
  responsive: true,
472
482
  size: 'small',
@@ -10,29 +10,29 @@ export const numberOperator = [{
10
10
  key: '>'
11
11
  }, {
12
12
  value: 'greaterthanorequal',
13
- label: 'Greater Than or Equal',
13
+ label: 'Greater than or equal',
14
14
  key: '>='
15
15
  }, {
16
16
  value: 'lessthan',
17
- label: 'Less Than',
17
+ label: 'Less than',
18
18
  key: '<'
19
19
  }, {
20
20
  value: 'lessthanorequal',
21
- label: 'Less Than Or Equal',
21
+ label: 'Less than or equal',
22
22
  key: '<='
23
23
  }, {
24
24
  value: 'notequal',
25
- label: 'Not Equal',
25
+ label: 'Not equal',
26
26
  key: '!='
27
27
  }];
28
28
  export const stringOperator = [{
29
29
  value: 'startswith',
30
30
  key: '_=',
31
- label: 'Starts With'
31
+ label: 'Starts with'
32
32
  }, {
33
33
  value: 'endswith',
34
34
  key: '|=',
35
- label: 'Ends With'
35
+ label: 'Ends with'
36
36
  }, {
37
37
  value: 'contains',
38
38
  key: '~=',
@@ -44,7 +44,7 @@ export const stringOperator = [{
44
44
  }, {
45
45
  value: 'notequal',
46
46
  key: '!=',
47
- label: 'Not Equal'
47
+ label: 'Not equal'
48
48
  }];
49
49
  export const dateOperator = [{
50
50
  value: 'equal',
@@ -53,15 +53,15 @@ export const dateOperator = [{
53
53
  }, {
54
54
  value: 'notequal',
55
55
  key: '!=',
56
- label: 'Not Equal'
56
+ label: 'Not equal'
57
57
  }, {
58
58
  value: 'greaterthan',
59
59
  key: '>',
60
- label: 'Greater Than'
60
+ label: 'Greater than'
61
61
  }, {
62
62
  value: 'lessthan',
63
63
  key: '<',
64
- label: 'Less Than'
64
+ label: 'Less than'
65
65
  }];
66
66
  export const dateTimeOperator = [{
67
67
  value: 'equal',
@@ -70,15 +70,15 @@ export const dateTimeOperator = [{
70
70
  }, {
71
71
  value: 'notequal',
72
72
  key: '!=',
73
- label: 'Not Equal'
73
+ label: 'Not equal'
74
74
  }, {
75
75
  value: 'greaterthan',
76
76
  key: '>',
77
- label: 'Greater Than'
77
+ label: 'Greater than'
78
78
  }, {
79
79
  value: 'lessthan',
80
80
  key: '<',
81
- label: 'Less Than'
81
+ label: 'Less than'
82
82
  }];
83
83
  export const booleanOperator = [{
84
84
  value: 'equal',
@@ -87,7 +87,7 @@ export const booleanOperator = [{
87
87
  }, {
88
88
  value: 'notequal',
89
89
  key: '!=',
90
- label: 'Not Equal'
90
+ label: 'Not equal'
91
91
  }];
92
92
  export const translateOption = (options, t) => {
93
93
  if (!t) {
@@ -1,7 +1,9 @@
1
- import type { ColumnsType, ColumnType, IFormat } from "../../type";
1
+ import type { ColumnType, IFormat } from "../../type";
2
2
  import React from "react";
3
- import { TableLocale } from "rc-master-ui/lib/table/interface";
4
- export declare function flatColumns<RecordType>(columns: ColumnsType<RecordType>, parentKey?: string): ColumnType<RecordType>[];
3
+ import type { TableLocale } from "rc-master-ui/lib/table/interface";
4
+ import type { ColumnsTable } from "../../type";
5
+ export declare function flatColumns<RecordType>(columns: ColumnsTable<RecordType>, parentKey?: string): ColumnsTable<RecordType>;
6
+ export declare function flatColumns2<RecordType>(columns: ColumnsTable<RecordType>, parentKey?: string): ColumnsTable<RecordType>;
5
7
  export declare const getValueCell: <T>(column: ColumnType<T>, value: any, format?: IFormat) => any;
6
8
  export declare const renderContent: <RecordType>(column: ColumnType<RecordType>, value: any, record: RecordType, index: number, format?: IFormat) => React.JSX.Element;
7
9
  export declare const renderFilter: <RecordType>(column: ColumnType<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any) => React.JSX.Element;
@@ -7,7 +7,7 @@ import moment from "moment/moment";
7
7
  import React, { Fragment } from "react";
8
8
  import { DatePicker, Empty, Input, Select } from "rc-master-ui";
9
9
  import CheckboxFilter from "../../CheckboxFilter";
10
- // import {ColorPicker} from "antd";
10
+ import { SELECTION_COLUMN } from "rc-master-ui/es/table/hooks/useSelection";
11
11
  const {
12
12
  RangePicker
13
13
  } = DatePicker;
@@ -34,6 +34,34 @@ export function flatColumns(columns, parentKey = 'key') {
34
34
  }];
35
35
  }, []);
36
36
  }
37
+ export function flatColumns2(columns, parentKey = 'key') {
38
+ // @ts-ignore
39
+ return columns.reduce((list, column, index) => {
40
+ const {
41
+ fixed
42
+ } = column;
43
+ // Convert `fixed='true'` to `fixed='left'` instead
44
+ const parsedFixed = fixed === true ? 'left' : fixed;
45
+ const mergedKey = `${parentKey}-${index}`;
46
+ const subColumns = column.children;
47
+ if (column === SELECTION_COLUMN) {
48
+ return [...list, {
49
+ ...column
50
+ }];
51
+ }
52
+ if (subColumns && subColumns.length > 0) {
53
+ return [...list, ...flatColumns(subColumns, mergedKey).map(subColum => ({
54
+ fixed: parsedFixed,
55
+ ...subColum
56
+ }))];
57
+ }
58
+ return [...list, {
59
+ key: mergedKey,
60
+ ...column,
61
+ fixed: parsedFixed
62
+ }];
63
+ }, []);
64
+ }
37
65
  export const getValueCell = (column, value, format) => {
38
66
  switch (column?.type) {
39
67
  case 'number':
@@ -4,7 +4,7 @@ import type { EditType, IColumnType, TypeFilter } from "rc-master-ui";
4
4
  import type { ColumnEditType, ColumnsType, ColumnTable, GetRowKey } from "../type";
5
5
  import type { SelectionSettings } from "../type";
6
6
  import type { AnyObject } from "../type";
7
- import { Key } from "react";
7
+ import type { Key } from "react";
8
8
  export declare const newGuid: () => any;
9
9
  export declare const sumDataByField: (data: any[], field: string) => any;
10
10
  export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
@@ -24,7 +24,7 @@ export declare const customWeekStartEndFormat: (value: any, weekFormat: string)
24
24
  export declare const getTypeFilter: (col: ColumnTable<any>) => TypeFilter;
25
25
  export declare const updateArrayByKey: (arr: any[], element: any, key: string) => any[];
26
26
  export declare const getDateString: <T>(column: ColumnTable<T>, value: any) => string;
27
- export declare const getEditType: <T>(column: ColumnEditType<T>, rowData?: any) => EditType | ((rowData?: any) => EditType);
27
+ export declare const getEditType: <T>(column: ColumnEditType<T>, rowData?: any) => EditType;
28
28
  export declare const isDisable: <T>(column: ColumnEditType<T>, rowData?: any) => boolean;
29
29
  export declare const checkFieldKey: (key: string | undefined) => string;
30
30
  export declare const convertLabelToTitle: (data: any[]) => any[];
@@ -37,3 +37,7 @@ export declare const updateData: <Record_1 = AnyObject>(initData: Record_1[], ro
37
37
  export declare const parseBooleanToValue: (value: boolean, type: 'boolean' | 'number') => number | boolean;
38
38
  export declare const genPresets: (presets?: import("@ant-design/colors").PalettesProps) => import("antd/es/color-picker/interface").PresetsItem[];
39
39
  export declare function findAllChildrenKeys<RecordType>(data: readonly RecordType[], getRowKey: GetRowKey<RecordType>, childrenColumnName: string): Key[];
40
+ export declare const flattenArray: <RecordType extends AnyObject = AnyObject>(arr: any[]) => RecordType[];
41
+ export declare const flattenData: <RecordType extends AnyObject = AnyObject>(childrenColumnName: keyof RecordType, data?: RecordType[]) => RecordType[];
42
+ export declare const countItemsBeforeIndex: (array: any[], index: number) => number;
43
+ export declare const getRowNumber: (array: any[], rowKey: any, key: any) => number;
@@ -222,7 +222,7 @@ export const getEditType = (column, rowData) => {
222
222
  if (column && typeof column.editType === 'function') {
223
223
  return column.editType(rowData);
224
224
  }
225
- return column.editType;
225
+ return column.editType ?? 'text';
226
226
  };
227
227
  export const isDisable = (column, rowData) => {
228
228
  if (column && typeof column?.disable === 'function') {
@@ -339,4 +339,46 @@ export function findAllChildrenKeys(data, getRowKey, childrenColumnName) {
339
339
  }
340
340
  dig(data);
341
341
  return keys;
342
- }
342
+ }
343
+ export const flattenArray = arr => {
344
+ if (!arr) {
345
+ return [];
346
+ }
347
+ return arr.reduce((r, {
348
+ children,
349
+ ...rest
350
+ }) => {
351
+ r.push(rest);
352
+ if (children) {
353
+ r.push(...flattenArray(children));
354
+ }
355
+ return r;
356
+ }, []);
357
+ };
358
+ export const flattenData = (childrenColumnName, data) => {
359
+ let list = [];
360
+ (data || []).forEach(record => {
361
+ list.push(record);
362
+ if (record && typeof record === 'object' && childrenColumnName in record) {
363
+ list = [...list, ...flattenData(childrenColumnName, record[childrenColumnName])];
364
+ }
365
+ });
366
+ return list;
367
+ };
368
+ export const countItemsBeforeIndex = (array, index) => {
369
+ let count = 0;
370
+ for (let i = 0; i < index; i++) {
371
+ if (array[i].children && array[i].children.length > 0) {
372
+ const rs = flattenData('children', [array[i]]);
373
+ count += rs.length;
374
+ } else {
375
+ count++;
376
+ }
377
+ }
378
+ return count;
379
+ };
380
+ export const getRowNumber = (array, rowKey, key) => {
381
+ // const flattArray = flattenArray(array)
382
+ const flattArray = flattenData('children', array);
383
+ return flattArray.findIndex(it => it[key] === rowKey);
384
+ };