react-table-edit 1.4.10 → 1.4.11
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/dist/component/edit-form/index.d.ts +1 -1
- package/dist/component/table/button-handle.d.ts +3 -3
- package/dist/index.js +107 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -22,13 +22,13 @@ type Props = {
|
|
|
22
22
|
menuWidth?: number;
|
|
23
23
|
rowData: any;
|
|
24
24
|
indexRow: any;
|
|
25
|
-
template?: any;
|
|
26
25
|
onKeyDown?: any;
|
|
27
26
|
defaultValues?: any;
|
|
28
27
|
schema?: InferType<any>;
|
|
29
28
|
onFormOpen?: (rowData: any, itemsField: FromItemsField[], setItemsField: Dispatch<SetStateAction<FromItemsField[]>>) => void;
|
|
30
29
|
onFormSubmit?: (rowData: any, setValue: UseFormSetValue<any>, getValues: UseFormGetValues<any>, reset: UseFormReset<any>) => void;
|
|
31
30
|
footerTemplate?: (rowData: any) => JSX.Element;
|
|
31
|
+
template?: (row: any, indexRow: number) => JSX.Element | string | number | undefined;
|
|
32
32
|
onChangeField?: (rowData: any, field: string, setValue: UseFormSetValue<any>, getValues: UseFormGetValues<any>) => void;
|
|
33
33
|
onChange: (rowData: any) => void;
|
|
34
34
|
onPaste?: (e: ClipboardEvent<HTMLInputElement>) => void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IFTableEditButton, IFTableEditPaging, IFTableEditToolbar } from "../type";
|
|
2
|
-
export declare const handleAdd: (dataSource: any[], tableElement: any, columnFistEdit: any, changeDataSource: (data: any[],
|
|
2
|
+
export declare const handleAdd: (dataSource: any[], tableElement: any, columnFistEdit: any, changeDataSource: (data: any[], numberOfRows?: number) => void, pagingSetting: {
|
|
3
3
|
setCurrentPage?: (page: number) => void;
|
|
4
4
|
pageSize?: number;
|
|
5
|
-
} | undefined, setIndexFocus: (item: number) => void, focusNewElement: (col: number, row: number, onLoad?: boolean) => void) => void;
|
|
5
|
+
} | undefined, setIndexFocus: (item: number) => void, focusNewElement: (col: number, row: number, onLoad?: boolean) => void, numberOfRows?: number) => void;
|
|
6
6
|
export declare const handleDuplicate: (dataSource: any[], indexFocus: number, fieldKey: string | undefined, defaultValue: any, fieldUniKey: string[], changeDataSource: (data: any[]) => void, tableElement: any, totalCount: number, toolbarSetting?: IFTableEditToolbar, buttonSetting?: IFTableEditButton, editDisable?: boolean, addDisable?: boolean, onDuplicate?: (newData: any, index: number) => void, // sự kiện khi duplicate
|
|
7
7
|
pagingClient?: boolean, pagingSetting?: IFTableEditPaging) => Promise<void>;
|
|
8
8
|
export declare const handleInsertAfter: (dataSource: any[], indexFocus: number, defaultValue: any, changeDataSource: (data: any[]) => void, tableElement: any, totalCount: number, pagingClient?: boolean, pagingSetting?: IFTableEditPaging, toolbarSetting?: IFTableEditToolbar, buttonSetting?: IFTableEditButton, editDisable?: boolean, addDisable?: boolean) => void;
|
|
9
9
|
export declare const handleInsertBefore: (dataSource: any[], indexFocus: number, defaultValue: any, changeDataSource: (data: any[]) => void, pagingClient?: boolean, pagingSetting?: IFTableEditPaging, toolbarSetting?: IFTableEditToolbar, buttonSetting?: IFTableEditButton, editDisable?: boolean, addDisable?: boolean) => void;
|
|
10
|
-
export declare const handleDeleteAll: (t: any, messageBoxConfirmDelete: (t: any, callback: () => void, message: string) => void, setIndexFocus: (item: number) => void, changeDataSource: (data: any[]
|
|
10
|
+
export declare const handleDeleteAll: (t: any, messageBoxConfirmDelete: (t: any, callback: () => void, message: string) => void, setIndexFocus: (item: number) => void, changeDataSource: (data: any[]) => void, editDisable?: boolean, addDisable?: boolean, toolbarSetting?: IFTableEditToolbar, buttonSetting?: IFTableEditButton) => void;
|
package/dist/index.js
CHANGED
|
@@ -23061,12 +23061,13 @@ const SelectTableBox$1 = (props) => {
|
|
|
23061
23061
|
|
|
23062
23062
|
const defaultWidth = 200;
|
|
23063
23063
|
const EditForm = React$5.forwardRef((props, ref) => {
|
|
23064
|
-
const { id, field, displayValue, menuHeight, menuWidth, rowData, invalid, onChange, onChangeField, onKeyDown, defaultValues, placeholder, textAlign, schema, onFormOpen, onFormSubmit, footerTemplate, minWidth, onPaste, openOnFocus, isClearable, labelSize = 'label-small' } = props;
|
|
23064
|
+
const { id, field, displayValue, menuHeight, menuWidth, rowData, invalid, onChange, onChangeField, onKeyDown, defaultValues, placeholder, textAlign, schema, onFormOpen, onFormSubmit, footerTemplate, template, minWidth, onPaste, openOnFocus, isClearable, indexRow, labelSize = 'label-small' } = props;
|
|
23065
23065
|
const { innerWidth } = window;
|
|
23066
23066
|
const inputRef = React$5.useRef(null);
|
|
23067
23067
|
const editFormRef = React$5.useRef(null);
|
|
23068
23068
|
const buttonRef = React$5.useRef(null);
|
|
23069
23069
|
const [dropdownOpen, setDropdownOpen] = React$5.useState(false);
|
|
23070
|
+
const [isFocus, setIsFocus] = React$5.useState(false);
|
|
23070
23071
|
const [itemsField, setItemsField] = React$5.useState([]);
|
|
23071
23072
|
const { t } = reactI18next.useTranslation();
|
|
23072
23073
|
useOnClickOutside(editFormRef, () => {
|
|
@@ -23108,6 +23109,7 @@ const EditForm = React$5.forwardRef((props, ref) => {
|
|
|
23108
23109
|
else {
|
|
23109
23110
|
setDropdownOpen(true);
|
|
23110
23111
|
}
|
|
23112
|
+
inputRef?.current.focus();
|
|
23111
23113
|
};
|
|
23112
23114
|
const handleOnSubmit = (val) => {
|
|
23113
23115
|
closeMenu();
|
|
@@ -23221,7 +23223,26 @@ const EditForm = React$5.forwardRef((props, ref) => {
|
|
|
23221
23223
|
}
|
|
23222
23224
|
}) }));
|
|
23223
23225
|
};
|
|
23224
|
-
|
|
23226
|
+
React$5.useEffect(() => {
|
|
23227
|
+
if (inputRef) {
|
|
23228
|
+
inputRef.current.addEventListener('blur', function () {
|
|
23229
|
+
setIsFocus(false);
|
|
23230
|
+
});
|
|
23231
|
+
inputRef.current.addEventListener('focus', function () {
|
|
23232
|
+
if (!isFocus) {
|
|
23233
|
+
setIsFocus(true);
|
|
23234
|
+
}
|
|
23235
|
+
});
|
|
23236
|
+
}
|
|
23237
|
+
}, [inputRef]);
|
|
23238
|
+
return (jsxRuntime.jsx("div", { className: "form-edit", ref: ref, id: id, children: jsxRuntime.jsx("div", { ref: editFormRef, children: jsxRuntime.jsxs(Dropdown$1, { isOpen: dropdownOpen, toggle: () => { }, children: [jsxRuntime.jsx(DropdownToggle$1, { tag: 'div', children: jsxRuntime.jsxs("div", { className: classnames('display-value', { 'r-is-focus': isFocus || dropdownOpen }, { 'is-invalid': invalid }), onClick: handleOnClick, children: [template?.(rowData, indexRow) ?? displayValue, jsxRuntime.jsx(Input$1, { style: {
|
|
23239
|
+
width: template ? 0 : '100%',
|
|
23240
|
+
height: template ? 0 : 28,
|
|
23241
|
+
lineHeight: template ? 0 : 19,
|
|
23242
|
+
padding: template ? 0 : 'auto',
|
|
23243
|
+
backgroundColor: '#FFF',
|
|
23244
|
+
textAlign: textAlign ?? 'left'
|
|
23245
|
+
}, placeholder: placeholder, innerRef: inputRef, onKeyDown: (e) => handleOnKeyDown(e), onPaste: (e) => onPaste && onPaste(e), readOnly: true })] }) }), jsxRuntime.jsx(DropdownMenu$1, { className: 'formula-dropdown icon-dropdown p-0', style: {
|
|
23225
23246
|
minWidth: minWidth ? minWidth : defaultWidth,
|
|
23226
23247
|
width: menuWidth ? menuWidth : 'min-content',
|
|
23227
23248
|
maxWidth: innerWidth > 1280 ? 1280 : innerWidth,
|
|
@@ -41723,6 +41744,12 @@ const HeaderTableCol = (props) => {
|
|
|
41723
41744
|
if (size.width > 50) {
|
|
41724
41745
|
const newColumns = [...column];
|
|
41725
41746
|
newColumns[indexCol].width = size.width;
|
|
41747
|
+
if ((column[indexCol]?.maxWidth ?? 0) < size.width) {
|
|
41748
|
+
newColumns[indexCol].maxWidth = size.width;
|
|
41749
|
+
}
|
|
41750
|
+
if ((column[indexCol]?.minWidth ?? 0) > size.width) {
|
|
41751
|
+
newColumns[indexCol].minWidth = size.width;
|
|
41752
|
+
}
|
|
41726
41753
|
setColumn(newColumns);
|
|
41727
41754
|
}
|
|
41728
41755
|
};
|
|
@@ -41731,8 +41758,8 @@ const HeaderTableCol = (props) => {
|
|
|
41731
41758
|
left: col.fixedType === 'left' ? objWidthFix[col.index ?? 0] : undefined,
|
|
41732
41759
|
right: col.fixedType === 'right' ? objWidthFix[col.index ?? 0] : undefined,
|
|
41733
41760
|
width: col.width ? typeof col.width === 'number' ? col.width : col.width?.includes('px') || col.width?.includes('%') ? col.width : `${col.width}px` : 'auto',
|
|
41734
|
-
minWidth: col.width ? typeof col.
|
|
41735
|
-
maxWidth: col.width ? typeof col.
|
|
41761
|
+
minWidth: col.fixedType ? col.width : col.minWidth ? typeof col.minWidth === 'number' ? col.minWidth : col.minWidth?.includes('px') || col.minWidth?.includes('%') ? col.minWidth : `${col.minWidth}px` : 'auto',
|
|
41762
|
+
maxWidth: col.fixedType ? col.width : col.maxWidth ? typeof col.maxWidth === 'number' ? col.maxWidth : col.maxWidth?.includes('px') || col.maxWidth?.includes('%') ? col.maxWidth : `${col.maxWidth}px` : 'auto'
|
|
41736
41763
|
}, children: jsxRuntime.jsxs("div", { style: { justifyContent: col.textAlign ?? 'left' }, className: classnames('r-headercell-div'), children: [col.field === 'checkbox' && (jsxRuntime.jsx(Input$1, { checked: totalCount > 0 && selectedRows?.length >= totalCount, type: "checkbox", className: classnames('cursor-pointer', { 'd-none': !isMulti }), style: { textAlign: col.textAlign ?? 'left', marginTop: 6 }, onChange: (e) => {
|
|
41737
41764
|
if (selectEnable) {
|
|
41738
41765
|
if (e.target.checked) {
|
|
@@ -42136,11 +42163,11 @@ const RenderToolbarTop = ({ toolbarTopOption }) => {
|
|
|
42136
42163
|
|
|
42137
42164
|
const handleAdd = (dataSource, tableElement, columnFistEdit,
|
|
42138
42165
|
/*eslint-disable*/
|
|
42139
|
-
changeDataSource, pagingSetting, setIndexFocus, focusNewElement
|
|
42166
|
+
changeDataSource, pagingSetting, setIndexFocus, focusNewElement,
|
|
42140
42167
|
/*eslint-enable*/
|
|
42141
|
-
) => {
|
|
42168
|
+
numberOfRows) => {
|
|
42142
42169
|
const lengthData = dataSource.length;
|
|
42143
|
-
changeDataSource(dataSource,
|
|
42170
|
+
changeDataSource(dataSource, numberOfRows ?? 1);
|
|
42144
42171
|
if (pagingSetting?.setCurrentPage) {
|
|
42145
42172
|
pagingSetting?.setCurrentPage(Math.floor(lengthData / (pagingSetting?.pageSize ?? 0)) + 1);
|
|
42146
42173
|
}
|
|
@@ -42224,14 +42251,14 @@ editDisable, addDisable, toolbarSetting, buttonSetting) => {
|
|
|
42224
42251
|
messageBoxConfirmDelete(t, () => {
|
|
42225
42252
|
if (!editDisable && !addDisable) {
|
|
42226
42253
|
setIndexFocus(-1);
|
|
42227
|
-
changeDataSource([]
|
|
42254
|
+
changeDataSource([]);
|
|
42228
42255
|
}
|
|
42229
42256
|
}, '');
|
|
42230
42257
|
}
|
|
42231
42258
|
};
|
|
42232
42259
|
|
|
42233
42260
|
const ToolbarBottom = ({ handleAdd, handleDuplicate, handleInsertBefore, handleInsertAfter, handleDeleteAll, setOpenPopupSetupColumn, indexFocus, editDisable, addDisable, buttonSetting, toolbarSetting, headerColumns, t }) => {
|
|
42234
|
-
return (jsxRuntime.jsx("div", { id: "table_custom_bottom_toolbar", className: "r-toolbar r-toolbar-bottom", role: "toolbar", "aria-disabled": "false", "aria-haspopup": "false", "aria-orientation": "horizontal", children: jsxRuntime.jsxs("div", { className: "r-toolbar-items", children: [jsxRuntime.jsxs("div", { className: "r-toolbar-left", children: [jsxRuntime.
|
|
42261
|
+
return (jsxRuntime.jsx("div", { id: "table_custom_bottom_toolbar", className: "r-toolbar r-toolbar-bottom", role: "toolbar", "aria-disabled": "false", "aria-haspopup": "false", "aria-orientation": "horizontal", children: jsxRuntime.jsxs("div", { className: "r-toolbar-items", children: [jsxRuntime.jsxs("div", { className: "r-toolbar-left", children: [jsxRuntime.jsxs("div", { className: classnames('r-toolbar-item d-flex', { 'd-none': editDisable || addDisable }), "aria-disabled": "false", children: [jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: () => handleAdd(1), className: 'd-flex', children: t('Add item') }), jsxRuntime.jsxs(UncontrolledDropdown, { className: 'nav-item', children: [jsxRuntime.jsx(DropdownToggle$1, { tag: 'div', className: 'me-0 d-flex', children: jsxRuntime.jsx(Button$1, { type: 'button', color: 'success', outline: true, style: { marginLeft: -1 }, className: 'px-25', children: jsxRuntime.jsx("svg", { fill: '#28c76f', height: "15", width: "20", viewBox: "0 0 20 20", children: jsxRuntime.jsx("path", { d: "M4.516 7.548c0.436-0.446 1.043-0.481 1.576 0l3.908 3.747 3.908-3.747c0.533-0.481 1.141-0.446 1.574 0 0.436 0.445 0.408 1.197 0 1.615-0.406 0.418-4.695 4.502-4.695 4.502-0.217 0.223-0.502 0.335-0.787 0.335s-0.57-0.112-0.789-0.335c0 0-4.287-4.084-4.695-4.502s-0.436-1.17 0-1.615z" }) }) }) }), jsxRuntime.jsxs(DropdownMenu$1, { className: 'formula-dropdown icon-dropdown p-0', style: { width: 60 }, children: [jsxRuntime.jsx(DropdownItem$1, { className: 'py-25', tag: 'div', onClick: () => handleAdd(10), children: " 10 " }), jsxRuntime.jsx(DropdownItem$1, { className: 'py-25', tag: 'div', onClick: () => handleAdd(20), children: " 20 " }), jsxRuntime.jsx(DropdownItem$1, { className: 'py-25', tag: 'div', onClick: () => handleAdd(30), children: " 30 " }), jsxRuntime.jsx(DropdownItem$1, { className: 'py-25', tag: 'div', onClick: () => handleAdd(40), children: " 40 " }), jsxRuntime.jsx(DropdownItem$1, { className: 'py-25', tag: 'div', onClick: () => handleAdd(50), children: " 50 " })] })] })] }), (indexFocus ?? -1) > -1 ? jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.duplicateDisable }), "aria-disabled": "false", children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: () => { handleDuplicate(); }, className: 'd-flex', children: t('Duplicate') }) }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.insertBeforeDisable }), "aria-disabled": "false", children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: handleInsertBefore, className: 'd-flex', children: t('Insert item before') }) }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.insertAfterDisable }), "aria-disabled": "false", children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: handleInsertAfter, className: 'd-flex', children: t('Insert item after') }) })] }) : jsxRuntime.jsx(jsxRuntime.Fragment, { children: " " }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || buttonSetting?.deleteAllDisable }), "aria-disabled": "false", children: jsxRuntime.jsx(Button$1, { color: 'primary', outline: true, onClick: handleDeleteAll, className: 'd-flex', children: t('Delete all item') }) }), toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
|
|
42235
42262
|
return ((item.align === 'left') ? jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-left-${index}`) : '');
|
|
42236
42263
|
})] }), jsxRuntime.jsx("div", { className: "r-toolbar-center", children: toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
|
|
42237
42264
|
return ((item.align === 'center') ? jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-center-${index}`) : '');
|
|
@@ -42459,9 +42486,9 @@ const EditFormInline = React$5.forwardRef((props, ref) => {
|
|
|
42459
42486
|
onFormOpen(rowData, itemsField, setItemsField);
|
|
42460
42487
|
}
|
|
42461
42488
|
setOnFocus(true);
|
|
42462
|
-
}, onKeyDown: e => formKeyDown(e, handleSubmit), children: template ? template(rowData, indexRow) : displayValue }), jsxRuntime.jsx("div", { className: `form__edit ${onFocus ? 'active' : ''}`, onKeyDown: e => handleOnKeyDown(), children: itemsField.map((item, index) => {
|
|
42489
|
+
}, onKeyDown: e => formKeyDown(e, handleSubmit), children: template ? template(rowData, indexRow) : displayValue }), onFocus && jsxRuntime.jsx("div", { className: `form__edit ${onFocus ? 'active' : ''}`, style: { width: (itemsField?.length ?? 0) * 95 }, onKeyDown: e => handleOnKeyDown(), children: itemsField.map((item, index) => {
|
|
42463
42490
|
if (item.type === 'numeric') {
|
|
42464
|
-
return (jsxRuntime.jsx("div", { className: "form__element", onKeyDown: e => formItemKeyDown(e, index), children: jsxRuntime.jsx(NumberInput, { id: `form-element-${field}-${index}`, control: control, name: item.name, label: item.label ? item.label : '', labelSize: `${labelSize}`, errors: errors[item.name], disabled: item.disabled, min: item.min, max: item.max, inLine: false, fractionCurrency: item.fraction, callback: () => { elementChange(item.name); } }, index) }, index));
|
|
42491
|
+
return (jsxRuntime.jsx("div", { style: { minWidth: 90 }, className: "form__element", onKeyDown: e => formItemKeyDown(e, index), children: jsxRuntime.jsx(NumberInput, { id: `form-element-${field}-${index}`, control: control, name: item.name, label: item.label ? item.label : '', labelSize: `${labelSize}`, errors: errors[item.name], disabled: item.disabled, min: item.min, max: item.max, inLine: false, fractionCurrency: item.fraction, callback: () => { elementChange(item.name); } }, index) }, index));
|
|
42465
42492
|
}
|
|
42466
42493
|
else if (item.type === 'text') {
|
|
42467
42494
|
return (jsxRuntime.jsx("div", { className: "form__element", onKeyDown: e => formItemKeyDown(e, index), children: jsxRuntime.jsx(TextInput, { id: `form-element-${field}-${index}`, control: control, name: item.name, label: item.label ? item.label : '', labelSize: `${labelSize}`, inLine: false, errors: errors[item.name], disabled: item.disabled, callback: () => { elementChange(item.name); } }, index) }, index));
|
|
@@ -42648,7 +42675,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
42648
42675
|
else {
|
|
42649
42676
|
toolbarTopOption = [...defaultToolbarOption];
|
|
42650
42677
|
}
|
|
42651
|
-
const
|
|
42678
|
+
const RenderEditCell = (row, col, indexCol, indexRow) => {
|
|
42652
42679
|
/*eslint-disable */
|
|
42653
42680
|
switch (col?.editTypeCondition ? col?.editTypeCondition(row) : col.editType) {
|
|
42654
42681
|
case 'date':
|
|
@@ -42759,31 +42786,29 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
42759
42786
|
else {
|
|
42760
42787
|
valueSelectTree = (!isNullOrUndefined$1(row[col.field]) && row[col.field] !== '') ? findItemInTree(optionsSelectTree, row[col.field]) : '';
|
|
42761
42788
|
}
|
|
42762
|
-
return (jsxRuntime.jsx(
|
|
42789
|
+
return (jsxRuntime.jsx(SelectTableTree, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, value: valueSelectTree, options: optionsSelectTree, onChange: (val) => {
|
|
42790
|
+
if (col.selectSettings?.isMulti) {
|
|
42791
|
+
row[col.field] = !isNullOrUndefined$1(val) ? val : [];
|
|
42792
|
+
}
|
|
42793
|
+
else {
|
|
42794
|
+
row[col.field] = !isNullOrUndefined$1(val) ? val[col.selectSettings?.fieldValue ?? 'value'] : undefined;
|
|
42795
|
+
}
|
|
42796
|
+
if (col.callback) {
|
|
42797
|
+
col.callback(val, indexRow, row);
|
|
42798
|
+
}
|
|
42799
|
+
handleDataChange(row, col, indexRow);
|
|
42800
|
+
}, fieldValue: col.selectSettings?.fieldValue, fieldLabel: col.selectSettings?.fieldLabel, component: gridRef, columns: col.selectSettings?.columns, isClearable: col.selectSettings?.isClearable ?? false, formatSetting: formatSetting, placeholder: t('Select'), onOpenMenu: () => {
|
|
42801
|
+
if (col.selectSettings?.onOpenMenu) {
|
|
42802
|
+
col.selectSettings?.onOpenMenu(row, col, indexRow);
|
|
42803
|
+
}
|
|
42804
|
+
}, loadOptions: col.selectSettings?.loadOptions, handleAdd: col.selectSettings?.handAddNew ? (e) => col.selectSettings?.handAddNew(e, indexRow, row) : undefined, fieldChildren: col.selectSettings?.fieldChild ?? 'children', selectChilds: col.selectSettings?.selectChilds, showFooter: col.selectSettings?.showFooter, formatOptionLabel: col.selectSettings?.formatOptionLabel, footerComponent: col.selectSettings?.footerComponent, width: col.selectSettings?.widthPopup ? Number(col.selectSettings?.widthPopup) : undefined, isMulti: col.selectSettings?.isMulti, noHeader: col.selectSettings?.noHeader, invalid: col.validate && col.validate(row[col.field], row), maxHeight: col.selectSettings?.heightPopup ? Number(col.selectSettings?.heightPopup) : undefined, menuWidth: col.selectSettings?.widthPopup ? Number(col.selectSettings?.widthPopup) : undefined, textAlign: col.textAlign ?? 'left', onKeyDown: (e) => {
|
|
42763
42805
|
if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) ;
|
|
42764
|
-
},
|
|
42765
|
-
|
|
42766
|
-
|
|
42767
|
-
|
|
42768
|
-
|
|
42769
|
-
|
|
42770
|
-
}
|
|
42771
|
-
if (col.callback) {
|
|
42772
|
-
col.callback(val, indexRow, row);
|
|
42773
|
-
}
|
|
42774
|
-
handleDataChange(row, col, indexRow);
|
|
42775
|
-
}, fieldValue: col.selectSettings?.fieldValue, fieldLabel: col.selectSettings?.fieldLabel, component: gridRef, columns: col.selectSettings?.columns, isClearable: col.selectSettings?.isClearable ?? false, formatSetting: formatSetting, placeholder: t('Select'), onOpenMenu: () => {
|
|
42776
|
-
if (col.selectSettings?.onOpenMenu) {
|
|
42777
|
-
col.selectSettings?.onOpenMenu(row, col, indexRow);
|
|
42778
|
-
}
|
|
42779
|
-
}, loadOptions: col.selectSettings?.loadOptions, handleAdd: col.selectSettings?.handAddNew ? (e) => col.selectSettings?.handAddNew(e, indexRow, row) : undefined, fieldChildren: col.selectSettings?.fieldChild ?? 'children', selectChilds: col.selectSettings?.selectChilds, showFooter: col.selectSettings?.showFooter, formatOptionLabel: col.selectSettings?.formatOptionLabel, footerComponent: col.selectSettings?.footerComponent, width: col.selectSettings?.widthPopup ? Number(col.selectSettings?.widthPopup) : undefined, isMulti: col.selectSettings?.isMulti, noHeader: col.selectSettings?.noHeader, invalid: col.validate && col.validate(row[col.field], row), maxHeight: col.selectSettings?.heightPopup ? Number(col.selectSettings?.heightPopup) : undefined, menuWidth: col.selectSettings?.widthPopup ? Number(col.selectSettings?.widthPopup) : undefined, textAlign: col.textAlign ?? 'left', onKeyDown: (e) => {
|
|
42780
|
-
if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) ;
|
|
42781
|
-
}, onPaste: (e) => {
|
|
42782
|
-
if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
|
|
42783
|
-
pasteDataFromExcel(indexRow, indexCol, e);
|
|
42784
|
-
e.preventDefault();
|
|
42785
|
-
}
|
|
42786
|
-
} }) }));
|
|
42806
|
+
}, onPaste: (e) => {
|
|
42807
|
+
if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
|
|
42808
|
+
pasteDataFromExcel(indexRow, indexCol, e);
|
|
42809
|
+
e.preventDefault();
|
|
42810
|
+
}
|
|
42811
|
+
} }));
|
|
42787
42812
|
case 'checkbox':
|
|
42788
42813
|
return (jsxRuntime.jsx(Input$1, { checked: row[col.field], id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, type: "checkbox", className: "input-checkbox cursor-pointer", style: { textAlign: col.textAlign ?? 'left', marginTop: 6 }, onChange: (val) => {
|
|
42789
42814
|
row[col.field] = val.currentTarget.checked;
|
|
@@ -42848,7 +42873,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
42848
42873
|
return (jsxRuntime.jsx(EditForm, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, ...col.formSettings, field: col.field, displayValue: col.formSettings?.displayValue ? col.formSettings?.displayValue(row) : '', placeholder: col.placeholder ? t(col.placeholder) : '', rowData: row, indexRow: indexRow, onChange: (val) => {
|
|
42849
42874
|
Object.assign(row, val);
|
|
42850
42875
|
handleDataChange(row, col, indexRow);
|
|
42851
|
-
}, invalid: col.validate && col.validate(row[col.field], row), textAlign: col.textAlign, onKeyDown: (e) => {
|
|
42876
|
+
}, invalid: col.validate && col.validate(row[col.field], row), textAlign: col.textAlign, template: col.template, onKeyDown: (e) => {
|
|
42852
42877
|
return checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
|
|
42853
42878
|
}, onPaste: (e) => {
|
|
42854
42879
|
if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
|
|
@@ -42924,7 +42949,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
42924
42949
|
};
|
|
42925
42950
|
//Thêm dòng mới
|
|
42926
42951
|
const moveIndexRowToNewPage = () => {
|
|
42927
|
-
changeDataSource(dataSource,
|
|
42952
|
+
changeDataSource(dataSource, 1);
|
|
42928
42953
|
if (pagingClient && pagingSetting?.setCurrentPage && (totalCount % (pagingSetting?.pageSize ?? 0)) === 0) {
|
|
42929
42954
|
pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 0) + 1);
|
|
42930
42955
|
}
|
|
@@ -42991,13 +43016,13 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
42991
43016
|
}, 50);
|
|
42992
43017
|
});
|
|
42993
43018
|
const getColumn = (col, index) => {
|
|
42994
|
-
const column = contentColumns
|
|
43019
|
+
const column = contentColumns[col + index];
|
|
42995
43020
|
if (column) {
|
|
42996
43021
|
return { ...column };
|
|
42997
43022
|
}
|
|
42998
43023
|
return undefined;
|
|
42999
43024
|
};
|
|
43000
|
-
const pasteDataFromExcel = async (currenRowIndex,
|
|
43025
|
+
const pasteDataFromExcel = async (currenRowIndex, indexCol, e) => {
|
|
43001
43026
|
const clipboard = (e.clipboardData || window.Clipboard).getData('text');
|
|
43002
43027
|
const rowsClipboard = clipboard.trimEnd().split('\n');
|
|
43003
43028
|
setIndexFocus(-1);
|
|
@@ -43013,7 +43038,8 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43013
43038
|
stringData.push(element.trimEnd().split('\t')[index].toString().trim());
|
|
43014
43039
|
}
|
|
43015
43040
|
});
|
|
43016
|
-
const column = getColumn(
|
|
43041
|
+
const column = getColumn(indexCol, index);
|
|
43042
|
+
console.log(column);
|
|
43017
43043
|
if (column) {
|
|
43018
43044
|
if ((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + 0])) && column.editEnable && column.onPasteValidate) {
|
|
43019
43045
|
const rs = await column.onPasteValidate(stringData.join(','), currenRowIndex + 0, dataSource[currenRowIndex + 0]);
|
|
@@ -43090,8 +43116,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43090
43116
|
}
|
|
43091
43117
|
}
|
|
43092
43118
|
else if (column.editType === 'select') {
|
|
43093
|
-
|
|
43094
|
-
if (rs) {
|
|
43119
|
+
if (column.selectSettings?.allowCreate) {
|
|
43095
43120
|
if (column.onPaste) {
|
|
43096
43121
|
dataRow[column.field] = column.onPaste(dataRow, stringData);
|
|
43097
43122
|
}
|
|
@@ -43099,11 +43124,25 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43099
43124
|
dataRow[column.field] = stringData;
|
|
43100
43125
|
}
|
|
43101
43126
|
if (column.callback) {
|
|
43102
|
-
column.callback(
|
|
43127
|
+
column.callback(stringData, currenRowIndex + indexRow);
|
|
43103
43128
|
}
|
|
43104
43129
|
}
|
|
43105
43130
|
else {
|
|
43106
|
-
|
|
43131
|
+
const rs = ((column.selectSettings?.optionsField ? item[column.selectSettings?.optionsField] : column.selectSettings?.options) ?? []).find((item) => item[column.selectSettings?.fieldValue ?? 'value'] === stringData);
|
|
43132
|
+
if (rs) {
|
|
43133
|
+
if (column.onPaste) {
|
|
43134
|
+
dataRow[column.field] = column.onPaste(dataRow, stringData);
|
|
43135
|
+
}
|
|
43136
|
+
else {
|
|
43137
|
+
dataRow[column.field] = stringData;
|
|
43138
|
+
}
|
|
43139
|
+
if (column.callback) {
|
|
43140
|
+
column.callback(rs, currenRowIndex + indexRow);
|
|
43141
|
+
}
|
|
43142
|
+
}
|
|
43143
|
+
else {
|
|
43144
|
+
notificationError(t('PasteExcelNotExist', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
|
|
43145
|
+
}
|
|
43107
43146
|
}
|
|
43108
43147
|
}
|
|
43109
43148
|
else {
|
|
@@ -43128,7 +43167,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43128
43167
|
}
|
|
43129
43168
|
changeDataSource(dataSource);
|
|
43130
43169
|
};
|
|
43131
|
-
const changeDataSource = (data,
|
|
43170
|
+
const changeDataSource = (data, numberOfRows) => {
|
|
43132
43171
|
if (!editDisable && setDataSource) {
|
|
43133
43172
|
if ((searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm)) {
|
|
43134
43173
|
if (searchSetting?.setSearchTerm) {
|
|
@@ -43138,8 +43177,10 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43138
43177
|
setSearchTerm('');
|
|
43139
43178
|
}
|
|
43140
43179
|
}
|
|
43141
|
-
if (
|
|
43142
|
-
|
|
43180
|
+
if (numberOfRows && !addDisable) {
|
|
43181
|
+
for (let index = 0; index < numberOfRows; index++) {
|
|
43182
|
+
data.push(defaultValue ? { ...defaultValue, [fieldKey]: disableAutoKey ? undefined : generateUUID() } : {});
|
|
43183
|
+
}
|
|
43143
43184
|
setDataSource([...data]);
|
|
43144
43185
|
}
|
|
43145
43186
|
else {
|
|
@@ -43242,9 +43283,8 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43242
43283
|
else if (col.field === 'checkbox') {
|
|
43243
43284
|
return (jsxRuntime.jsx("td", { className: classnames(`r-rowcell p-0 fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || indexFocus === indexRow }), style: {
|
|
43244
43285
|
left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
|
|
43245
|
-
right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined
|
|
43246
|
-
|
|
43247
|
-
}, children: jsxRuntime.jsx("div", { className: "r-rowcell-div cursor-pointer", onClick: (e) => {
|
|
43286
|
+
right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined
|
|
43287
|
+
}, children: jsxRuntime.jsx("div", { className: "r-rowcell-div cursor-pointer", style: { alignItems: 'center' }, onClick: (e) => {
|
|
43248
43288
|
if (selectEnable) {
|
|
43249
43289
|
const index = selectedRows?.findIndex((x) => x[fieldKey] === row[fieldKey]);
|
|
43250
43290
|
if (index > -1) {
|
|
@@ -43266,7 +43306,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43266
43306
|
}
|
|
43267
43307
|
e.stopPropagation();
|
|
43268
43308
|
}
|
|
43269
|
-
}, children: jsxRuntime.jsx(Input$1, { checked: isSelected, type: "checkbox", className: "cursor-pointer",
|
|
43309
|
+
}, children: jsxRuntime.jsx(Input$1, { checked: isSelected, type: "checkbox", className: "cursor-pointer", style: { textAlign: col.textAlign ?? 'center' } }) }) }, `col-${indexRow}-${indexCol}`));
|
|
43270
43310
|
}
|
|
43271
43311
|
else {
|
|
43272
43312
|
let value = row[col.field];
|
|
@@ -43314,8 +43354,20 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43314
43354
|
}
|
|
43315
43355
|
}, children: jsxRuntime.jsx("div", { className: classnames('r-rowcell-div'), children: jsxRuntime.jsxs("div", { id: indexFocus === indexRow && typeDis !== 1 ? `${idTable}-col${indexCol + 1}-row${indexRow + 1}` : '', className: classnames('r-rowcell-content', { 'r-is-invalid': errorMessage }), style: {
|
|
43316
43356
|
textAlign: col.textAlign ? col.textAlign : 'left'
|
|
43317
|
-
}, children: [typeDis === 1 && !refreshRow
|
|
43357
|
+
}, children: [typeDis === 1 && !refreshRow && jsxRuntime.jsx(jsxRuntime.Fragment, { children: RenderEditCell(row, col, indexCol, indexRow) }), (typeDis !== 1 || refreshRow) && RenderContentCell(row, col, indexCol, indexRow, typeDis, value), jsxRuntime.jsx("span", { id: `error-${indexRow}-${indexCol}`, className: classnames('cursor-pointer text-primary icon-table', { 'd-none': !errorMessage }), children: jsxRuntime.jsx(SvgAlertCircle, { fontSize: 15.5 }) }), jsxRuntime.jsx(UncontrolledTooltip, { target: `error-${indexRow}-${indexCol}`, className: "r-tooltip tooltip-error", children: errorMessage?.toString() ?? '' })] }) }) }, `col-${indexRow}-${indexCol}`) }, indexCol));
|
|
43358
|
+
}
|
|
43359
|
+
};
|
|
43360
|
+
const RenderContentCell = (row, col, indexCol, indexRow, typeDis, value) => {
|
|
43361
|
+
if (typeDis === 2) {
|
|
43362
|
+
const value = col.template?.(row, indexRow) ?? '';
|
|
43363
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
43364
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { id: `content-${idTable}-row${indexRow}col-${indexCol}`, className: "r-cell-text", children: value }), (!refreshRow && typeDis !== 2) && jsxRuntime.jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `content-${idTable}-row${indexRow}col-${indexCol}`, children: (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxRuntime.jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) })] }));
|
|
43365
|
+
}
|
|
43366
|
+
else {
|
|
43367
|
+
return value;
|
|
43368
|
+
}
|
|
43318
43369
|
}
|
|
43370
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { id: `content-${idTable}-row${indexRow}col-${indexCol}`, className: "r-cell-text", children: (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxRuntime.jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), (!(typeDis === 1 && !refreshRow) && typeDis !== 2) && jsxRuntime.jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `content-${idTable}-row${indexRow}col-${indexCol}`, children: (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxRuntime.jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) })] }));
|
|
43319
43371
|
};
|
|
43320
43372
|
const renderFooterCol = (col, indexCol) => {
|
|
43321
43373
|
const sumValue = (col.haveSum === true && col.editType === "numeric") ? dataSource.reduce(function (accumulator, currentValue) { return (Number(accumulator ?? 0) + Number(currentValue[col.field] ?? 0)); }, 0) : 0;
|
|
@@ -43358,8 +43410,8 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43358
43410
|
}) }, `header-${-indexParent}`));
|
|
43359
43411
|
}) }), jsxRuntime.jsx("tbody", { className: 'r-gridcontent', children: renderData() }), jsxRuntime.jsx("tfoot", { className: "r-gridfoot", children: haveSum == true ? jsxRuntime.jsx("tr", { className: 'r-row', children: contentColumns.map((col, index) => {
|
|
43360
43412
|
return (renderFooterCol(col, index));
|
|
43361
|
-
}) }) : jsxRuntime.jsx(jsxRuntime.Fragment, {}) })] }) }), toolbarSetting?.showBottomToolbar && jsxRuntime.jsx(ToolbarBottom, { handleAdd: () => {
|
|
43362
|
-
handleAdd(dataSource, tableElement.current, columnFistEdit, changeDataSource, pagingSetting, setIndexFocus, focusNewElement);
|
|
43413
|
+
}) }) : jsxRuntime.jsx(jsxRuntime.Fragment, {}) })] }) }), toolbarSetting?.showBottomToolbar && jsxRuntime.jsx(ToolbarBottom, { handleAdd: (numberOfRows) => {
|
|
43414
|
+
handleAdd(dataSource, tableElement.current, columnFistEdit, changeDataSource, pagingSetting, setIndexFocus, focusNewElement, numberOfRows);
|
|
43363
43415
|
}, handleDuplicate: () => {
|
|
43364
43416
|
handleDuplicate(dataSource, indexFocus, fieldKey, defaultValue, fieldUniKey, changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate);
|
|
43365
43417
|
}, handleInsertAfter: () => {
|