es-grid-template 1.2.4 → 1.2.5
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/EditableCell.js +3 -1
- package/es/grid-component/InternalTable.js +2 -2
- package/es/grid-component/hooks/utils.d.ts +1 -0
- package/es/grid-component/hooks/utils.js +6 -0
- package/es/grid-component/table/GridEdit.js +5 -3
- package/es/grid-component/type.d.ts +3 -1
- package/lib/grid-component/EditableCell.js +2 -1
- package/lib/grid-component/InternalTable.js +2 -2
- package/lib/grid-component/hooks/utils.d.ts +1 -0
- package/lib/grid-component/hooks/utils.js +9 -2
- package/lib/grid-component/table/GridEdit.js +4 -2
- package/lib/grid-component/type.d.ts +3 -1
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ import { checkDecimalSeparator, checkThousandSeparator, checkFieldKey, convertAr
|
|
|
6
6
|
convertLabelToTitle,
|
|
7
7
|
// customWeekStartEndFormat,
|
|
8
8
|
getDatepickerFormat, getTemplate, isDisable, isEmpty, isNullOrUndefined, customWeekStartEndFormat, convertDayjsToDate, parseBooleanToValue, isColor, genPresets
|
|
9
|
+
// isEditable,
|
|
9
10
|
// convertDayjsToDate
|
|
10
11
|
} from "./hooks";
|
|
11
12
|
// import moment from "moment";
|
|
@@ -79,10 +80,11 @@ const EditableCell = props => {
|
|
|
79
80
|
toolbarClick,
|
|
80
81
|
loadOptions,
|
|
81
82
|
validateOption,
|
|
82
|
-
options:
|
|
83
|
+
options: propsOptions
|
|
83
84
|
} = column.editSelectSettings || {};
|
|
84
85
|
const isInvalid = false;
|
|
85
86
|
const keySelect = checkFieldKey(column?.editSelectSettings?.fieldKey);
|
|
87
|
+
const selectOptions = typeof propsOptions === 'function' ? propsOptions(record, column.dataIndex) : propsOptions;
|
|
86
88
|
const options = validateOption ? validateOption(record, column.dataIndex) : selectOptions ?? [];
|
|
87
89
|
const optionsTree = validateOption ? convertArrayWithIndent(validateOption(record, column.dataIndex)) : selectOptions ? convertArrayWithIndent(selectOptions) : [];
|
|
88
90
|
switch (editType) {
|
|
@@ -148,9 +148,9 @@ const InternalTable = props => {
|
|
|
148
148
|
}, [rowKey]);
|
|
149
149
|
|
|
150
150
|
// const triggerChangeColumns = (newColumns: ColumnsTable<RecordType>) => {
|
|
151
|
-
const triggerChangeColumns = newColumns => {
|
|
151
|
+
const triggerChangeColumns = (newColumns, type) => {
|
|
152
152
|
setColumns(newColumns);
|
|
153
|
-
if (tableRef.current) {
|
|
153
|
+
if (tableRef.current && type === 'columnChoose') {
|
|
154
154
|
tableRef.current.scrollTo({
|
|
155
155
|
left: 0.1,
|
|
156
156
|
behavior: "smooth"
|
|
@@ -68,3 +68,4 @@ export declare const removeColumns: <RecordType>(columns: ColumnsTable<RecordTyp
|
|
|
68
68
|
export declare const convertFlatColumn: (array: ColumnsTable) => ColumnsTable[];
|
|
69
69
|
export declare const convertColumns: <RecordType>(cols: ColumnsTable<RecordType>) => ColumnsTable<RecordType>;
|
|
70
70
|
export declare const checkChild: (inputArray: any[]) => boolean;
|
|
71
|
+
export declare const isEditable: <RecordType>(column: ColumnEditType, rowData: RecordType) => boolean | ((rowData: any) => boolean);
|
|
@@ -772,4 +772,10 @@ export const convertColumns = cols => {
|
|
|
772
772
|
};
|
|
773
773
|
export const checkChild = inputArray => {
|
|
774
774
|
return inputArray.some(item => item.children && item.children.length > 0);
|
|
775
|
+
};
|
|
776
|
+
export const isEditable = (column, rowData) => {
|
|
777
|
+
if (column && typeof column.editEnable === 'function') {
|
|
778
|
+
return column.editEnable(rowData);
|
|
779
|
+
}
|
|
780
|
+
return column?.editEnable;
|
|
775
781
|
};
|
|
@@ -13,7 +13,7 @@ import dayjs from "dayjs";
|
|
|
13
13
|
import 'dayjs/locale/es';
|
|
14
14
|
import 'dayjs/locale/vi';
|
|
15
15
|
import TableGrid from "../TableGrid";
|
|
16
|
-
import { addRows8, checkChild, findAllChildrenKeys, findItemByKey, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, isObjEmpty, newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
|
|
16
|
+
import { addRows8, checkChild, findAllChildrenKeys, findItemByKey, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, isEditable, isObjEmpty, newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
|
|
17
17
|
import Message from "../../Message/Message";
|
|
18
18
|
|
|
19
19
|
// import Command from "../Command";
|
|
@@ -49,6 +49,7 @@ const GridEdit = props => {
|
|
|
49
49
|
defaultValue,
|
|
50
50
|
expandable,
|
|
51
51
|
onCellClick,
|
|
52
|
+
rowEditable,
|
|
52
53
|
...rest
|
|
53
54
|
} = props;
|
|
54
55
|
const {
|
|
@@ -1365,7 +1366,8 @@ const GridEdit = props => {
|
|
|
1365
1366
|
title: getValueCell(column, record[column.field], format),
|
|
1366
1367
|
'data-col-index': colIndex,
|
|
1367
1368
|
'data-row-index': rowNumber,
|
|
1368
|
-
editing: isEditing(record),
|
|
1369
|
+
editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record) !== false,
|
|
1370
|
+
// editing: isEditing(record) && rowEditable?.(record) !== false,
|
|
1369
1371
|
tabIndex: (rowIndex ?? 0) * columns.length + colIndex,
|
|
1370
1372
|
style: isPasteDragging ? {
|
|
1371
1373
|
cursor: "crosshair"
|
|
@@ -1384,7 +1386,7 @@ const GridEdit = props => {
|
|
|
1384
1386
|
onMouseUp: handleMouseUp
|
|
1385
1387
|
}, /*#__PURE__*/React.createElement("div", {
|
|
1386
1388
|
className: 'ui-rc_content'
|
|
1387
|
-
}, renderContent(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && getLastSelectCell(selectedCells).row === rowNumber && getLastSelectCell(selectedCells).col === colIndex && !isSelectDragging &&
|
|
1389
|
+
}, renderContent(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && getLastSelectCell(selectedCells).row === rowNumber && getLastSelectCell(selectedCells).col === colIndex && isEditable(column, record) !== false && !isSelectDragging &&
|
|
1388
1390
|
/*#__PURE__*/
|
|
1389
1391
|
// showDraggingPoint &&
|
|
1390
1392
|
React.createElement("div", {
|
|
@@ -46,7 +46,7 @@ export type ColumnSelectTable = {
|
|
|
46
46
|
};
|
|
47
47
|
export type IEditSelectSettings = {
|
|
48
48
|
fieldKey?: string;
|
|
49
|
-
options: any[];
|
|
49
|
+
options: any[] | ((rowData: any, field: string) => any[]);
|
|
50
50
|
/** get value form other field **/
|
|
51
51
|
fieldValue?: string;
|
|
52
52
|
/** get label form other field **/
|
|
@@ -114,6 +114,7 @@ export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTempl
|
|
|
114
114
|
export type ColumnEditType<RecordType = AnyObject> = Omit<ColumnType<RecordType>, 'children'> & {
|
|
115
115
|
editType?: EditType | ((rowData?: RecordType) => EditType);
|
|
116
116
|
disable?: boolean | ((rowData: any) => boolean);
|
|
117
|
+
editEnable?: boolean | ((rowData: any) => boolean);
|
|
117
118
|
isClearable?: boolean;
|
|
118
119
|
maxDate?: any;
|
|
119
120
|
minDate?: any;
|
|
@@ -185,6 +186,7 @@ export interface TableEditProps<RecordType = AnyObject> extends Omit<TableProps<
|
|
|
185
186
|
onCellPaste?: ICellPasteModel<RecordType>;
|
|
186
187
|
onCellChange?: (args: CellChangeArgs<RecordType>, handleCallback: (rowData: any, index: any, value?: any) => void) => void;
|
|
187
188
|
onCellClick?: (args: ICellClick, callback?: any) => void;
|
|
189
|
+
rowEditable?: (rowData: RecordType) => boolean;
|
|
188
190
|
}
|
|
189
191
|
export type ICellClick = {
|
|
190
192
|
index: number;
|
|
@@ -81,10 +81,11 @@ const EditableCell = props => {
|
|
|
81
81
|
toolbarClick,
|
|
82
82
|
loadOptions,
|
|
83
83
|
validateOption,
|
|
84
|
-
options:
|
|
84
|
+
options: propsOptions
|
|
85
85
|
} = column.editSelectSettings || {};
|
|
86
86
|
const isInvalid = false;
|
|
87
87
|
const keySelect = (0, _hooks.checkFieldKey)(column?.editSelectSettings?.fieldKey);
|
|
88
|
+
const selectOptions = typeof propsOptions === 'function' ? propsOptions(record, column.dataIndex) : propsOptions;
|
|
88
89
|
const options = validateOption ? validateOption(record, column.dataIndex) : selectOptions ?? [];
|
|
89
90
|
const optionsTree = validateOption ? (0, _hooks.convertArrayWithIndent)(validateOption(record, column.dataIndex)) : selectOptions ? (0, _hooks.convertArrayWithIndent)(selectOptions) : [];
|
|
90
91
|
switch (editType) {
|
|
@@ -151,9 +151,9 @@ const InternalTable = props => {
|
|
|
151
151
|
}, [rowKey]);
|
|
152
152
|
|
|
153
153
|
// const triggerChangeColumns = (newColumns: ColumnsTable<RecordType>) => {
|
|
154
|
-
const triggerChangeColumns = newColumns => {
|
|
154
|
+
const triggerChangeColumns = (newColumns, type) => {
|
|
155
155
|
setColumns(newColumns);
|
|
156
|
-
if (tableRef.current) {
|
|
156
|
+
if (tableRef.current && type === 'columnChoose') {
|
|
157
157
|
tableRef.current.scrollTo({
|
|
158
158
|
left: 0.1,
|
|
159
159
|
behavior: "smooth"
|
|
@@ -68,3 +68,4 @@ export declare const removeColumns: <RecordType>(columns: ColumnsTable<RecordTyp
|
|
|
68
68
|
export declare const convertFlatColumn: (array: ColumnsTable) => ColumnsTable[];
|
|
69
69
|
export declare const convertColumns: <RecordType>(cols: ColumnsTable<RecordType>) => ColumnsTable<RecordType>;
|
|
70
70
|
export declare const checkChild: (inputArray: any[]) => boolean;
|
|
71
|
+
export declare const isEditable: <RecordType>(column: ColumnEditType, rowData: RecordType) => boolean | ((rowData: any) => boolean);
|
|
@@ -10,7 +10,7 @@ exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.conve
|
|
|
10
10
|
exports.findAllChildrenKeys = findAllChildrenKeys;
|
|
11
11
|
exports.getFirstSelectCell = exports.getEditType = exports.getDefaultValue = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = exports.findItemByKey = void 0;
|
|
12
12
|
exports.getHiddenParentKeys = getHiddenParentKeys;
|
|
13
|
-
exports.updateData = exports.updateColumnsByGroup = exports.updateColumns = exports.updateArrayByKey = exports.transformColumns1 = exports.transformColumns = exports.totalFixedWidth = exports.sumDataByField = exports.removeColumns = exports.parseBooleanToValue = exports.newGuid = exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isEmpty = exports.isDisable = exports.isColor = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTemplate = exports.getRowsPasteIndex = exports.getRowNumber = exports.getLastSelectCell = void 0;
|
|
13
|
+
exports.updateData = exports.updateColumnsByGroup = exports.updateColumns = exports.updateArrayByKey = exports.transformColumns1 = exports.transformColumns = exports.totalFixedWidth = exports.sumDataByField = exports.removeColumns = exports.parseBooleanToValue = exports.newGuid = exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isEmpty = exports.isEditable = exports.isDisable = exports.isColor = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTemplate = exports.getRowsPasteIndex = exports.getRowNumber = exports.getLastSelectCell = void 0;
|
|
14
14
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
15
15
|
var _moment = _interopRequireDefault(require("moment/moment"));
|
|
16
16
|
var _uuid = require("uuid");
|
|
@@ -832,4 +832,11 @@ exports.convertColumns = convertColumns;
|
|
|
832
832
|
const checkChild = inputArray => {
|
|
833
833
|
return inputArray.some(item => item.children && item.children.length > 0);
|
|
834
834
|
};
|
|
835
|
-
exports.checkChild = checkChild;
|
|
835
|
+
exports.checkChild = checkChild;
|
|
836
|
+
const isEditable = (column, rowData) => {
|
|
837
|
+
if (column && typeof column.editEnable === 'function') {
|
|
838
|
+
return column.editEnable(rowData);
|
|
839
|
+
}
|
|
840
|
+
return column?.editEnable;
|
|
841
|
+
};
|
|
842
|
+
exports.isEditable = isEditable;
|
|
@@ -56,6 +56,7 @@ const GridEdit = props => {
|
|
|
56
56
|
defaultValue,
|
|
57
57
|
expandable,
|
|
58
58
|
onCellClick,
|
|
59
|
+
rowEditable,
|
|
59
60
|
...rest
|
|
60
61
|
} = props;
|
|
61
62
|
const {
|
|
@@ -1372,7 +1373,8 @@ const GridEdit = props => {
|
|
|
1372
1373
|
title: (0, _columns.getValueCell)(column, record[column.field], format),
|
|
1373
1374
|
'data-col-index': colIndex,
|
|
1374
1375
|
'data-row-index': rowNumber,
|
|
1375
|
-
editing: isEditing(record),
|
|
1376
|
+
editing: isEditing(record) && rowEditable?.(record) !== false && (0, _hooks.isEditable)(column, record) !== false,
|
|
1377
|
+
// editing: isEditing(record) && rowEditable?.(record) !== false,
|
|
1376
1378
|
tabIndex: (rowIndex ?? 0) * columns.length + colIndex,
|
|
1377
1379
|
style: isPasteDragging ? {
|
|
1378
1380
|
cursor: "crosshair"
|
|
@@ -1391,7 +1393,7 @@ const GridEdit = props => {
|
|
|
1391
1393
|
onMouseUp: handleMouseUp
|
|
1392
1394
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
1393
1395
|
className: 'ui-rc_content'
|
|
1394
|
-
}, (0, _columns.renderContent)(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && (0, _hooks.getLastSelectCell)(selectedCells).row === rowNumber && (0, _hooks.getLastSelectCell)(selectedCells).col === colIndex && !isSelectDragging &&
|
|
1396
|
+
}, (0, _columns.renderContent)(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && (0, _hooks.getLastSelectCell)(selectedCells).row === rowNumber && (0, _hooks.getLastSelectCell)(selectedCells).col === colIndex && (0, _hooks.isEditable)(column, record) !== false && !isSelectDragging &&
|
|
1395
1397
|
/*#__PURE__*/
|
|
1396
1398
|
// showDraggingPoint &&
|
|
1397
1399
|
_react.default.createElement("div", {
|
|
@@ -46,7 +46,7 @@ export type ColumnSelectTable = {
|
|
|
46
46
|
};
|
|
47
47
|
export type IEditSelectSettings = {
|
|
48
48
|
fieldKey?: string;
|
|
49
|
-
options: any[];
|
|
49
|
+
options: any[] | ((rowData: any, field: string) => any[]);
|
|
50
50
|
/** get value form other field **/
|
|
51
51
|
fieldValue?: string;
|
|
52
52
|
/** get label form other field **/
|
|
@@ -114,6 +114,7 @@ export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTempl
|
|
|
114
114
|
export type ColumnEditType<RecordType = AnyObject> = Omit<ColumnType<RecordType>, 'children'> & {
|
|
115
115
|
editType?: EditType | ((rowData?: RecordType) => EditType);
|
|
116
116
|
disable?: boolean | ((rowData: any) => boolean);
|
|
117
|
+
editEnable?: boolean | ((rowData: any) => boolean);
|
|
117
118
|
isClearable?: boolean;
|
|
118
119
|
maxDate?: any;
|
|
119
120
|
minDate?: any;
|
|
@@ -185,6 +186,7 @@ export interface TableEditProps<RecordType = AnyObject> extends Omit<TableProps<
|
|
|
185
186
|
onCellPaste?: ICellPasteModel<RecordType>;
|
|
186
187
|
onCellChange?: (args: CellChangeArgs<RecordType>, handleCallback: (rowData: any, index: any, value?: any) => void) => void;
|
|
187
188
|
onCellClick?: (args: ICellClick, callback?: any) => void;
|
|
189
|
+
rowEditable?: (rowData: RecordType) => boolean;
|
|
188
190
|
}
|
|
189
191
|
export type ICellClick = {
|
|
190
192
|
index: number;
|