es-grid-template 1.1.8 → 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.
- package/es/grid-component/ColumnsChoose.js +1 -1
- package/es/grid-component/GridStyle.js +1 -1
- package/es/grid-component/InternalTable.js +5 -1
- package/es/grid-component/TableGrid.d.ts +4 -2
- package/es/grid-component/TableGrid.js +11 -4
- package/es/grid-component/hooks/utils.d.ts +5 -1
- package/es/grid-component/hooks/utils.js +43 -1
- package/es/grid-component/styles.scss +55 -4
- package/es/grid-component/table/Grid.d.ts +3 -0
- package/es/grid-component/table/Grid.js +0 -2
- package/es/grid-component/table/GridEdit.js +109 -14
- package/es/grid-component/type.d.ts +5 -1
- package/lib/grid-component/ColumnsChoose.js +1 -1
- package/lib/grid-component/GridStyle.js +1 -1
- package/lib/grid-component/InternalTable.js +5 -1
- package/lib/grid-component/TableGrid.d.ts +4 -2
- package/lib/grid-component/TableGrid.js +11 -4
- package/lib/grid-component/hooks/utils.d.ts +5 -1
- package/lib/grid-component/hooks/utils.js +50 -4
- package/lib/grid-component/styles.scss +55 -4
- package/lib/grid-component/table/Grid.d.ts +3 -0
- package/lib/grid-component/table/Grid.js +0 -2
- package/lib/grid-component/table/GridEdit.js +105 -11
- package/lib/grid-component/type.d.ts +5 -1
- package/package.json +1 -1
|
@@ -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` :
|
|
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');
|
|
@@ -87,7 +87,7 @@ const InternalTable = props => {
|
|
|
87
87
|
// const [expandKeys, setExpandKeys] = useState<string[]>([]);
|
|
88
88
|
const [dataSourceFilter, setDataSourceFilter] = useState(propDataSourceFilter ?? []);
|
|
89
89
|
useEffect(() => {
|
|
90
|
-
const rs = propsColumns ? [Table.SELECTION_COLUMN, ...propsColumns] : [];
|
|
90
|
+
const rs = propsColumns && propsColumns.length > 0 ? [Table.SELECTION_COLUMN, ...propsColumns] : [];
|
|
91
91
|
// const rs = propsColumns ? [...propsColumns] : []
|
|
92
92
|
setColumns(rs);
|
|
93
93
|
}, [propsColumns]);
|
|
@@ -305,6 +305,10 @@ const InternalTable = props => {
|
|
|
305
305
|
if (column.children?.length) {
|
|
306
306
|
return {
|
|
307
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,
|
|
308
312
|
children: transformColumns(column.children)
|
|
309
313
|
};
|
|
310
314
|
}
|
|
@@ -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;
|
|
@@ -119,6 +119,7 @@ const TableGrid = props => {
|
|
|
119
119
|
summary,
|
|
120
120
|
showToolbar,
|
|
121
121
|
onSorter,
|
|
122
|
+
bottomToolbar,
|
|
122
123
|
...rest
|
|
123
124
|
} = props;
|
|
124
125
|
const {
|
|
@@ -317,6 +318,7 @@ const TableGrid = props => {
|
|
|
317
318
|
},
|
|
318
319
|
loading: {
|
|
319
320
|
spinning: columns && columns.length === 0 || loading === true,
|
|
321
|
+
// spinning: loading === true,
|
|
320
322
|
indicator: /*#__PURE__*/React.createElement(ComponentSpinner, null)
|
|
321
323
|
},
|
|
322
324
|
dataSource: dataSource
|
|
@@ -342,7 +344,7 @@ const TableGrid = props => {
|
|
|
342
344
|
onContextMenu: onContextMenu(data)
|
|
343
345
|
};
|
|
344
346
|
},
|
|
345
|
-
rowSelection: {
|
|
347
|
+
rowSelection: columns && columns.length === 0 ? undefined : {
|
|
346
348
|
...selectionSettings,
|
|
347
349
|
type: selectionSettings?.mode === 'checkbox' || type === 'multiple' ? 'checkbox' : "radio",
|
|
348
350
|
columnWidth: !mode ? 0.0000001 : columnWidth ?? 50,
|
|
@@ -411,9 +413,9 @@ const TableGrid = props => {
|
|
|
411
413
|
// @ts-ignore
|
|
412
414
|
, {
|
|
413
415
|
style: {
|
|
414
|
-
width: `calc(100% - 650px`
|
|
416
|
+
width: pagination && pagination.onChange && pagination?.position && pagination?.position[0] === 'topRight' ? `calc(100% - 650px` : `calc(100% - 25px`
|
|
415
417
|
},
|
|
416
|
-
items: toolbarItems ?? [],
|
|
418
|
+
items: (toolbarItems ?? []).filter(it => it.position !== 'Bottom'),
|
|
417
419
|
mode: 'scroll'
|
|
418
420
|
}), /*#__PURE__*/React.createElement("div", {
|
|
419
421
|
style: {
|
|
@@ -464,12 +466,17 @@ const TableGrid = props => {
|
|
|
464
466
|
},
|
|
465
467
|
className: 'ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed'
|
|
466
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
|
+
});
|
|
467
473
|
}
|
|
468
474
|
}
|
|
469
475
|
}
|
|
470
|
-
})), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/React.createElement(Pagination
|
|
476
|
+
})), bottomToolbar?.(), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/React.createElement(Pagination
|
|
471
477
|
// style={{padding: '0.75rem 1rem'}}
|
|
472
478
|
, _extends({
|
|
479
|
+
rootClassName: 'pagination-template',
|
|
473
480
|
showSizeChanger: true,
|
|
474
481
|
responsive: true,
|
|
475
482
|
size: 'small',
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -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
|
+
};
|
|
@@ -102,13 +102,19 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
102
102
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
|
|
106
|
+
@for $i from 0 through 10 {
|
|
107
|
+
&:has(.indent-level-#{$i}) {
|
|
108
|
+
.ui-rc-table-cell {
|
|
109
|
+
&.cell-number {
|
|
110
|
+
.ui-rc_content {
|
|
111
|
+
padding-left: $i * 10px;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
116
|
}
|
|
117
|
+
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
.ui-rc-table-placeholder {
|
|
@@ -306,6 +312,7 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
306
312
|
}
|
|
307
313
|
|
|
308
314
|
.#{$prefix}-table-tbody {
|
|
315
|
+
|
|
309
316
|
.#{$prefix}-table-row {
|
|
310
317
|
&.#{$prefix}-table-row-selected {
|
|
311
318
|
>.#{$prefix}-table-cell {
|
|
@@ -317,6 +324,50 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
317
324
|
background: #FBDED6;
|
|
318
325
|
}
|
|
319
326
|
}
|
|
327
|
+
|
|
328
|
+
.ui-rc-table-cell {
|
|
329
|
+
|
|
330
|
+
.ui-rc-table-row-indent {
|
|
331
|
+
position: absolute;
|
|
332
|
+
@for $i from 1 through 10 {
|
|
333
|
+
&.indent-level-#{$i} {
|
|
334
|
+
padding-left: $i * 25px;;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
@for $i from 0 through 10 {
|
|
340
|
+
&:has(.indent-level-#{$i}) {
|
|
341
|
+
|
|
342
|
+
.ui-rc-table-row-expand-icon {
|
|
343
|
+
position: absolute;
|
|
344
|
+
//.ui-rc_content {
|
|
345
|
+
padding-left: $i * 10px;
|
|
346
|
+
//}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.ui-rc_cell-content {
|
|
350
|
+
padding-left: $i * 25px + 8px;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
@for $i from 0 through 10 {
|
|
357
|
+
&:has(.indent-level-#{$i}) {
|
|
358
|
+
|
|
359
|
+
.ui-rc-table-row-expand-icon {
|
|
360
|
+
position: absolute;
|
|
361
|
+
left: $i * 25px + 8px !important;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.ui-rc_cell-content {
|
|
365
|
+
padding-left: ($i + 1)* 25px + 8px;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
320
371
|
}
|
|
321
372
|
|
|
322
373
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ColumnsTable, GridTableProps } from "../type";
|
|
3
|
+
import type { GetRowKey } from "../type";
|
|
3
4
|
type Props<T> = GridTableProps<T> & {
|
|
4
5
|
tableRef: any;
|
|
5
6
|
triggerChangeColumns?: (columns: ColumnsTable<T>, type: string) => void;
|
|
7
|
+
triggerChangeData?: (newData: T[], type: string) => void;
|
|
8
|
+
getRowKey: GetRowKey<T>;
|
|
6
9
|
};
|
|
7
10
|
declare const Grid: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
8
11
|
export default Grid;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import React, { Fragment, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import React, { Fragment, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
4
|
import classNames from "classnames";
|
|
5
|
-
import { Form } from "antd";
|
|
5
|
+
import { Button, Dropdown, Form } from "antd";
|
|
6
6
|
import { useForm } from 'react-hook-form';
|
|
7
7
|
import { Toaster } from "react-hot-toast";
|
|
8
8
|
import { flatColumns, renderContent } from "../hooks/useColumns";
|
|
@@ -13,11 +13,13 @@ import dayjs from "dayjs";
|
|
|
13
13
|
import 'dayjs/locale/es';
|
|
14
14
|
import 'dayjs/locale/vi';
|
|
15
15
|
import TableGrid from "../TableGrid";
|
|
16
|
-
import { getEditType, isObjEmpty, totalFixedWidth } from "../hooks";
|
|
16
|
+
import { getEditType, getRowNumber, isObjEmpty, totalFixedWidth } from "../hooks";
|
|
17
17
|
import Message from "../../Message/Message";
|
|
18
18
|
|
|
19
19
|
// import Command from "../Command";
|
|
20
20
|
|
|
21
|
+
import { Toolbar } from "rc-master-ui";
|
|
22
|
+
import classnames from "classnames";
|
|
21
23
|
dayjs.extend(customParseFormat);
|
|
22
24
|
const toast = 'top-right';
|
|
23
25
|
const GridEdit = props => {
|
|
@@ -39,6 +41,7 @@ const GridEdit = props => {
|
|
|
39
41
|
style,
|
|
40
42
|
getRowKey,
|
|
41
43
|
className,
|
|
44
|
+
toolbarItems,
|
|
42
45
|
...rest
|
|
43
46
|
} = props;
|
|
44
47
|
|
|
@@ -49,11 +52,78 @@ const GridEdit = props => {
|
|
|
49
52
|
const startCell = useRef(null);
|
|
50
53
|
const isSelectingRow = useRef(false);
|
|
51
54
|
const rowStart = useRef(null);
|
|
55
|
+
const itemsAdd = [{
|
|
56
|
+
key: '10',
|
|
57
|
+
label: '10 rows'
|
|
58
|
+
}, {
|
|
59
|
+
key: '50',
|
|
60
|
+
label: '50 rows'
|
|
61
|
+
}, {
|
|
62
|
+
key: '100',
|
|
63
|
+
label: '100 rows'
|
|
64
|
+
}];
|
|
52
65
|
const [form] = Form.useForm();
|
|
53
66
|
const [editingKey, setEditingKey] = useState('');
|
|
54
67
|
const [selectedCells, setSelectedCells] = useState(new Set());
|
|
55
68
|
const [rowsSelected, setRowsSelected] = useState(new Set());
|
|
56
69
|
const [selectedCell, setSelectedCell] = useState(null);
|
|
70
|
+
const handleAdd = item => {
|
|
71
|
+
console.log(item);
|
|
72
|
+
if (item.onClick) {
|
|
73
|
+
console.log('cccccccccccccccc');
|
|
74
|
+
} else {
|
|
75
|
+
console.log('bbbbbbbbbbbbb');
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const handleDuplicate = () => {};
|
|
79
|
+
const handleInsertBefore = () => {};
|
|
80
|
+
const handleInsertAfter = () => {};
|
|
81
|
+
const handleDeleteAll = () => {};
|
|
82
|
+
const toolbarItemsBottom = useMemo(() => {
|
|
83
|
+
return toolbarItems?.filter(it => it.position === 'Bottom').map(item => {
|
|
84
|
+
return {
|
|
85
|
+
...item,
|
|
86
|
+
template: () => {
|
|
87
|
+
return /*#__PURE__*/React.createElement(Fragment, null, item.key === 'ADD' && /*#__PURE__*/React.createElement("div", {
|
|
88
|
+
className: classnames(`be-toolbar-item ${item.className}`)
|
|
89
|
+
}, /*#__PURE__*/React.createElement(Dropdown.Button, {
|
|
90
|
+
menu: {
|
|
91
|
+
items: itemsAdd,
|
|
92
|
+
onClick: () => handleAdd(item)
|
|
93
|
+
}
|
|
94
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Add item') : 'Add item')), item.key === 'DUPLICATE' && item.visible !== false && editingKey && /*#__PURE__*/React.createElement("div", {
|
|
95
|
+
className: classnames(`be-toolbar-item ${item.className}`)
|
|
96
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
97
|
+
color: "green",
|
|
98
|
+
variant: 'outlined',
|
|
99
|
+
onClick: handleDuplicate,
|
|
100
|
+
className: "d-flex be-button"
|
|
101
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Duplicate') : 'Duplicate')), item.key === 'INSERT_BEFORE' && item.visible !== false && editingKey && /*#__PURE__*/React.createElement("div", {
|
|
102
|
+
className: classnames(`be-toolbar-item ${item.className}`)
|
|
103
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
104
|
+
color: "green",
|
|
105
|
+
variant: 'outlined',
|
|
106
|
+
onClick: handleInsertBefore,
|
|
107
|
+
className: "d-flex be-button"
|
|
108
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Insert item before') : 'Insert item before')), item.key === 'INSERT_AFTER' && item.visible !== false && editingKey && /*#__PURE__*/React.createElement("div", {
|
|
109
|
+
className: classnames(`be-toolbar-item ${item.className}`)
|
|
110
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
111
|
+
color: "green",
|
|
112
|
+
variant: 'outlined',
|
|
113
|
+
onClick: handleInsertAfter,
|
|
114
|
+
className: "d-flex be-button"
|
|
115
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Insert item after') : 'Insert item after')), item.key === 'DELETE' && item.visible !== false && /*#__PURE__*/React.createElement("div", {
|
|
116
|
+
className: classnames(`be-toolbar-item ${item.className}`)
|
|
117
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
118
|
+
color: "primary",
|
|
119
|
+
variant: 'outlined',
|
|
120
|
+
onClick: handleDeleteAll,
|
|
121
|
+
className: "d-flex be-button"
|
|
122
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Delete all item') : 'Delete all item')));
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}, [toolbarItems]);
|
|
57
127
|
const {
|
|
58
128
|
control,
|
|
59
129
|
handleSubmit,
|
|
@@ -85,9 +155,10 @@ const GridEdit = props => {
|
|
|
85
155
|
|
|
86
156
|
if (!tableBody.contains(event.target)) {
|
|
87
157
|
setEditingKey('');
|
|
88
|
-
|
|
89
|
-
|
|
158
|
+
isSelecting.current = false;
|
|
159
|
+
startCell.current = null;
|
|
90
160
|
setSelectedCells(new Set());
|
|
161
|
+
setRowsSelected(new Set());
|
|
91
162
|
} else {}
|
|
92
163
|
}
|
|
93
164
|
};
|
|
@@ -585,20 +656,26 @@ const GridEdit = props => {
|
|
|
585
656
|
...column,
|
|
586
657
|
className: 'rc-ui-cell-editable',
|
|
587
658
|
render: (value, record, rowIndex) => {
|
|
659
|
+
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
588
660
|
return /*#__PURE__*/React.createElement("div", {
|
|
589
661
|
className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {
|
|
590
|
-
selected: rowsSelected.has(`${
|
|
591
|
-
focus: selectedCells && Array.from(selectedCells).some(item => item.startsWith(`${
|
|
662
|
+
selected: rowsSelected.has(`${rowNumber}-${colIndex}`),
|
|
663
|
+
focus: selectedCells && Array.from(selectedCells).some(item => item.startsWith(`${rowNumber}-`))
|
|
592
664
|
}),
|
|
593
|
-
onMouseDown: event => handleMouseDownColIndex(
|
|
594
|
-
onMouseEnter: event => handleMouseEnterColIndex(
|
|
595
|
-
onClick: () => handleClickRowHeader(
|
|
665
|
+
onMouseDown: event => handleMouseDownColIndex(rowNumber, colIndex, event),
|
|
666
|
+
onMouseEnter: event => handleMouseEnterColIndex(rowNumber, colIndex, event),
|
|
667
|
+
onClick: () => handleClickRowHeader(rowNumber, colIndex)
|
|
596
668
|
}, /*#__PURE__*/React.createElement("div", {
|
|
597
669
|
className: 'ui-rc_content'
|
|
598
670
|
}, rowIndex + 1));
|
|
599
671
|
}
|
|
600
672
|
};
|
|
601
673
|
}
|
|
674
|
+
if ((column.key || column.field) === 'command') {
|
|
675
|
+
return {
|
|
676
|
+
...column
|
|
677
|
+
};
|
|
678
|
+
}
|
|
602
679
|
return {
|
|
603
680
|
...column,
|
|
604
681
|
// editType: getEditType(column, record),
|
|
@@ -679,12 +756,16 @@ const GridEdit = props => {
|
|
|
679
756
|
tabIndex: (rowIndex ?? 0) * columns.length + colIndex
|
|
680
757
|
}),
|
|
681
758
|
render: (value, record, rowIndex) => {
|
|
759
|
+
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
682
760
|
return /*#__PURE__*/React.createElement("div", {
|
|
683
761
|
className: classNames('ui-rc_cell-content', {
|
|
684
|
-
selected: selectedCells.has(`${
|
|
762
|
+
// selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
|
|
763
|
+
selected: selectedCells.has(`${rowNumber}-${colIndex}`)
|
|
685
764
|
}),
|
|
686
|
-
onMouseDown: event => handleMouseDown(
|
|
687
|
-
onMouseEnter
|
|
765
|
+
onMouseDown: event => handleMouseDown(rowNumber, colIndex, event)
|
|
766
|
+
// onMouseEnter={() => handleMouseEnter(record[rowKey], colIndex)}
|
|
767
|
+
,
|
|
768
|
+
onMouseEnter: () => handleMouseEnter(rowNumber, colIndex)
|
|
688
769
|
}, /*#__PURE__*/React.createElement("div", {
|
|
689
770
|
className: 'ui-rc_content'
|
|
690
771
|
}, renderContent(column, value, record, rowIndex, format)));
|
|
@@ -714,6 +795,18 @@ const GridEdit = props => {
|
|
|
714
795
|
});
|
|
715
796
|
}, [convertColumns]);
|
|
716
797
|
const mergedColumns = React.useMemo(() => transformColumns(columns ?? []), [transformColumns, columns]);
|
|
798
|
+
const bottomToolbar = () => {
|
|
799
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Toolbar, {
|
|
800
|
+
style: {
|
|
801
|
+
width: '100%'
|
|
802
|
+
},
|
|
803
|
+
items: toolbarItemsBottom ?? [],
|
|
804
|
+
mode: 'scroll'
|
|
805
|
+
// onClick={({ item }) => {
|
|
806
|
+
// console.log('item', item)
|
|
807
|
+
// }}
|
|
808
|
+
}));
|
|
809
|
+
};
|
|
717
810
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
|
|
718
811
|
heightTable: height,
|
|
719
812
|
style: {
|
|
@@ -750,6 +843,7 @@ const GridEdit = props => {
|
|
|
750
843
|
target: 'sorter-icon'
|
|
751
844
|
},
|
|
752
845
|
format: format,
|
|
846
|
+
toolbarItems: toolbarItems,
|
|
753
847
|
selectionSettings: selectionSettings ? {
|
|
754
848
|
...selectionSettings,
|
|
755
849
|
checkboxOnly: true
|
|
@@ -758,7 +852,8 @@ const GridEdit = props => {
|
|
|
758
852
|
...style,
|
|
759
853
|
minHeight: height
|
|
760
854
|
},
|
|
761
|
-
rowHoverable: false
|
|
855
|
+
rowHoverable: false,
|
|
856
|
+
bottomToolbar: bottomToolbar
|
|
762
857
|
}))))), /*#__PURE__*/React.createElement(Toaster, {
|
|
763
858
|
position: toast,
|
|
764
859
|
toastOptions: {
|
|
@@ -3,12 +3,16 @@ import type React from "react";
|
|
|
3
3
|
import type { IOperator } from "./hooks";
|
|
4
4
|
import type { TypeFilter, TableProps as RcTableProps, TableColumnType as RcColumnType, EditType } from "rc-master-ui";
|
|
5
5
|
import type { FilterOperator, TableRowSelection } from "rc-master-ui/es/table/interface";
|
|
6
|
-
import type { ToolbarItem } from "rc-master-ui/es/toolbar";
|
|
6
|
+
import type { ToolbarItem as RcToolbarItem } from "rc-master-ui/es/toolbar";
|
|
7
7
|
import type { ItemType } from "rc-master-ui/es/menu/interface";
|
|
8
8
|
import type { FieldNames, FilterFunc } from "rc-select/es/Select";
|
|
9
9
|
import type { ColorPickerProps } from "antd";
|
|
10
10
|
export type IColumnType = "number" | "time" | "date" | "week" | "month" | "file" | "quarter" | "year" | "datetime" | "string" | "boolean" | "checkbox" | "color" | null | undefined;
|
|
11
11
|
export type AnyObject = Record<PropertyKey, any>;
|
|
12
|
+
export type ToolbarItem = Omit<RcToolbarItem, 'position'> & {
|
|
13
|
+
position?: 'Top' | 'Bottom';
|
|
14
|
+
onClick?: (args: any) => void;
|
|
15
|
+
};
|
|
12
16
|
export type SelectMode = 'checkbox' | 'radio' | undefined;
|
|
13
17
|
export type ITextAlign = 'center' | 'left' | 'right';
|
|
14
18
|
export type Frozen = 'left' | 'right' | 'Left' | 'Right';
|
|
@@ -163,7 +163,7 @@ const ColumnsChoose = props => {
|
|
|
163
163
|
style: {
|
|
164
164
|
marginBottom: 8
|
|
165
165
|
},
|
|
166
|
-
placeholder: "Search",
|
|
166
|
+
placeholder: t ? t("Search") : 'Search',
|
|
167
167
|
prefix: /*#__PURE__*/_react.default.createElement(_SearchOutlined.default, null),
|
|
168
168
|
onChange: onChange
|
|
169
169
|
}), /*#__PURE__*/_react.default.createElement(_tree.default, {
|
|
@@ -9,4 +9,4 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
|
9
9
|
const GridStyle = exports.GridStyle = _styledComponents.default.div.withConfig({
|
|
10
10
|
displayName: "GridStyle",
|
|
11
11
|
componentId: "es-grid-template__sc-sueu2e-0"
|
|
12
|
-
})([".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` :
|
|
12
|
+
})([".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');
|
|
@@ -96,7 +96,7 @@ const InternalTable = props => {
|
|
|
96
96
|
// const [expandKeys, setExpandKeys] = useState<string[]>([]);
|
|
97
97
|
const [dataSourceFilter, setDataSourceFilter] = (0, _react.useState)(propDataSourceFilter ?? []);
|
|
98
98
|
(0, _react.useEffect)(() => {
|
|
99
|
-
const rs = propsColumns ? [_rcMasterUi.Table.SELECTION_COLUMN, ...propsColumns] : [];
|
|
99
|
+
const rs = propsColumns && propsColumns.length > 0 ? [_rcMasterUi.Table.SELECTION_COLUMN, ...propsColumns] : [];
|
|
100
100
|
// const rs = propsColumns ? [...propsColumns] : []
|
|
101
101
|
setColumns(rs);
|
|
102
102
|
}, [propsColumns]);
|
|
@@ -314,6 +314,10 @@ const InternalTable = props => {
|
|
|
314
314
|
if (column.children?.length) {
|
|
315
315
|
return {
|
|
316
316
|
...column,
|
|
317
|
+
key: column.field ?? column.dataIndex ?? column.key,
|
|
318
|
+
title: t ? t(column.headerText ?? column.title) : column.headerText ?? column.title,
|
|
319
|
+
ellipsis: column.ellipsis !== false,
|
|
320
|
+
align: column.textAlign ?? column.align,
|
|
317
321
|
children: transformColumns(column.children)
|
|
318
322
|
};
|
|
319
323
|
}
|
|
@@ -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;
|
|
@@ -126,6 +126,7 @@ const TableGrid = props => {
|
|
|
126
126
|
summary,
|
|
127
127
|
showToolbar,
|
|
128
128
|
onSorter,
|
|
129
|
+
bottomToolbar,
|
|
129
130
|
...rest
|
|
130
131
|
} = props;
|
|
131
132
|
const {
|
|
@@ -324,6 +325,7 @@ const TableGrid = props => {
|
|
|
324
325
|
},
|
|
325
326
|
loading: {
|
|
326
327
|
spinning: columns && columns.length === 0 || loading === true,
|
|
328
|
+
// spinning: loading === true,
|
|
327
329
|
indicator: /*#__PURE__*/_react.default.createElement(_LoadingSpinner.default, null)
|
|
328
330
|
},
|
|
329
331
|
dataSource: dataSource
|
|
@@ -349,7 +351,7 @@ const TableGrid = props => {
|
|
|
349
351
|
onContextMenu: onContextMenu(data)
|
|
350
352
|
};
|
|
351
353
|
},
|
|
352
|
-
rowSelection: {
|
|
354
|
+
rowSelection: columns && columns.length === 0 ? undefined : {
|
|
353
355
|
...selectionSettings,
|
|
354
356
|
type: selectionSettings?.mode === 'checkbox' || type === 'multiple' ? 'checkbox' : "radio",
|
|
355
357
|
columnWidth: !mode ? 0.0000001 : columnWidth ?? 50,
|
|
@@ -418,9 +420,9 @@ const TableGrid = props => {
|
|
|
418
420
|
// @ts-ignore
|
|
419
421
|
, {
|
|
420
422
|
style: {
|
|
421
|
-
width: `calc(100% - 650px`
|
|
423
|
+
width: pagination && pagination.onChange && pagination?.position && pagination?.position[0] === 'topRight' ? `calc(100% - 650px` : `calc(100% - 25px`
|
|
422
424
|
},
|
|
423
|
-
items: toolbarItems ?? [],
|
|
425
|
+
items: (toolbarItems ?? []).filter(it => it.position !== 'Bottom'),
|
|
424
426
|
mode: 'scroll'
|
|
425
427
|
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
426
428
|
style: {
|
|
@@ -471,12 +473,17 @@ const TableGrid = props => {
|
|
|
471
473
|
},
|
|
472
474
|
className: 'ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed'
|
|
473
475
|
});
|
|
476
|
+
} else {
|
|
477
|
+
return /*#__PURE__*/_react.default.createElement("button", {
|
|
478
|
+
className: 'ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced'
|
|
479
|
+
});
|
|
474
480
|
}
|
|
475
481
|
}
|
|
476
482
|
}
|
|
477
|
-
})), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/_react.default.createElement(_pagination.default
|
|
483
|
+
})), bottomToolbar?.(), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/_react.default.createElement(_pagination.default
|
|
478
484
|
// style={{padding: '0.75rem 1rem'}}
|
|
479
485
|
, (0, _extends2.default)({
|
|
486
|
+
rootClassName: 'pagination-template',
|
|
480
487
|
showSizeChanger: true,
|
|
481
488
|
responsive: true,
|
|
482
489
|
size: 'small',
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -4,11 +4,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.customWeekStartEndFormat = exports.convertLabelToTitle = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertArrayWithIndent = exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = void 0;
|
|
7
|
+
exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.convertLabelToTitle = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertArrayWithIndent = exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = void 0;
|
|
8
8
|
exports.findAllChildrenKeys = findAllChildrenKeys;
|
|
9
|
-
exports.getEditType = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = void 0;
|
|
9
|
+
exports.getEditType = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = void 0;
|
|
10
10
|
exports.getHiddenParentKeys = getHiddenParentKeys;
|
|
11
|
-
exports.updateData = exports.updateColumns = exports.updateArrayByKey = exports.totalFixedWidth = exports.sumDataByField = exports.parseBooleanToValue = exports.newGuid = exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isEmpty = exports.isDisable = exports.isColor = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTemplate = void 0;
|
|
11
|
+
exports.updateData = exports.updateColumns = exports.updateArrayByKey = exports.totalFixedWidth = exports.sumDataByField = exports.parseBooleanToValue = exports.newGuid = exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isEmpty = exports.isDisable = exports.isColor = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTemplate = exports.getRowNumber = void 0;
|
|
12
12
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
13
13
|
var _moment = _interopRequireDefault(require("moment/moment"));
|
|
14
14
|
var _uuid = require("uuid");
|
|
@@ -380,4 +380,50 @@ function findAllChildrenKeys(data, getRowKey, childrenColumnName) {
|
|
|
380
380
|
}
|
|
381
381
|
dig(data);
|
|
382
382
|
return keys;
|
|
383
|
-
}
|
|
383
|
+
}
|
|
384
|
+
const flattenArray = arr => {
|
|
385
|
+
if (!arr) {
|
|
386
|
+
return [];
|
|
387
|
+
}
|
|
388
|
+
return arr.reduce((r, {
|
|
389
|
+
children,
|
|
390
|
+
...rest
|
|
391
|
+
}) => {
|
|
392
|
+
r.push(rest);
|
|
393
|
+
if (children) {
|
|
394
|
+
r.push(...flattenArray(children));
|
|
395
|
+
}
|
|
396
|
+
return r;
|
|
397
|
+
}, []);
|
|
398
|
+
};
|
|
399
|
+
exports.flattenArray = flattenArray;
|
|
400
|
+
const flattenData = (childrenColumnName, data) => {
|
|
401
|
+
let list = [];
|
|
402
|
+
(data || []).forEach(record => {
|
|
403
|
+
list.push(record);
|
|
404
|
+
if (record && typeof record === 'object' && childrenColumnName in record) {
|
|
405
|
+
list = [...list, ...flattenData(childrenColumnName, record[childrenColumnName])];
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
return list;
|
|
409
|
+
};
|
|
410
|
+
exports.flattenData = flattenData;
|
|
411
|
+
const countItemsBeforeIndex = (array, index) => {
|
|
412
|
+
let count = 0;
|
|
413
|
+
for (let i = 0; i < index; i++) {
|
|
414
|
+
if (array[i].children && array[i].children.length > 0) {
|
|
415
|
+
const rs = flattenData('children', [array[i]]);
|
|
416
|
+
count += rs.length;
|
|
417
|
+
} else {
|
|
418
|
+
count++;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return count;
|
|
422
|
+
};
|
|
423
|
+
exports.countItemsBeforeIndex = countItemsBeforeIndex;
|
|
424
|
+
const getRowNumber = (array, rowKey, key) => {
|
|
425
|
+
// const flattArray = flattenArray(array)
|
|
426
|
+
const flattArray = flattenData('children', array);
|
|
427
|
+
return flattArray.findIndex(it => it[key] === rowKey);
|
|
428
|
+
};
|
|
429
|
+
exports.getRowNumber = getRowNumber;
|
|
@@ -102,13 +102,19 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
102
102
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
|
|
106
|
+
@for $i from 0 through 10 {
|
|
107
|
+
&:has(.indent-level-#{$i}) {
|
|
108
|
+
.ui-rc-table-cell {
|
|
109
|
+
&.cell-number {
|
|
110
|
+
.ui-rc_content {
|
|
111
|
+
padding-left: $i * 10px;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
116
|
}
|
|
117
|
+
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
.ui-rc-table-placeholder {
|
|
@@ -306,6 +312,7 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
306
312
|
}
|
|
307
313
|
|
|
308
314
|
.#{$prefix}-table-tbody {
|
|
315
|
+
|
|
309
316
|
.#{$prefix}-table-row {
|
|
310
317
|
&.#{$prefix}-table-row-selected {
|
|
311
318
|
>.#{$prefix}-table-cell {
|
|
@@ -317,6 +324,50 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
317
324
|
background: #FBDED6;
|
|
318
325
|
}
|
|
319
326
|
}
|
|
327
|
+
|
|
328
|
+
.ui-rc-table-cell {
|
|
329
|
+
|
|
330
|
+
.ui-rc-table-row-indent {
|
|
331
|
+
position: absolute;
|
|
332
|
+
@for $i from 1 through 10 {
|
|
333
|
+
&.indent-level-#{$i} {
|
|
334
|
+
padding-left: $i * 25px;;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
@for $i from 0 through 10 {
|
|
340
|
+
&:has(.indent-level-#{$i}) {
|
|
341
|
+
|
|
342
|
+
.ui-rc-table-row-expand-icon {
|
|
343
|
+
position: absolute;
|
|
344
|
+
//.ui-rc_content {
|
|
345
|
+
padding-left: $i * 10px;
|
|
346
|
+
//}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.ui-rc_cell-content {
|
|
350
|
+
padding-left: $i * 25px + 8px;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
@for $i from 0 through 10 {
|
|
357
|
+
&:has(.indent-level-#{$i}) {
|
|
358
|
+
|
|
359
|
+
.ui-rc-table-row-expand-icon {
|
|
360
|
+
position: absolute;
|
|
361
|
+
left: $i * 25px + 8px !important;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.ui-rc_cell-content {
|
|
365
|
+
padding-left: ($i + 1)* 25px + 8px;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
320
371
|
}
|
|
321
372
|
|
|
322
373
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ColumnsTable, GridTableProps } from "../type";
|
|
3
|
+
import type { GetRowKey } from "../type";
|
|
3
4
|
type Props<T> = GridTableProps<T> & {
|
|
4
5
|
tableRef: any;
|
|
5
6
|
triggerChangeColumns?: (columns: ColumnsTable<T>, type: string) => void;
|
|
7
|
+
triggerChangeData?: (newData: T[], type: string) => void;
|
|
8
|
+
getRowKey: GetRowKey<T>;
|
|
6
9
|
};
|
|
7
10
|
declare const Grid: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
8
11
|
export default Grid;
|
|
@@ -13,8 +13,6 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
13
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
14
|
// import type {ColumnsTable} from "../type";
|
|
15
15
|
|
|
16
|
-
// import {renderContent} from "../hooks/useColumns";
|
|
17
|
-
|
|
18
16
|
const Grid = props => {
|
|
19
17
|
const {
|
|
20
18
|
height,
|
|
@@ -22,6 +22,7 @@ require("dayjs/locale/vi");
|
|
|
22
22
|
var _TableGrid = _interopRequireDefault(require("../TableGrid"));
|
|
23
23
|
var _hooks = require("../hooks");
|
|
24
24
|
var _Message = _interopRequireDefault(require("../../Message/Message"));
|
|
25
|
+
var _rcMasterUi = require("rc-master-ui");
|
|
25
26
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
26
27
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
27
28
|
// import Command from "../Command";
|
|
@@ -47,6 +48,7 @@ const GridEdit = props => {
|
|
|
47
48
|
style,
|
|
48
49
|
getRowKey,
|
|
49
50
|
className,
|
|
51
|
+
toolbarItems,
|
|
50
52
|
...rest
|
|
51
53
|
} = props;
|
|
52
54
|
|
|
@@ -57,11 +59,78 @@ const GridEdit = props => {
|
|
|
57
59
|
const startCell = (0, _react.useRef)(null);
|
|
58
60
|
const isSelectingRow = (0, _react.useRef)(false);
|
|
59
61
|
const rowStart = (0, _react.useRef)(null);
|
|
62
|
+
const itemsAdd = [{
|
|
63
|
+
key: '10',
|
|
64
|
+
label: '10 rows'
|
|
65
|
+
}, {
|
|
66
|
+
key: '50',
|
|
67
|
+
label: '50 rows'
|
|
68
|
+
}, {
|
|
69
|
+
key: '100',
|
|
70
|
+
label: '100 rows'
|
|
71
|
+
}];
|
|
60
72
|
const [form] = _antd.Form.useForm();
|
|
61
73
|
const [editingKey, setEditingKey] = (0, _react.useState)('');
|
|
62
74
|
const [selectedCells, setSelectedCells] = (0, _react.useState)(new Set());
|
|
63
75
|
const [rowsSelected, setRowsSelected] = (0, _react.useState)(new Set());
|
|
64
76
|
const [selectedCell, setSelectedCell] = (0, _react.useState)(null);
|
|
77
|
+
const handleAdd = item => {
|
|
78
|
+
console.log(item);
|
|
79
|
+
if (item.onClick) {
|
|
80
|
+
console.log('cccccccccccccccc');
|
|
81
|
+
} else {
|
|
82
|
+
console.log('bbbbbbbbbbbbb');
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const handleDuplicate = () => {};
|
|
86
|
+
const handleInsertBefore = () => {};
|
|
87
|
+
const handleInsertAfter = () => {};
|
|
88
|
+
const handleDeleteAll = () => {};
|
|
89
|
+
const toolbarItemsBottom = (0, _react.useMemo)(() => {
|
|
90
|
+
return toolbarItems?.filter(it => it.position === 'Bottom').map(item => {
|
|
91
|
+
return {
|
|
92
|
+
...item,
|
|
93
|
+
template: () => {
|
|
94
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'ADD' && /*#__PURE__*/_react.default.createElement("div", {
|
|
95
|
+
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
96
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
|
|
97
|
+
menu: {
|
|
98
|
+
items: itemsAdd,
|
|
99
|
+
onClick: () => handleAdd(item)
|
|
100
|
+
}
|
|
101
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Add item') : 'Add item')), item.key === 'DUPLICATE' && item.visible !== false && editingKey && /*#__PURE__*/_react.default.createElement("div", {
|
|
102
|
+
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
103
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
104
|
+
color: "green",
|
|
105
|
+
variant: 'outlined',
|
|
106
|
+
onClick: handleDuplicate,
|
|
107
|
+
className: "d-flex be-button"
|
|
108
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Duplicate') : 'Duplicate')), item.key === 'INSERT_BEFORE' && item.visible !== false && editingKey && /*#__PURE__*/_react.default.createElement("div", {
|
|
109
|
+
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
110
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
111
|
+
color: "green",
|
|
112
|
+
variant: 'outlined',
|
|
113
|
+
onClick: handleInsertBefore,
|
|
114
|
+
className: "d-flex be-button"
|
|
115
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Insert item before') : 'Insert item before')), item.key === 'INSERT_AFTER' && item.visible !== false && editingKey && /*#__PURE__*/_react.default.createElement("div", {
|
|
116
|
+
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
117
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
118
|
+
color: "green",
|
|
119
|
+
variant: 'outlined',
|
|
120
|
+
onClick: handleInsertAfter,
|
|
121
|
+
className: "d-flex be-button"
|
|
122
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Insert item after') : 'Insert item after')), item.key === 'DELETE' && item.visible !== false && /*#__PURE__*/_react.default.createElement("div", {
|
|
123
|
+
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
124
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
125
|
+
color: "primary",
|
|
126
|
+
variant: 'outlined',
|
|
127
|
+
onClick: handleDeleteAll,
|
|
128
|
+
className: "d-flex be-button"
|
|
129
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Delete all item') : 'Delete all item')));
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}, [toolbarItems]);
|
|
65
134
|
const {
|
|
66
135
|
control,
|
|
67
136
|
handleSubmit,
|
|
@@ -93,9 +162,10 @@ const GridEdit = props => {
|
|
|
93
162
|
|
|
94
163
|
if (!tableBody.contains(event.target)) {
|
|
95
164
|
setEditingKey('');
|
|
96
|
-
|
|
97
|
-
|
|
165
|
+
isSelecting.current = false;
|
|
166
|
+
startCell.current = null;
|
|
98
167
|
setSelectedCells(new Set());
|
|
168
|
+
setRowsSelected(new Set());
|
|
99
169
|
} else {}
|
|
100
170
|
}
|
|
101
171
|
};
|
|
@@ -593,20 +663,26 @@ const GridEdit = props => {
|
|
|
593
663
|
...column,
|
|
594
664
|
className: 'rc-ui-cell-editable',
|
|
595
665
|
render: (value, record, rowIndex) => {
|
|
666
|
+
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
596
667
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
597
668
|
className: (0, _classnames.default)('ui-rc_cell-content ui-rc_cell-content--index', {
|
|
598
|
-
selected: rowsSelected.has(`${
|
|
599
|
-
focus: selectedCells && Array.from(selectedCells).some(item => item.startsWith(`${
|
|
669
|
+
selected: rowsSelected.has(`${rowNumber}-${colIndex}`),
|
|
670
|
+
focus: selectedCells && Array.from(selectedCells).some(item => item.startsWith(`${rowNumber}-`))
|
|
600
671
|
}),
|
|
601
|
-
onMouseDown: event => handleMouseDownColIndex(
|
|
602
|
-
onMouseEnter: event => handleMouseEnterColIndex(
|
|
603
|
-
onClick: () => handleClickRowHeader(
|
|
672
|
+
onMouseDown: event => handleMouseDownColIndex(rowNumber, colIndex, event),
|
|
673
|
+
onMouseEnter: event => handleMouseEnterColIndex(rowNumber, colIndex, event),
|
|
674
|
+
onClick: () => handleClickRowHeader(rowNumber, colIndex)
|
|
604
675
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
605
676
|
className: 'ui-rc_content'
|
|
606
677
|
}, rowIndex + 1));
|
|
607
678
|
}
|
|
608
679
|
};
|
|
609
680
|
}
|
|
681
|
+
if ((column.key || column.field) === 'command') {
|
|
682
|
+
return {
|
|
683
|
+
...column
|
|
684
|
+
};
|
|
685
|
+
}
|
|
610
686
|
return {
|
|
611
687
|
...column,
|
|
612
688
|
// editType: getEditType(column, record),
|
|
@@ -687,12 +763,16 @@ const GridEdit = props => {
|
|
|
687
763
|
tabIndex: (rowIndex ?? 0) * columns.length + colIndex
|
|
688
764
|
}),
|
|
689
765
|
render: (value, record, rowIndex) => {
|
|
766
|
+
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
690
767
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
691
768
|
className: (0, _classnames.default)('ui-rc_cell-content', {
|
|
692
|
-
selected: selectedCells.has(`${
|
|
769
|
+
// selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
|
|
770
|
+
selected: selectedCells.has(`${rowNumber}-${colIndex}`)
|
|
693
771
|
}),
|
|
694
|
-
onMouseDown: event => handleMouseDown(
|
|
695
|
-
onMouseEnter
|
|
772
|
+
onMouseDown: event => handleMouseDown(rowNumber, colIndex, event)
|
|
773
|
+
// onMouseEnter={() => handleMouseEnter(record[rowKey], colIndex)}
|
|
774
|
+
,
|
|
775
|
+
onMouseEnter: () => handleMouseEnter(rowNumber, colIndex)
|
|
696
776
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
697
777
|
className: 'ui-rc_content'
|
|
698
778
|
}, (0, _useColumns.renderContent)(column, value, record, rowIndex, format)));
|
|
@@ -722,6 +802,18 @@ const GridEdit = props => {
|
|
|
722
802
|
});
|
|
723
803
|
}, [convertColumns]);
|
|
724
804
|
const mergedColumns = _react.default.useMemo(() => transformColumns(columns ?? []), [transformColumns, columns]);
|
|
805
|
+
const bottomToolbar = () => {
|
|
806
|
+
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Toolbar, {
|
|
807
|
+
style: {
|
|
808
|
+
width: '100%'
|
|
809
|
+
},
|
|
810
|
+
items: toolbarItemsBottom ?? [],
|
|
811
|
+
mode: 'scroll'
|
|
812
|
+
// onClick={({ item }) => {
|
|
813
|
+
// console.log('item', item)
|
|
814
|
+
// }}
|
|
815
|
+
}));
|
|
816
|
+
};
|
|
725
817
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_GridStyle.GridStyle, {
|
|
726
818
|
heightTable: height,
|
|
727
819
|
style: {
|
|
@@ -758,6 +850,7 @@ const GridEdit = props => {
|
|
|
758
850
|
target: 'sorter-icon'
|
|
759
851
|
},
|
|
760
852
|
format: format,
|
|
853
|
+
toolbarItems: toolbarItems,
|
|
761
854
|
selectionSettings: selectionSettings ? {
|
|
762
855
|
...selectionSettings,
|
|
763
856
|
checkboxOnly: true
|
|
@@ -766,7 +859,8 @@ const GridEdit = props => {
|
|
|
766
859
|
...style,
|
|
767
860
|
minHeight: height
|
|
768
861
|
},
|
|
769
|
-
rowHoverable: false
|
|
862
|
+
rowHoverable: false,
|
|
863
|
+
bottomToolbar: bottomToolbar
|
|
770
864
|
}))))), /*#__PURE__*/_react.default.createElement(_reactHotToast.Toaster, {
|
|
771
865
|
position: toast,
|
|
772
866
|
toastOptions: {
|
|
@@ -3,12 +3,16 @@ import type React from "react";
|
|
|
3
3
|
import type { IOperator } from "./hooks";
|
|
4
4
|
import type { TypeFilter, TableProps as RcTableProps, TableColumnType as RcColumnType, EditType } from "rc-master-ui";
|
|
5
5
|
import type { FilterOperator, TableRowSelection } from "rc-master-ui/es/table/interface";
|
|
6
|
-
import type { ToolbarItem } from "rc-master-ui/es/toolbar";
|
|
6
|
+
import type { ToolbarItem as RcToolbarItem } from "rc-master-ui/es/toolbar";
|
|
7
7
|
import type { ItemType } from "rc-master-ui/es/menu/interface";
|
|
8
8
|
import type { FieldNames, FilterFunc } from "rc-select/es/Select";
|
|
9
9
|
import type { ColorPickerProps } from "antd";
|
|
10
10
|
export type IColumnType = "number" | "time" | "date" | "week" | "month" | "file" | "quarter" | "year" | "datetime" | "string" | "boolean" | "checkbox" | "color" | null | undefined;
|
|
11
11
|
export type AnyObject = Record<PropertyKey, any>;
|
|
12
|
+
export type ToolbarItem = Omit<RcToolbarItem, 'position'> & {
|
|
13
|
+
position?: 'Top' | 'Bottom';
|
|
14
|
+
onClick?: (args: any) => void;
|
|
15
|
+
};
|
|
12
16
|
export type SelectMode = 'checkbox' | 'radio' | undefined;
|
|
13
17
|
export type ITextAlign = 'center' | 'left' | 'right';
|
|
14
18
|
export type Frozen = 'left' | 'right' | 'Left' | 'Right';
|