es-grid-template 1.1.7 → 1.1.8

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.
@@ -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([]);
@@ -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,96 @@ 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
+ children: transformColumns(column.children)
305
309
  };
306
310
  }
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
311
  });
326
- }, [getColumnSearchProps]);
312
+ }, [convertColumns]);
327
313
  const mergedColumns = React.useMemo(() => {
328
314
  return transformColumns(columns);
329
315
  }, [transformColumns, columns]);
330
-
331
- // console.log('mergedColumns', mergedColumns)
332
-
333
316
  const triggerChangeColumns = newColumns => {
334
317
  setColumns(newColumns);
335
318
  };
@@ -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,
@@ -328,7 +329,7 @@ const TableGrid = props => {
328
329
  virtual: virtual,
329
330
  columns: columns,
330
331
  rowKey: rowKey,
331
- rowHoverable: true,
332
+ rowHoverable: rowHoverable,
332
333
  size: "small",
333
334
  scroll: scroll ? scroll : {
334
335
  y: 500
@@ -350,7 +351,9 @@ const TableGrid = props => {
350
351
  selectedRowKeys: mergedSelectedKeys,
351
352
  defaultSelectedRowKeys: selectionSettings?.defaultSelectedRowKeys,
352
353
  preserveSelectedRowKeys: true,
353
- ...rowSelection,
354
+ // ...rowSelection,
355
+ // checkStrictly: false,
356
+
354
357
  hideSelectAll: !type || type === 'single' || selectionSettings?.mode === 'radio' ? true : hideSelectAll ?? type !== 'multiple'
355
358
  },
356
359
  onScroll: () => {
@@ -445,7 +448,7 @@ const TableGrid = props => {
445
448
  } = args;
446
449
 
447
450
  // @ts-ignore
448
- if (record?.children && record?.children?.length > 0 || record?.isChildren) {
451
+ if (record?.children?.length > 0 || record?.isChildren) {
449
452
  return expanded ? /*#__PURE__*/React.createElement("button", {
450
453
  onClick: e => {
451
454
  e.preventDefault();
@@ -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':
@@ -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[];
@@ -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') {