es-grid-template 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/grid-component/GridStyle.js +1 -1
- package/es/grid-component/InternalTable.d.ts +2 -0
- package/es/grid-component/InternalTable.js +6 -1
- package/es/grid-component/TableGrid.js +1 -1
- package/es/grid-component/hooks/columns/index.d.ts +1 -1
- package/es/grid-component/hooks/columns/index.js +19 -31
- package/es/grid-component/hooks/utils.d.ts +2 -0
- package/es/grid-component/hooks/utils.js +45 -1
- package/es/grid-component/styles.scss +4 -0
- package/es/grid-component/table/GridEdit.js +84 -74
- package/es/grid-component/table/Group.js +1 -0
- package/lib/grid-component/GridStyle.js +1 -1
- package/lib/grid-component/InternalTable.d.ts +2 -0
- package/lib/grid-component/InternalTable.js +6 -1
- package/lib/grid-component/TableGrid.js +1 -1
- package/lib/grid-component/hooks/columns/index.d.ts +1 -1
- package/lib/grid-component/hooks/columns/index.js +17 -29
- package/lib/grid-component/hooks/utils.d.ts +2 -0
- package/lib/grid-component/hooks/utils.js +53 -5
- package/lib/grid-component/styles.scss +4 -0
- package/lib/grid-component/table/GridEdit.js +84 -74
- package/lib/grid-component/table/Group.js +1 -0
- package/package.json +110 -110
|
@@ -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
|
-
})(["height:", ";.ui-rc-table.ui-rc-table-virtual.ui-rc-table-scroll-horizontal{.ui-rc-table-container{&:has(.ui-rc-table-tbody-virtual-scrollbar-horizontal){padding-bottom:8px;border-bottom:1px solid #e0e0e0;}}}.ui-rc-table-container{.ui-rc-table-tbody-virtual.ui-rc-table-tbody{min-height:", ";}}.ui-rc-toolbar-bottom{position:relative;padding:.25rem 1rem;background-color:#ffffff;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;visibility:visible;right:0;}.toolbar-button{border-radius:0;.ant-btn{border-radius:0;}}}.ui-rc-pagination{border-bottom:1px solid #e0e0e0;border-top:1px solid #e0e0e0;margin:0;padding:.75rem 1rem;background-color:#ffffff;.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;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:50px;bottom:0;visibility:visible;right:0;}&.pagination-template{position:relative;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;visibility:visible;right:0;}}}.react-resizable{position:relative;background-clip:padding-box;}.rc-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 ? `${props.$heightTable}px` : undefined, props => props.$heightScroll ? `${props.$heightScroll}px` : undefined);
|
|
5
|
+
})(["height:", ";.ui-rc-table.ui-rc-table-virtual.ui-rc-table-scroll-horizontal{.ui-rc-table-container{&:has(.ui-rc-table-tbody-virtual-scrollbar-horizontal){padding-bottom:8px;border-bottom:1px solid #e0e0e0;}}}.ui-rc-table-container{.ui-rc-table-tbody-virtual.ui-rc-table-tbody{min-height:", ";}.ui-rc-table-body{&:has(.ui-rc-table-placeholder){height:", ";}table{height:100%;.ui-rc-table-placeholder{vertical-align:top;}}}.ui-rc-table-placeholder{}}.ui-rc-toolbar-bottom{position:relative;padding:.25rem 1rem;background-color:#ffffff;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;visibility:visible;right:0;}.toolbar-button{border-radius:0;.ant-btn{border-radius:0;}}}.ui-rc-pagination{border-bottom:1px solid #e0e0e0;border-top:1px solid #e0e0e0;margin:0;padding:.75rem 1rem;background-color:#ffffff;.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;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:50px;bottom:0;visibility:visible;right:0;}&.pagination-template{position:relative;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;visibility:visible;right:0;}}}.react-resizable{position:relative;background-clip:padding-box;}.rc-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 ? `${props.$heightTable}px` : undefined, props => props.$heightScroll ? `${props.$heightScroll}px` : undefined, props => props.$heightScroll ? `${props.$heightScroll - 1}px` : undefined);
|
|
@@ -4,6 +4,8 @@ import type { GridTableProps } from "./type";
|
|
|
4
4
|
import 'dayjs/locale/es';
|
|
5
5
|
import 'dayjs/locale/vi';
|
|
6
6
|
import './styles.scss';
|
|
7
|
+
import 'rc-master-ui/es/date-range-picker/styles/index.less';
|
|
8
|
+
import 'rc-master-ui/assets/index.css';
|
|
7
9
|
export declare const SELECTION_COLUMN: {};
|
|
8
10
|
declare const InternalTable: <RecordType extends object>(props: GridTableProps<RecordType>) => React.JSX.Element;
|
|
9
11
|
export default InternalTable;
|
|
@@ -11,9 +11,13 @@ import GridEdit from "./table/GridEdit";
|
|
|
11
11
|
import Grid from "./table/Grid";
|
|
12
12
|
import en from "rc-master-ui/es/date-picker/locale/en_US";
|
|
13
13
|
import vi from "rc-master-ui/es/date-picker/locale/vi_VN";
|
|
14
|
+
import enDr from "rc-master-ui/es/locales/en_US";
|
|
15
|
+
import viDr from "rc-master-ui/es/locales/vi_VN";
|
|
14
16
|
// import useColumns from "./hooks/useColumns";
|
|
15
17
|
|
|
16
18
|
import "./styles.scss";
|
|
19
|
+
import 'rc-master-ui/es/date-range-picker/styles/index.less';
|
|
20
|
+
import 'rc-master-ui/assets/index.css';
|
|
17
21
|
import { flatColumns2, renderContent, renderFilter } from "./hooks/columns";
|
|
18
22
|
import Group from "./table/Group";
|
|
19
23
|
import Swal from "sweetalert2";
|
|
@@ -202,6 +206,7 @@ const InternalTable = props => {
|
|
|
202
206
|
// }, [height, id])
|
|
203
207
|
|
|
204
208
|
const local = lang && lang === 'en' ? en : vi;
|
|
209
|
+
const dateRangeLocale = lang && lang === 'en' ? enDr : viDr;
|
|
205
210
|
const buddhistLocale = {
|
|
206
211
|
...local,
|
|
207
212
|
lang: {
|
|
@@ -319,7 +324,7 @@ const InternalTable = props => {
|
|
|
319
324
|
style: {
|
|
320
325
|
marginBottom: 8
|
|
321
326
|
}
|
|
322
|
-
}, renderFilter(column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, propDataSourceFilter ?? [], buddhistLocale, locale, t)), /*#__PURE__*/React.createElement(Space, {
|
|
327
|
+
}, renderFilter(column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, propDataSourceFilter ?? [], buddhistLocale, locale, t, format, dateRangeLocale)), /*#__PURE__*/React.createElement(Space, {
|
|
323
328
|
style: {
|
|
324
329
|
justifyContent: 'end',
|
|
325
330
|
width: '100%'
|
|
@@ -485,7 +485,7 @@ const TableGrid = props => {
|
|
|
485
485
|
|
|
486
486
|
// const dec = (col.format?.decimalScale || col.format?.decimalScale === 0) ? col.format?.decimalScale : format?.decimalScale
|
|
487
487
|
const dec = cellFormat?.decimalScale;
|
|
488
|
-
const sumValue = col.type === 'number' ? sumDataByField(dataSource, col?.key) : 0;
|
|
488
|
+
const sumValue = col.type === 'number' ? sumDataByField(filterDataByColumns4(dataSource, filterStates), col?.key) : 0;
|
|
489
489
|
const value = !isEmpty(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
|
|
490
490
|
const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
|
|
491
491
|
const numericFormatProps = {
|
|
@@ -6,4 +6,4 @@ export declare function flatColumns<RecordType>(columns: ColumnsTable<RecordType
|
|
|
6
6
|
export declare const flatColumns2: <RecordType>(columns: ColumnsTable<RecordType>) => ColumnsTable<RecordType>;
|
|
7
7
|
export declare const getValueCell: <T>(column: ColumnTable<T>, value: any, format?: IFormat) => any;
|
|
8
8
|
export declare const renderContent: <T>(column: ColumnTable<T>, value: any, record: any, index: number, format?: IFormat) => React.JSX.Element;
|
|
9
|
-
export declare const renderFilter: <RecordType>(column: ColumnTable<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any, format?: IFormat) => React.JSX.Element;
|
|
9
|
+
export declare const renderFilter: <RecordType>(column: ColumnTable<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any, format?: IFormat, dateRangeLocale?: any) => React.JSX.Element;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { checkDecimalSeparator, checkThousandSeparator, convertDateToDayjs, convertDayjsToDate, getDatepickerFormat, getDateString, getTypeFilter, isColor, isEmpty } from "../utils";
|
|
1
|
+
import { checkDecimalSeparator, checkThousandSeparator, convertDateToDayjs, convertDayjsToDate, convertFormat, getDatepickerFormat, getDateString, getTypeFilter, isColor, isEmpty } from "../utils";
|
|
2
2
|
import { numericFormatter } from "react-numeric-component";
|
|
3
3
|
import dayjs from "dayjs";
|
|
4
4
|
import moment from "moment/moment";
|
|
5
5
|
import React, { Fragment } from "react";
|
|
6
|
-
import { DatePicker, Empty, Input, Select } from "rc-master-ui";
|
|
6
|
+
import { CustomProvider, DatePicker, DateRangePicker, Empty, Input, Select } from "rc-master-ui";
|
|
7
7
|
import CheckboxFilter from "../../CheckboxFilter";
|
|
8
8
|
import { SELECTION_COLUMN } from "rc-master-ui/es/table/hooks/useSelection";
|
|
9
9
|
import NumberRange from "../../number-range";
|
|
10
10
|
import NumberInput from "../../number";
|
|
11
11
|
// import {Typography} from "antd";
|
|
12
|
-
const {
|
|
13
|
-
RangePicker
|
|
14
|
-
} = DatePicker;
|
|
12
|
+
// const {RangePicker} = DatePicker
|
|
15
13
|
|
|
16
14
|
// const { Text } = Typography;
|
|
17
15
|
|
|
@@ -125,11 +123,11 @@ export const renderContent = (column, value, record, index, format) => {
|
|
|
125
123
|
field: column.field
|
|
126
124
|
}) : column.template : content);
|
|
127
125
|
};
|
|
128
|
-
export const renderFilter = (column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, dataSourceFilter, buddhistLocale, locale, t, format) => {
|
|
126
|
+
export const renderFilter = (column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, dataSourceFilter, buddhistLocale, locale, t, format, dateRangeLocale) => {
|
|
129
127
|
const cellFormat = column.format ? typeof column.format === 'function' ? column.format({}) : column.format : format;
|
|
130
128
|
const type = getTypeFilter(column);
|
|
131
129
|
const dateFormat = getDatepickerFormat(column?.typeFilter ?? column?.type, cellFormat) ?? 'DD/MM/YYYY';
|
|
132
|
-
const dateRangeFormat = getDatepickerFormat(column?.type, cellFormat) ?? 'DD/MM/YYYY';
|
|
130
|
+
const dateRangeFormat = convertFormat(getDatepickerFormat(column?.type, cellFormat) ?? 'DD/MM/YYYY');
|
|
133
131
|
const find = dataSourceFilter?.find(it => it.key === column?.field);
|
|
134
132
|
const options = find ? find.data : [];
|
|
135
133
|
switch (type) {
|
|
@@ -176,35 +174,25 @@ export const renderFilter = (column, selectedKeys, setSelectedKeys, confirm, vis
|
|
|
176
174
|
}
|
|
177
175
|
}))));
|
|
178
176
|
case 'DateRange':
|
|
179
|
-
const dateRangeValue = [selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateRangeFormat) : '', selectedKeys[1] ? convertDateToDayjs(new Date(selectedKeys[1]), dateRangeFormat) : '']
|
|
177
|
+
// const dateRangeValue: any = [selectedKeys[0] ? convertDateToDayjs(new Date(selectedKeys[0]), dateRangeFormat) : '', selectedKeys[1] ? convertDateToDayjs(new Date(selectedKeys[1]), dateRangeFormat) : '']
|
|
178
|
+
const dateRangeValue = selectedKeys && selectedKeys.length > 0 ? [selectedKeys[0] ? new Date(selectedKeys[0]) : '', selectedKeys[1] ? new Date(selectedKeys[1]) : ''] : null;
|
|
180
179
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
181
180
|
className: 'mb-1'
|
|
182
|
-
}, /*#__PURE__*/React.createElement(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
value: dateRangeValue,
|
|
190
|
-
locale: buddhistLocale
|
|
191
|
-
// placeholder={['Ngày bắt đầu', 'Ngày kết thúc']}
|
|
192
|
-
,
|
|
193
|
-
popupStyle: {
|
|
194
|
-
zIndex: 9999
|
|
181
|
+
}, /*#__PURE__*/React.createElement(CustomProvider, {
|
|
182
|
+
locale: dateRangeLocale
|
|
183
|
+
}, /*#__PURE__*/React.createElement(DateRangePicker
|
|
184
|
+
// placeholder={['Ngày bắt đầu', 'Ngày bắt đầu']}
|
|
185
|
+
, {
|
|
186
|
+
style: {
|
|
187
|
+
width: 300
|
|
195
188
|
},
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
189
|
+
format: dateRangeFormat,
|
|
190
|
+
value: dateRangeValue,
|
|
191
|
+
onChange: value => {
|
|
192
|
+
const newDateRangeValue = value ? [value[0] ? moment(value[0]).format() : '', value[1] ? moment(value[0]).format() : ''] : [];
|
|
200
193
|
setSelectedKeys(newDateRangeValue);
|
|
201
|
-
},
|
|
202
|
-
style: {
|
|
203
|
-
width: '100%'
|
|
204
194
|
}
|
|
205
|
-
|
|
206
|
-
// getPopupContainer={() => menuRef.current}
|
|
207
|
-
}))));
|
|
195
|
+
})))));
|
|
208
196
|
case 'Week':
|
|
209
197
|
const weekValue = !isEmpty(selectedKeys[0]) ? dayjs(selectedKeys[0], dateFormat) : null;
|
|
210
198
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
@@ -36,7 +36,9 @@ export declare const getFormat: (colFormat?: IFormat, format?: IFormat) => {
|
|
|
36
36
|
monthFormat: string;
|
|
37
37
|
yearFormat: string;
|
|
38
38
|
};
|
|
39
|
+
export declare function convertFormat(formatStr: string): string;
|
|
39
40
|
export declare const getDatepickerFormat: (type: EditType | TypeFilter | IColumnType, format?: IFormat) => string;
|
|
41
|
+
export declare const getDateRangeFormat: (type: EditType | TypeFilter | IColumnType, format?: IFormat) => string;
|
|
40
42
|
export declare const customWeekStartEndFormat: (value: any, weekFormat: string) => string;
|
|
41
43
|
export declare const getTypeFilter: (col: ColumnTable<any>) => TypeFilter;
|
|
42
44
|
export declare const updateArrayByKey: (arr: any[], element: any, key: string) => any[];
|
|
@@ -190,12 +190,56 @@ export const getFormat = (colFormat, format) => {
|
|
|
190
190
|
yearFormat: colFormat?.yearFormat ?? format?.yearFormat
|
|
191
191
|
};
|
|
192
192
|
};
|
|
193
|
+
export function convertFormat(formatStr) {
|
|
194
|
+
// return formatStr.split('').map((char, i) => {
|
|
195
|
+
// if (char === 'D' || char === 'd') {
|
|
196
|
+
// return 'd'; // ngày: lowercase
|
|
197
|
+
// }
|
|
198
|
+
// if (char === 'Y' || char === 'y') {
|
|
199
|
+
// return 'y'; // năm: lowercase
|
|
200
|
+
// }
|
|
201
|
+
// if (char === 'M' || char === 'm') {
|
|
202
|
+
// return char; // tháng: giữ nguyên
|
|
203
|
+
// }
|
|
204
|
+
// return char; // separator
|
|
205
|
+
// }).join('');
|
|
206
|
+
|
|
207
|
+
return formatStr.split('').map(char => {
|
|
208
|
+
if (char === 'D' || char === 'd') return 'd';
|
|
209
|
+
if (char === 'Y' || char === 'y') return 'y';
|
|
210
|
+
if ('Hhmsa'.includes(char)) return char; // giờ, phút, giây, am/pm
|
|
211
|
+
if (char === 'M' || char === 'm') return char; // tháng: giữ nguyên
|
|
212
|
+
return char; // dấu phân cách
|
|
213
|
+
}).join('');
|
|
214
|
+
}
|
|
193
215
|
export const getDatepickerFormat = (type, format) => {
|
|
194
216
|
const typeFormat = type ? type.toLowerCase() : '';
|
|
195
217
|
switch (typeFormat) {
|
|
196
218
|
case "date":
|
|
197
219
|
case "daterange":
|
|
198
|
-
return format?.dateFormat ?? '
|
|
220
|
+
return format?.dateFormat ?? 'dd/MM/YYYY';
|
|
221
|
+
case "datetime":
|
|
222
|
+
return format?.datetimeFormat ?? 'dd/MM/YYYY HH:mm';
|
|
223
|
+
case "week":
|
|
224
|
+
return format?.weekFormat ?? 'dd/MM';
|
|
225
|
+
case "month":
|
|
226
|
+
return format?.monthFormat ?? 'MM/YYYY';
|
|
227
|
+
case "quarter":
|
|
228
|
+
return format?.dateFormat ?? 'dd/MM/YYYY';
|
|
229
|
+
case "year":
|
|
230
|
+
return format?.yearFormat ?? 'YYYY';
|
|
231
|
+
case "time":
|
|
232
|
+
return format?.timeFormat ?? 'HH:mm';
|
|
233
|
+
default:
|
|
234
|
+
return 'dd/MM/YYYY';
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
export const getDateRangeFormat = (type, format) => {
|
|
238
|
+
const typeFormat = type ? type.toLowerCase() : '';
|
|
239
|
+
switch (typeFormat) {
|
|
240
|
+
case "date":
|
|
241
|
+
case "daterange":
|
|
242
|
+
return convertFormat(format?.dateFormat ?? 'DD/MM/YYYY');
|
|
199
243
|
case "datetime":
|
|
200
244
|
return format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm';
|
|
201
245
|
case "week":
|
|
@@ -223,6 +223,8 @@ const GridEdit = props => {
|
|
|
223
223
|
// quét vùng chọn
|
|
224
224
|
const isDragMouse = useRef(false);
|
|
225
225
|
const isMouseDown = useRef(false);
|
|
226
|
+
const editingKey = useRef('');
|
|
227
|
+
const cellEditing = useRef({});
|
|
226
228
|
|
|
227
229
|
// quét vùng được paste - tiếp tục hiển thị con trỏ crosshair
|
|
228
230
|
// const isPasteDragging = useRef(false);
|
|
@@ -368,7 +370,9 @@ const GridEdit = props => {
|
|
|
368
370
|
// }, [])
|
|
369
371
|
|
|
370
372
|
const [form] = Form.useForm();
|
|
371
|
-
|
|
373
|
+
|
|
374
|
+
// const [editingKey, setEditingKey] = useState<string | number>('')
|
|
375
|
+
|
|
372
376
|
const [dataErrors, setDataErrors] = useState([]);
|
|
373
377
|
const [isFilter, setIsFilter] = React.useState(false);
|
|
374
378
|
const [rangeCells, setRangeCells] = useState(new Set());
|
|
@@ -377,7 +381,9 @@ const GridEdit = props => {
|
|
|
377
381
|
type: ''
|
|
378
382
|
});
|
|
379
383
|
const [rowsAdd, setRowsAdd] = useState(1);
|
|
380
|
-
|
|
384
|
+
|
|
385
|
+
// const [cellEditing, setCellEditing] = useState<any>(null)
|
|
386
|
+
|
|
381
387
|
const [isPasteDragging, setIsPasteDragging] = useState(false); // isPasteDragging == tiếp tục hiển thị con trỏ crosshair
|
|
382
388
|
|
|
383
389
|
const [innerExpandedKeys, setInnerExpandedKeys] = React.useState(() => {
|
|
@@ -490,10 +496,11 @@ const GridEdit = props => {
|
|
|
490
496
|
// onRemoveBorderSelectedCell(selectedCells.current, id)
|
|
491
497
|
//
|
|
492
498
|
|
|
493
|
-
setTimeout(() => {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}, 10)
|
|
499
|
+
// setTimeout(() => {
|
|
500
|
+
// onAddBgSelectedCell(selectedCells.current, id)
|
|
501
|
+
// onAddBorderSelectedCell(selectedCells.current, id)
|
|
502
|
+
// }, 10)
|
|
503
|
+
|
|
497
504
|
const defaultRowValue = getDefaultValue(defaultValue);
|
|
498
505
|
// const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
|
|
499
506
|
|
|
@@ -681,10 +688,11 @@ const GridEdit = props => {
|
|
|
681
688
|
}
|
|
682
689
|
}, [dataSource, defaultValue, getRowKey, mergedExpandedKeys, rowKey, rowsFocus, triggerChangeData]);
|
|
683
690
|
const handleDeleteRows = React.useCallback(item => {
|
|
684
|
-
setTimeout(() => {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
})
|
|
691
|
+
// setTimeout(() => {
|
|
692
|
+
// onAddBgSelectedCell(selectedCells.current, id)
|
|
693
|
+
// onAddBorderSelectedCell(selectedCells.current, id)
|
|
694
|
+
// })
|
|
695
|
+
|
|
688
696
|
if (item.onClick) {
|
|
689
697
|
item.onClick({
|
|
690
698
|
toolbar: item
|
|
@@ -716,7 +724,9 @@ const GridEdit = props => {
|
|
|
716
724
|
const rowIndex = Number(rowIndexStr);
|
|
717
725
|
const colIndex = Number(colIndexStr);
|
|
718
726
|
const field = colIndexToField[colIndex];
|
|
719
|
-
|
|
727
|
+
const column = flatColumns2(visibleCols)[colIndex];
|
|
728
|
+
const rowData = flattenData(childrenColumnName, dataSource)[rowIndex];
|
|
729
|
+
if (newData[rowIndex] && field && field in newData[rowIndex] && isEditable(column, rowData)) {
|
|
720
730
|
// @ts-ignore
|
|
721
731
|
newData[rowIndex][field] = '';
|
|
722
732
|
}
|
|
@@ -947,9 +957,13 @@ const GridEdit = props => {
|
|
|
947
957
|
mode: 'onChange',
|
|
948
958
|
resolver: validate ? yupResolver(validate) : undefined
|
|
949
959
|
});
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
960
|
+
|
|
961
|
+
// const isEditing = React.useCallback((record: RecordType) => {
|
|
962
|
+
// return record[rowKey as any] === editingKey.current
|
|
963
|
+
// }, [editingKey, rowKey])
|
|
964
|
+
|
|
965
|
+
// console.log('isEditing', isEditing)
|
|
966
|
+
|
|
953
967
|
React.useEffect(() => {
|
|
954
968
|
const handleClickOutside = event => {
|
|
955
969
|
const element = event.target;
|
|
@@ -976,9 +990,9 @@ const GridEdit = props => {
|
|
|
976
990
|
// if (ref.current && tableId && !tableId.contains(event.target as Node)) {
|
|
977
991
|
|
|
978
992
|
if (ref.current && tableBody && !tableBody.contains(event.target)) {
|
|
979
|
-
// setEditingKey('')
|
|
980
993
|
setTimeout(() => {
|
|
981
|
-
setEditingKey('')
|
|
994
|
+
// setEditingKey('')
|
|
995
|
+
editingKey.current = '';
|
|
982
996
|
});
|
|
983
997
|
isSelecting.current = false;
|
|
984
998
|
startCell.current = null;
|
|
@@ -996,11 +1010,12 @@ const GridEdit = props => {
|
|
|
996
1010
|
|
|
997
1011
|
// document.addEventListener('click', handleClickOutside)
|
|
998
1012
|
document.addEventListener('mousedown', handleClickOutside);
|
|
999
|
-
document.addEventListener('touchstart', handleClickOutside)
|
|
1013
|
+
// document.addEventListener('touchstart', handleClickOutside)
|
|
1014
|
+
|
|
1000
1015
|
return () => {
|
|
1001
1016
|
// document.removeEventListener('click', handleClickOutside)
|
|
1002
1017
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
1003
|
-
document.removeEventListener('touchstart', handleClickOutside)
|
|
1018
|
+
// document.removeEventListener('touchstart', handleClickOutside)
|
|
1004
1019
|
};
|
|
1005
1020
|
}, [id]);
|
|
1006
1021
|
const triggerDragPaste = pastesArray => {
|
|
@@ -1412,12 +1427,13 @@ const GridEdit = props => {
|
|
|
1412
1427
|
e.stopPropagation();
|
|
1413
1428
|
return;
|
|
1414
1429
|
}
|
|
1415
|
-
if (editingKey && editingKey === record[rowKey]) {
|
|
1430
|
+
if (editingKey && editingKey.current === record[rowKey]) {
|
|
1416
1431
|
return;
|
|
1417
1432
|
}
|
|
1418
|
-
if (record[rowKey] !== editingKey && editingKey !== '') {
|
|
1433
|
+
if (record[rowKey] !== editingKey.current && editingKey.current !== '') {
|
|
1419
1434
|
setTimeout(() => {
|
|
1420
|
-
setEditingKey('')
|
|
1435
|
+
// setEditingKey('')
|
|
1436
|
+
editingKey.current = '';
|
|
1421
1437
|
});
|
|
1422
1438
|
}
|
|
1423
1439
|
|
|
@@ -1653,8 +1669,9 @@ const GridEdit = props => {
|
|
|
1653
1669
|
e.stopPropagation();
|
|
1654
1670
|
return;
|
|
1655
1671
|
}
|
|
1656
|
-
if (editingKey) {
|
|
1657
|
-
|
|
1672
|
+
if (editingKey.current) {
|
|
1673
|
+
editingKey.current = '';
|
|
1674
|
+
// setEditingKey('')
|
|
1658
1675
|
}
|
|
1659
1676
|
isSelectingRow.current = true;
|
|
1660
1677
|
rowStart.current = {
|
|
@@ -1870,12 +1887,20 @@ const GridEdit = props => {
|
|
|
1870
1887
|
const handleEdit = (record, col, editType, e) => {
|
|
1871
1888
|
onRemoveBorderSelectedCell(selectedCells.current, id);
|
|
1872
1889
|
setTooltipContent('');
|
|
1890
|
+
|
|
1873
1891
|
// @ts-ignore
|
|
1874
|
-
setEditingKey(record[rowKey])
|
|
1875
|
-
|
|
1892
|
+
// setEditingKey(record[rowKey])
|
|
1893
|
+
editingKey.current = record[rowKey];
|
|
1894
|
+
|
|
1895
|
+
// setCellEditing({
|
|
1896
|
+
// row: record,
|
|
1897
|
+
// column: col
|
|
1898
|
+
// })
|
|
1899
|
+
|
|
1900
|
+
cellEditing.current = {
|
|
1876
1901
|
row: record,
|
|
1877
1902
|
column: col
|
|
1878
|
-
}
|
|
1903
|
+
};
|
|
1879
1904
|
reset();
|
|
1880
1905
|
|
|
1881
1906
|
// const formattedRecord = { ...record };
|
|
@@ -1949,7 +1974,7 @@ const GridEdit = props => {
|
|
|
1949
1974
|
}
|
|
1950
1975
|
};
|
|
1951
1976
|
const handleFocusCell = (rowIndex, colIndex, col, scrollType, e, isTimeout) => {
|
|
1952
|
-
const isEdit = editingKey !== '';
|
|
1977
|
+
const isEdit = editingKey.current !== '';
|
|
1953
1978
|
const cellEdit = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowIndex}"].cell-editing[data-col-index="${colIndex}"]`);
|
|
1954
1979
|
const cell = document.querySelector(`.ui-rc-table-row .cell-editable[data-row-index="${rowIndex}"].cell-editable[data-col-index="${colIndex}"]`);
|
|
1955
1980
|
const updateSelection = () => {
|
|
@@ -1993,7 +2018,8 @@ const GridEdit = props => {
|
|
|
1993
2018
|
scrollToCell(rowIndex, colIndex, editingCell, 'horizontal');
|
|
1994
2019
|
}
|
|
1995
2020
|
if (scrollType === 'vertical' && cellEditable) {
|
|
1996
|
-
setEditingKey('')
|
|
2021
|
+
// setEditingKey('')
|
|
2022
|
+
editingKey.current = '';
|
|
1997
2023
|
updateSelection();
|
|
1998
2024
|
scrollToCell(rowIndex, colIndex, cellEdit, 'vertical');
|
|
1999
2025
|
if (e?.key !== 'Tab') {
|
|
@@ -2042,13 +2068,13 @@ const GridEdit = props => {
|
|
|
2042
2068
|
return {
|
|
2043
2069
|
'data-row-index': rowNumber,
|
|
2044
2070
|
onPaste: event => {
|
|
2045
|
-
if (editingKey === '') {
|
|
2071
|
+
if (editingKey.current === '') {
|
|
2046
2072
|
handlePaste(record, colIndex + 1, rowNumber, event);
|
|
2047
2073
|
event.preventDefault();
|
|
2048
2074
|
}
|
|
2049
2075
|
},
|
|
2050
2076
|
onCopy: e => {
|
|
2051
|
-
if (editingKey === '') {
|
|
2077
|
+
if (editingKey.current === '') {
|
|
2052
2078
|
handleCopy(e);
|
|
2053
2079
|
e.preventDefault();
|
|
2054
2080
|
}
|
|
@@ -2089,7 +2115,7 @@ const GridEdit = props => {
|
|
|
2089
2115
|
const key = getRowKey(record, dataSource.indexOf(record));
|
|
2090
2116
|
if (event.key === 'Control' && event.ctrlKey) {} else {
|
|
2091
2117
|
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
|
|
2092
|
-
if (record[rowKey] !== editingKey && isEditable(column, record)) {
|
|
2118
|
+
if (record[rowKey] !== editingKey.current && isEditable(column, record)) {
|
|
2093
2119
|
// ~~ khi editingKey = ''
|
|
2094
2120
|
event.preventDefault();
|
|
2095
2121
|
event.stopPropagation();
|
|
@@ -2112,7 +2138,7 @@ const GridEdit = props => {
|
|
|
2112
2138
|
if (event.key === 'Enter') {
|
|
2113
2139
|
event.preventDefault();
|
|
2114
2140
|
event.stopPropagation();
|
|
2115
|
-
if (editingKey && editingKey !== '' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length && event.key === 'Enter') {
|
|
2141
|
+
if (editingKey && editingKey.current !== '' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length && event.key === 'Enter') {
|
|
2116
2142
|
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
2117
2143
|
} else {
|
|
2118
2144
|
// // focus cell hiện tại và tắt edit
|
|
@@ -2128,7 +2154,7 @@ const GridEdit = props => {
|
|
|
2128
2154
|
}
|
|
2129
2155
|
}
|
|
2130
2156
|
if (event.key === 'Tab') {
|
|
2131
|
-
if (editingKey) {} else {
|
|
2157
|
+
if (editingKey.current) {} else {
|
|
2132
2158
|
if (colIndex + 1 !== visibleCols.length) {
|
|
2133
2159
|
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
2134
2160
|
} else {
|
|
@@ -2138,7 +2164,7 @@ const GridEdit = props => {
|
|
|
2138
2164
|
}
|
|
2139
2165
|
}
|
|
2140
2166
|
if (event.key === 'ArrowRight' && colIndex + 1 !== visibleCols.length) {
|
|
2141
|
-
if (editingKey !== '') {} else {
|
|
2167
|
+
if (editingKey.current !== '') {} else {
|
|
2142
2168
|
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
2143
2169
|
}
|
|
2144
2170
|
}
|
|
@@ -2147,47 +2173,51 @@ const GridEdit = props => {
|
|
|
2147
2173
|
event.stopPropagation();
|
|
2148
2174
|
event.preventDefault();
|
|
2149
2175
|
} else {
|
|
2150
|
-
if (editingKey !== '') {} else {
|
|
2176
|
+
if (editingKey.current !== '') {} else {
|
|
2151
2177
|
handleFocusCell(rowNumber, colIndex - 1, column, 'horizontal', event);
|
|
2152
2178
|
}
|
|
2153
2179
|
}
|
|
2154
2180
|
}
|
|
2155
2181
|
if (event.key === 'ArrowDown' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length) {
|
|
2156
|
-
if (isEditing(record) && (
|
|
2182
|
+
// if (isEditing(record) && (
|
|
2183
|
+
if (record[rowKey] === editingKey.current && (getEditType(column, record) === 'treeSelect' || getEditType(column, record) === 'select' || getEditType(column, record) === 'selectTable' || getEditType(column, record) === 'asyncSelect')) {
|
|
2157
2184
|
event.stopPropagation();
|
|
2158
2185
|
} else {
|
|
2159
2186
|
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
2160
2187
|
}
|
|
2161
2188
|
}
|
|
2162
2189
|
if (event.key === 'ArrowUp' && (rowNumber ?? 0) > 0) {
|
|
2163
|
-
if (
|
|
2190
|
+
if (record[rowKey] === editingKey.current && (getEditType(column, record) === 'asyncSelect' || getEditType(column, record) === 'select' || getEditType(column, record) === 'selectTable' || getEditType(column, record) === 'treeSelect')) {
|
|
2164
2191
|
event.stopPropagation();
|
|
2165
2192
|
} else {
|
|
2166
2193
|
handleFocusCell((rowNumber ?? 0) - 1, colIndex, column, 'vertical', event);
|
|
2167
2194
|
}
|
|
2168
2195
|
}
|
|
2169
2196
|
if (event.key === 'Delete') {
|
|
2197
|
+
if (!isEditable(column, record)) {}
|
|
2170
2198
|
handleDeleteContent();
|
|
2171
2199
|
}
|
|
2172
2200
|
if (event.key === 'Escape') {
|
|
2173
|
-
setEditingKey('')
|
|
2201
|
+
// setEditingKey('')
|
|
2202
|
+
editingKey.current = '';
|
|
2174
2203
|
}
|
|
2175
2204
|
}
|
|
2176
2205
|
},
|
|
2177
2206
|
onPaste: event => {
|
|
2178
|
-
if (editingKey === '') {
|
|
2207
|
+
if (editingKey.current === '') {
|
|
2179
2208
|
handlePaste(record, colIndex, rowNumber, event);
|
|
2180
2209
|
event.preventDefault();
|
|
2181
2210
|
}
|
|
2182
2211
|
},
|
|
2183
2212
|
onCopy: e => {
|
|
2184
|
-
if (editingKey === '') {
|
|
2213
|
+
if (editingKey.current === '') {
|
|
2185
2214
|
handleCopy(e);
|
|
2186
2215
|
e.preventDefault();
|
|
2187
2216
|
}
|
|
2188
2217
|
},
|
|
2189
2218
|
onDoubleClick: event => {
|
|
2190
|
-
if (!isEditing(record) && record[rowKey] !== editingKey && isEditable(column, record)) {
|
|
2219
|
+
// if (!isEditing(record) && record[rowKey] !== editingKey.current && isEditable(column as any, record)) {
|
|
2220
|
+
if (!(record[rowKey] === editingKey.current) && record[rowKey] !== editingKey.current && isEditable(column, record)) {
|
|
2191
2221
|
handleEdit(record, column, getEditType(column, record), event);
|
|
2192
2222
|
|
|
2193
2223
|
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
@@ -2212,26 +2242,21 @@ const GridEdit = props => {
|
|
|
2212
2242
|
}
|
|
2213
2243
|
},
|
|
2214
2244
|
onClick: () => {
|
|
2215
|
-
if (record[rowKey] !== editingKey && editingKey !== '') {
|
|
2245
|
+
if (record[rowKey] !== editingKey.current && editingKey.current !== '') {
|
|
2216
2246
|
// setEditingKey('')
|
|
2217
2247
|
} else {
|
|
2218
|
-
if (record[rowKey] !== editingKey) {
|
|
2248
|
+
if (record[rowKey] !== editingKey.current) {
|
|
2219
2249
|
onAddBorderSelectedCell(selectedCells.current, id);
|
|
2220
2250
|
}
|
|
2221
|
-
if (editingKey) {
|
|
2251
|
+
if (editingKey.current) {
|
|
2222
2252
|
handleCellClick(rowNumber, record, column);
|
|
2223
2253
|
}
|
|
2224
2254
|
}
|
|
2225
2255
|
},
|
|
2226
2256
|
// className: isEditing(record) ? `rc-ui-cell-editable cell-editing ${!isEditable(column as any, record) ? 'disable' : ''}` : `rc-ui-cell-editable cell-editable ${!isEditable(column as any, record) ? 'disable' : ''}`,
|
|
2227
2257
|
className: classNames('rc-ui-cell-editable', {
|
|
2228
|
-
'cell-editing':
|
|
2229
|
-
'cell-editable': !
|
|
2230
|
-
// selected: isSelectedCell(rangeCells,rowIndex, colIndex),
|
|
2231
|
-
// 'cell-border-bottom': isRangeCell(rangeCells, 'bottom',rowIndex, colIndex),
|
|
2232
|
-
// 'cell-border-right': isRangeCell(rangeCells, 'right',rowIndex, colIndex),
|
|
2233
|
-
// 'cell-border-top': isRangeCell(rangeCells, 'top',rowIndex, colIndex),
|
|
2234
|
-
// 'cell-border-left': isRangeCell(rangeCells, 'left',rowIndex, colIndex),
|
|
2258
|
+
'cell-editing': record[rowKey] === editingKey.current,
|
|
2259
|
+
'cell-editable': !(record[rowKey] === editingKey.current),
|
|
2235
2260
|
disable: !isEditable(column, record)
|
|
2236
2261
|
}),
|
|
2237
2262
|
record,
|
|
@@ -2244,8 +2269,9 @@ const GridEdit = props => {
|
|
|
2244
2269
|
'data-col-index': colIndex,
|
|
2245
2270
|
'data-row-index': rowNumber,
|
|
2246
2271
|
'data-tooltip-id': "tooltip-cell-content",
|
|
2247
|
-
editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record),
|
|
2248
|
-
|
|
2272
|
+
// editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column as any, record),
|
|
2273
|
+
editing: record.rowId === editingKey.current && rowEditable?.(record) !== false && isEditable(column, record),
|
|
2274
|
+
cellEditing: cellEditing.current,
|
|
2249
2275
|
t,
|
|
2250
2276
|
tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex,
|
|
2251
2277
|
style: isPasteDragging ? {
|
|
@@ -2260,13 +2286,13 @@ const GridEdit = props => {
|
|
|
2260
2286
|
handleClickColHeader(column, colIndex);
|
|
2261
2287
|
},
|
|
2262
2288
|
onCopy: e => {
|
|
2263
|
-
if (editingKey === '') {
|
|
2289
|
+
if (editingKey.current === '') {
|
|
2264
2290
|
handleCopy(e);
|
|
2265
2291
|
e.preventDefault();
|
|
2266
2292
|
}
|
|
2267
2293
|
},
|
|
2268
2294
|
onPaste: event => {
|
|
2269
|
-
if (editingKey === '') {
|
|
2295
|
+
if (editingKey.current === '') {
|
|
2270
2296
|
handlePaste(dataSource[0], colIndex, 0, event);
|
|
2271
2297
|
event.preventDefault();
|
|
2272
2298
|
}
|
|
@@ -2282,18 +2308,12 @@ const GridEdit = props => {
|
|
|
2282
2308
|
const cellFormat = getFormat(colFormat, format);
|
|
2283
2309
|
const rowError = dataErrors.find(it => it.index === rowNumber);
|
|
2284
2310
|
const cellError = rowError && column.field && rowError[column.field]?.field === column.field ? rowError[column.field] : null;
|
|
2285
|
-
|
|
2286
|
-
// const aaa = dataErrors.find((it) => column?.field && it[column.field].field === column.field && it.index === rowNumber)
|
|
2287
|
-
// const aaa = column.field && rowError && rowError[column.field]?.field === column?.field
|
|
2288
|
-
|
|
2289
2311
|
return /*#__PURE__*/React.createElement("div", {
|
|
2290
2312
|
className: classNames('ui-rc_cell-content', {
|
|
2291
|
-
// disable: !isEditable(column as any, record)
|
|
2292
2313
|
isValid: column.field && rowError && rowError[column.field]?.field === column?.field
|
|
2293
2314
|
}),
|
|
2294
2315
|
onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
|
|
2295
2316
|
onMouseEnter: event => {
|
|
2296
|
-
// setTooltipContent(cellError ? cellError.message : renderContent(column as any, value, record, rowIndex, cellFormat))
|
|
2297
2317
|
setTooltipContent(cellError ? cellError.message : '');
|
|
2298
2318
|
handleMouseEnter(rowNumber, colIndex, event);
|
|
2299
2319
|
},
|
|
@@ -2304,20 +2324,9 @@ const GridEdit = props => {
|
|
|
2304
2324
|
isDragMouse.current = true;
|
|
2305
2325
|
}
|
|
2306
2326
|
}
|
|
2307
|
-
|
|
2308
|
-
// onClick={(event) => {
|
|
2309
|
-
//
|
|
2310
|
-
// handleClickCell(event)
|
|
2311
|
-
//
|
|
2312
|
-
// }}
|
|
2313
2327
|
}, /*#__PURE__*/React.createElement("div", {
|
|
2314
2328
|
className: 'ui-rc_content'
|
|
2315
|
-
}, renderContent(column, value, record, rowIndex, cellFormat)),
|
|
2316
|
-
// selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
|
|
2317
|
-
// getLastSelectCell(selectedCells.current).col === colIndex &&
|
|
2318
|
-
// isEditable(column as any, record) &&
|
|
2319
|
-
|
|
2320
|
-
!isDragMouse.current && /*#__PURE__*/React.createElement("div", {
|
|
2329
|
+
}, renderContent(column, value, record, rowIndex, cellFormat)), !isDragMouse.current && /*#__PURE__*/React.createElement("div", {
|
|
2321
2330
|
className: 'dragging-point hidden',
|
|
2322
2331
|
onMouseDown: e => {
|
|
2323
2332
|
// e.stopPropagation()
|
|
@@ -2408,7 +2417,8 @@ const GridEdit = props => {
|
|
|
2408
2417
|
items: toolbarItemsBottom ?? [],
|
|
2409
2418
|
mode: 'scroll',
|
|
2410
2419
|
onClick: ({}) => {
|
|
2411
|
-
|
|
2420
|
+
editingKey.current = '';
|
|
2421
|
+
// setEditingKey('')
|
|
2412
2422
|
}
|
|
2413
2423
|
}));
|
|
2414
2424
|
};
|