react-table-edit 1.4.23 → 1.4.25
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/table/header.d.ts +15 -5
- package/dist/component/table/index.d.ts +3 -0
- package/dist/component/type/index.d.ts +12 -0
- package/dist/component/utils.d.ts +4 -0
- package/dist/component/virtualized-table/index.d.ts +1 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +199 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +199 -145
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19318,6 +19318,8 @@ const calculateTableStructure = (columns) => {
|
|
|
19318
19318
|
const flat = [];
|
|
19319
19319
|
const objWidthFixLeft = {};
|
|
19320
19320
|
const objWidthFixRight = {};
|
|
19321
|
+
const objHeaderWidthFixRight = {};
|
|
19322
|
+
const objHeaderWidthFixLeft = {};
|
|
19321
19323
|
let maxDepth = 0;
|
|
19322
19324
|
// Tính depth tối đa
|
|
19323
19325
|
const calculateDepth = (cols, depth = 1) => (Math.max(...cols.map(col => (col.columns?.length ? calculateDepth(col.columns, depth + 1) : depth))));
|
|
@@ -19326,7 +19328,7 @@ const calculateTableStructure = (columns) => {
|
|
|
19326
19328
|
let rightTotal = 0;
|
|
19327
19329
|
const traverse = (cols, level = 0) => {
|
|
19328
19330
|
levels[level] = levels[level] || [];
|
|
19329
|
-
return cols.reduce((colspanSum, col) => {
|
|
19331
|
+
return cols.reduce((colspanSum, col, indexCol) => {
|
|
19330
19332
|
const hasChildren = (col.columns?.length ?? 0) > 0;
|
|
19331
19333
|
const colspan = hasChildren ? traverse(col.columns, level + 1) : 1;
|
|
19332
19334
|
const cell = {
|
|
@@ -19336,17 +19338,23 @@ const calculateTableStructure = (columns) => {
|
|
|
19336
19338
|
rowspan: hasChildren ? 1 : maxDepth - level
|
|
19337
19339
|
};
|
|
19338
19340
|
levels[level].push(cell);
|
|
19341
|
+
const headerKey = `${level}-${indexCol}`;
|
|
19342
|
+
if (col.fixedType === 'right' && col.visible !== false) {
|
|
19343
|
+
objHeaderWidthFixRight[headerKey] = rightTotal;
|
|
19344
|
+
}
|
|
19345
|
+
if (col.fixedType === 'left' && col.visible !== false) {
|
|
19346
|
+
objHeaderWidthFixLeft[headerKey] = leftTotal;
|
|
19347
|
+
}
|
|
19339
19348
|
if (!hasChildren) {
|
|
19340
|
-
const visible = col.visible !== false;
|
|
19341
19349
|
const index = flat.length;
|
|
19342
19350
|
const width = col.width ?? 40;
|
|
19343
19351
|
cell.index = index;
|
|
19344
19352
|
flat.push(cell);
|
|
19345
|
-
if (col.fixedType === 'left' && visible) {
|
|
19353
|
+
if (col.fixedType === 'left' && col.visible !== false) {
|
|
19346
19354
|
objWidthFixLeft[index] = leftTotal;
|
|
19347
19355
|
leftTotal += width;
|
|
19348
19356
|
}
|
|
19349
|
-
if (col.fixedType === 'right' && visible) {
|
|
19357
|
+
if (col.fixedType === 'right' && col.visible !== false) {
|
|
19350
19358
|
objWidthFixRight[index] = rightTotal;
|
|
19351
19359
|
rightTotal += width;
|
|
19352
19360
|
}
|
|
@@ -19358,6 +19366,9 @@ const calculateTableStructure = (columns) => {
|
|
|
19358
19366
|
const flatVisble = flat.filter((e) => e.visible !== false);
|
|
19359
19367
|
const lastObjWidthFixLeft = Math.max(...Object.keys(objWidthFixLeft).map(Number), 0);
|
|
19360
19368
|
const fisrtObjWidthFixRight = Math.min(...Object.keys(objWidthFixRight).map(Number), flat.length);
|
|
19369
|
+
const editableColumns = flat.filter(item => item.editEnable && item.visible !== false && !item.disabledCondition);
|
|
19370
|
+
const firstEdit = editableColumns[0];
|
|
19371
|
+
const lastEdit = editableColumns[editableColumns.length - 1];
|
|
19361
19372
|
return {
|
|
19362
19373
|
levels,
|
|
19363
19374
|
flat,
|
|
@@ -19365,7 +19376,11 @@ const calculateTableStructure = (columns) => {
|
|
|
19365
19376
|
objWidthFixLeft,
|
|
19366
19377
|
objWidthFixRight,
|
|
19367
19378
|
lastObjWidthFixLeft,
|
|
19368
|
-
fisrtObjWidthFixRight
|
|
19379
|
+
fisrtObjWidthFixRight,
|
|
19380
|
+
objHeaderWidthFixRight,
|
|
19381
|
+
objHeaderWidthFixLeft,
|
|
19382
|
+
firstEdit,
|
|
19383
|
+
lastEdit
|
|
19369
19384
|
};
|
|
19370
19385
|
};
|
|
19371
19386
|
|
|
@@ -41811,31 +41826,52 @@ var css_248z$1 = ".react-resizable {\n position: relative;\n}\n.react-resizable
|
|
|
41811
41826
|
styleInject(css_248z$1);
|
|
41812
41827
|
|
|
41813
41828
|
const HeaderTableCol$1 = (props) => {
|
|
41814
|
-
const { selectEnable, dataSource, setSelectedRows, col, indexCol, indexParent,
|
|
41829
|
+
const { selectEnable, dataSource, setSelectedRows, col, indexCol, indexParent, objHeaderWidthFixLeft, objHeaderWidthFixRight, totalCount, selectedRows, columns, setColumns, orderBy, changeFilter, filterBy, changeOrder, allowFilter, allowOrder, container, fisrtObjWidthFixRight, lastObjWidthFixLeft, formatSetting, optionsFilter, idTable, isMulti } = props;
|
|
41815
41830
|
const { t } = reactI18next.useTranslation();
|
|
41831
|
+
const headerRef = React$5.useRef(null);
|
|
41832
|
+
const order = orderBy.find((item) => item.key === col.field);
|
|
41833
|
+
const [openFilter, setOpenFilter] = React$5.useState(false);
|
|
41834
|
+
const filter = filterBy.find((item) => item.key === col.field);
|
|
41816
41835
|
const handleResize = (e, { size }) => {
|
|
41817
41836
|
// Update the column width here
|
|
41818
41837
|
// You might need to update the state or call a callback to update the width
|
|
41819
41838
|
if (size.width > 50) {
|
|
41820
|
-
const newColumns = [...
|
|
41839
|
+
const newColumns = [...columns];
|
|
41821
41840
|
newColumns[indexCol].width = size.width;
|
|
41822
|
-
if ((
|
|
41841
|
+
if ((columns[indexCol]?.maxWidth ?? 0) < size.width) {
|
|
41823
41842
|
newColumns[indexCol].maxWidth = size.width;
|
|
41824
41843
|
}
|
|
41825
|
-
if ((
|
|
41844
|
+
if ((columns[indexCol]?.minWidth ?? 0) > size.width) {
|
|
41826
41845
|
newColumns[indexCol].minWidth = size.width;
|
|
41827
41846
|
}
|
|
41828
|
-
|
|
41847
|
+
if (setColumns) {
|
|
41848
|
+
setColumns(newColumns);
|
|
41849
|
+
}
|
|
41829
41850
|
}
|
|
41830
41851
|
};
|
|
41831
|
-
|
|
41852
|
+
const checkOverflow = () => {
|
|
41853
|
+
return headerRef.current && headerRef.current.scrollHeight > headerRef.current.clientHeight;
|
|
41854
|
+
};
|
|
41855
|
+
console.log(col);
|
|
41856
|
+
return (jsxRuntime.jsx(React$5.Fragment, { children: col.visible !== false && (jsxRuntime.jsx(Resizable, { className: "r-resize", width: typeof col.width === 'number' ? col.width : Number((col.width ?? "").replaceAll(new RegExp(`[^0-9]`, "g"), '')), height: 0, onResize: handleResize, draggableOpts: { enableUserSelectHack: false }, children: jsxRuntime.jsx("th", { rowSpan: col.rowspan !== 1 ? col.rowspan : 1, colSpan: col.columns?.filter(x => x.visible !== false)?.length ?? 1, className: classNames$1(`r-headercell fix-${col.fixedType}`, { 'fixed-last': (col.fixedType === 'left' && indexCol === lastObjWidthFixLeft) || (col.fixedType === 'right' && indexCol === fisrtObjWidthFixRight) }, { 'cell-fixed': col.fixedType }), style: {
|
|
41832
41857
|
top: `${indexParent * 42}px`,
|
|
41833
|
-
left: col.fixedType === 'left' ?
|
|
41834
|
-
right: col.fixedType === 'right' ?
|
|
41835
|
-
|
|
41836
|
-
|
|
41837
|
-
|
|
41838
|
-
|
|
41858
|
+
left: col.fixedType === 'left' ? objHeaderWidthFixLeft[`${indexParent}-${indexCol ?? 0}`] : undefined,
|
|
41859
|
+
right: col.fixedType === 'right' ? objHeaderWidthFixRight[`${indexParent}-${indexCol ?? 0}`] : undefined
|
|
41860
|
+
}, children: jsxRuntime.jsxs("div", { style: { justifyContent: 'space-between' }, onClick: () => {
|
|
41861
|
+
if (order) {
|
|
41862
|
+
if (order.direction === 'asc') {
|
|
41863
|
+
order.direction = 'desc';
|
|
41864
|
+
changeOrder(orderBy);
|
|
41865
|
+
}
|
|
41866
|
+
else {
|
|
41867
|
+
changeOrder(orderBy.filter((x) => x.key !== col.field));
|
|
41868
|
+
}
|
|
41869
|
+
}
|
|
41870
|
+
else {
|
|
41871
|
+
orderBy.push({ direction: 'asc', key: col.field });
|
|
41872
|
+
changeOrder(orderBy);
|
|
41873
|
+
}
|
|
41874
|
+
}, className: classNames$1('r-headercell-div', { 'cursor-pointer': allowOrder }), children: [col.field === 'checkbox' && (jsxRuntime.jsx(Input$1, { checked: !!(totalCount > 0 && selectedRows?.length >= totalCount), type: "checkbox", className: classNames$1('cursor-pointer', { 'd-none': !isMulti }), style: { textAlign: col.textAlign ?? 'left', marginTop: 6 }, onChange: (e) => {
|
|
41839
41875
|
if (selectEnable) {
|
|
41840
41876
|
if (e.target.checked) {
|
|
41841
41877
|
setSelectedRows(dataSource.map((item) => { return item; }));
|
|
@@ -41844,7 +41880,89 @@ const HeaderTableCol$1 = (props) => {
|
|
|
41844
41880
|
setSelectedRows([]);
|
|
41845
41881
|
}
|
|
41846
41882
|
}
|
|
41847
|
-
} })), col.field !== 'checkbox' && jsxRuntime.
|
|
41883
|
+
} })), col.field !== 'checkbox' && jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: 'header-content', style: { justifyContent: col.textAlign ?? 'left' }, children: [jsxRuntime.jsx("span", { id: `header-${idTable}-${indexParent}-${indexCol}`, ref: headerRef, className: 'text-content', children: t(col.headerText ?? '') }), checkOverflow() && jsxRuntime.jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `header-${idTable}-${indexParent}-${indexCol}`, children: t(col.headerText ?? '') })] }), col.field !== '#' && col.field !== 'command' && jsxRuntime.jsxs("div", { className: 'd-flex', children: [allowOrder && order?.direction === 'asc' && jsxRuntime.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", className: 'ms-25', width: "10", height: "10", viewBox: "0 0 16 18", fill: "none", children: [jsxRuntime.jsx("g", { "clip-path": "url(#clip0_520_6)", children: jsxRuntime.jsx("path", { d: "M8.70711 0.292893C8.31658 -0.0976311 7.68342 -0.0976311 7.29289 0.292893L0.928932 6.65685C0.538408 7.04738 0.538408 7.68054 0.928932 8.07107C1.31946 8.46159 1.95262 8.46159 2.34315 8.07107L8 2.41421L13.6569 8.07107C14.0474 8.46159 14.6805 8.46159 15.0711 8.07107C15.4616 7.68054 15.4616 7.04738 15.0711 6.65685L8.70711 0.292893ZM8 18H9L9 1H8H7L7 18H8Z", fill: "black" }) }), jsxRuntime.jsx("defs", { children: jsxRuntime.jsx("clipPath", { id: "clip0_520_6", children: jsxRuntime.jsx("rect", { width: "16", height: "18", fill: "white" }) }) })] }), allowOrder && order?.direction === 'desc' && jsxRuntime.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", className: 'ms-25', width: "10", height: "10", viewBox: "0 0 16 18", fill: "none", children: [jsxRuntime.jsx("g", { "clip-path": "url(#clip0_520_2)", children: jsxRuntime.jsx("path", { d: "M7.29289 17.7071C7.68342 18.0976 8.31658 18.0976 8.70711 17.7071L15.0711 11.3431C15.4616 10.9526 15.4616 10.3195 15.0711 9.92893C14.6805 9.53841 14.0474 9.53841 13.6569 9.92893L8 15.5858L2.34315 9.92893C1.95262 9.53841 1.31946 9.53841 0.928932 9.92893C0.538408 10.3195 0.538408 10.9526 0.928932 11.3431L7.29289 17.7071ZM8 0L7 0L7 17H8H9L9 0L8 0Z", fill: "black" }) }), jsxRuntime.jsx("defs", { children: jsxRuntime.jsx("clipPath", { id: "clip0_520_2", children: jsxRuntime.jsx("rect", { width: "16", height: "18", fill: "white" }) }) })] }), allowFilter && (col.columns?.length ?? 0) === 0 && col.allowFilter !== false && jsxRuntime.jsxs(Dropdown$1, { isOpen: openFilter, toggle: (e) => {
|
|
41884
|
+
setOpenFilter(!openFilter);
|
|
41885
|
+
e.stopPropagation();
|
|
41886
|
+
}, onClick: (e) => {
|
|
41887
|
+
e.stopPropagation();
|
|
41888
|
+
}, children: [jsxRuntime.jsx(DropdownToggle$1, { tag: 'div', className: 'p-0 r-filter', children: jsxRuntime.jsxs("svg", { className: classNames$1('cursor-pointer ms-25', { 'active': filter }), width: "10", height: "10", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", "stroke-width": "1.5", "font-size": "12", children: [jsxRuntime.jsx("path", { d: "M14.7 11.998v10.506c.052.4-.08.826-.381 1.106a1.306 1.306 0 0 1-.925.39 1.289 1.289 0 0 1-.926-.39l-2.637-2.68a1.323 1.323 0 0 1-.38-1.106v-7.826h-.04L1.85 2.16A1.348 1.348 0 0 1 2.076.293C2.325.107 2.6 0 2.888 0h18.373c.289 0 .564.107.814.293a1.348 1.348 0 0 1 .223 1.866L14.738 12H14.7Z", fill: "currentColor" }), " "] }) }), jsxRuntime.jsx(DropdownMenu$1, { container: container, className: 'formula-dropdown icon-dropdown p-0', style: {
|
|
41889
|
+
borderRadius: 8,
|
|
41890
|
+
zIndex: 1056
|
|
41891
|
+
}, children: jsxRuntime.jsx(DropdownItem$1, { className: 'p-1', style: { borderRadius: '6px' }, tag: 'div', header: true, children: jsxRuntime.jsx(RenderFilterElement$1, { setOpenFilter: setOpenFilter, filter: filter, filterBy: filterBy, optionsFilter: optionsFilter, formatSetting: formatSetting, changeFilter: changeFilter, column: col }) }) })] })] })] })] }) }) })) }, `header-${indexCol}`));
|
|
41892
|
+
};
|
|
41893
|
+
const RenderFilterElement$1 = ({ filter, optionsFilter, formatSetting, filterBy, setOpenFilter, changeFilter, column }) => {
|
|
41894
|
+
const { t } = reactI18next.useTranslation();
|
|
41895
|
+
const [operator, setOperator] = React$5.useState(filter?.ope ?? ((!column.filterType && column.editType === 'numeric') || column.filterType === 'select' ? 'equal' : 'contains'));
|
|
41896
|
+
const [valueFilter, setValueFilter] = React$5.useState(filter?.value ?? '');
|
|
41897
|
+
const RenderStringFilter = () => {
|
|
41898
|
+
const options = [
|
|
41899
|
+
{ label: 'Bắt đầu bởi', value: 'startswith' },
|
|
41900
|
+
{ label: 'Kết thúc bởi', value: 'endswith' },
|
|
41901
|
+
{ label: 'Chứa', value: 'contains' },
|
|
41902
|
+
{ label: 'Bằng', value: 'equal' },
|
|
41903
|
+
{ label: 'Không bằng', value: 'notequal' }
|
|
41904
|
+
];
|
|
41905
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(SelectTable, { value: options.find((x) => x.value === (operator)), options: options, onChange: (val) => {
|
|
41906
|
+
setOperator(val.value);
|
|
41907
|
+
}, placeholder: 'Select' }), jsxRuntime.jsx(Input$1, { className: 'my-1', value: valueFilter, onChange: (val) => {
|
|
41908
|
+
setValueFilter(val.target.value);
|
|
41909
|
+
} })] }));
|
|
41910
|
+
};
|
|
41911
|
+
const RenderNumberFilter = () => {
|
|
41912
|
+
const options = [
|
|
41913
|
+
{ label: 'Lớn hơn', value: 'greaterthan' },
|
|
41914
|
+
{ label: 'Lớn hơn hoặc bằng', value: 'greaterthanorequal' },
|
|
41915
|
+
{ label: 'Bằng', value: 'equal' },
|
|
41916
|
+
{ label: 'Bé hơn', value: 'lessthan' },
|
|
41917
|
+
{ label: 'Bé hơn hoặc bằng', value: 'lessthanorequal' }
|
|
41918
|
+
];
|
|
41919
|
+
const numericFormatProps = {
|
|
41920
|
+
value: !isNullOrUndefined$1(valueFilter) ? valueFilter.toString() : '',
|
|
41921
|
+
thousandSeparator: checkThousandSeparator(formatSetting?.thousandSeparator, formatSetting?.decimalSeparator),
|
|
41922
|
+
decimalSeparator: checkDecimalSeparator(formatSetting?.thousandSeparator, formatSetting?.decimalSeparator),
|
|
41923
|
+
allowNegative: column.numericSettings?.allowNegative ?? false,
|
|
41924
|
+
decimalScale: column.numericSettings?.fraction ?? 0
|
|
41925
|
+
};
|
|
41926
|
+
let floatValue = parseFloat(valueFilter ?? '0');
|
|
41927
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(SelectTable, { value: options.find((x) => x.value === (operator)), options: options, onChange: (val) => {
|
|
41928
|
+
setOperator(val.value);
|
|
41929
|
+
}, placeholder: t('Select') }), jsxRuntime.jsx(NumericFormat, { style: { textAlign: column.textAlign, height: 29 }, ...numericFormatProps, defaultValue: formartNumberic(valueFilter, formatSetting?.decimalSeparator ?? ',', formatSetting?.thousandSeparator ?? '.', column.numericSettings?.fraction), className: classNames$1('form-control my-1 input-numeric'), onValueChange: (values) => {
|
|
41930
|
+
floatValue = values?.floatValue;
|
|
41931
|
+
}, onFocus: (e) => {
|
|
41932
|
+
e.target.setSelectionRange(0, e.target.innerText.length - 1);
|
|
41933
|
+
}, onBlur: () => {
|
|
41934
|
+
if (floatValue !== valueFilter) {
|
|
41935
|
+
setValueFilter(!isNaN(floatValue) ? floatValue : 0);
|
|
41936
|
+
}
|
|
41937
|
+
} })] }));
|
|
41938
|
+
};
|
|
41939
|
+
const RenderSelectFilter = () => {
|
|
41940
|
+
return (jsxRuntime.jsx("div", { className: 'mb-1', children: jsxRuntime.jsx(SelectTable, { value: optionsFilter ? optionsFilter[column.field]?.find((x) => x.value === valueFilter) : undefined, options: (optionsFilter && optionsFilter[column.field]) ?? [], isClearable: true, onChange: (val) => {
|
|
41941
|
+
setValueFilter(val?.value);
|
|
41942
|
+
}, placeholder: t('Select') }) }));
|
|
41943
|
+
};
|
|
41944
|
+
const handleSave = () => {
|
|
41945
|
+
if (filter) {
|
|
41946
|
+
filter.ope = operator;
|
|
41947
|
+
filter.value = valueFilter ?? '';
|
|
41948
|
+
}
|
|
41949
|
+
else {
|
|
41950
|
+
filterBy.push({ key: column.field, ope: operator, value: valueFilter ?? '' });
|
|
41951
|
+
}
|
|
41952
|
+
changeFilter([...filterBy]);
|
|
41953
|
+
setOpenFilter(false);
|
|
41954
|
+
};
|
|
41955
|
+
return (jsxRuntime.jsxs("div", { className: 'r-filter-popup', onKeyDown: (e) => {
|
|
41956
|
+
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
|
|
41957
|
+
handleSave();
|
|
41958
|
+
e.stopPropagation();
|
|
41959
|
+
}
|
|
41960
|
+
}, children: [((!column.filterType && column.editType === 'numeric') || column.filterType === 'numeric') ? jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [RenderNumberFilter(), " "] }) : (column.filterType === 'select' ? jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [RenderSelectFilter(), " "] }) : RenderStringFilter()), jsxRuntime.jsxs("div", { className: 'd-flex justify-content-end', children: [jsxRuntime.jsx(Button$1, { color: 'primary', style: { borderRadius: 3 }, className: 'me-50 py-25 px-50 fw-bold', onClick: handleSave, children: t('Filter') }), jsxRuntime.jsx(Button$1, { className: 'py-25 px-50 fw-bold', color: 'white', style: { borderRadius: 3, borderWidth: 0 }, onClick: () => {
|
|
41961
|
+
if (filterBy) {
|
|
41962
|
+
changeFilter(filterBy.filter((x) => x.key !== column.field));
|
|
41963
|
+
}
|
|
41964
|
+
setOpenFilter(false);
|
|
41965
|
+
}, children: t('Clear') })] })] }));
|
|
41848
41966
|
};
|
|
41849
41967
|
|
|
41850
41968
|
const defaultMaxHeight = 250;
|
|
@@ -42616,9 +42734,15 @@ const EditFormInline = React$5.forwardRef((props, ref) => {
|
|
|
42616
42734
|
}) })] }));
|
|
42617
42735
|
});
|
|
42618
42736
|
|
|
42737
|
+
const RenderColGroup = ({ contentColumns }) => (jsxRuntime.jsx("colgroup", { children: contentColumns.map((col, index) => (jsxRuntime.jsx("col", { style: {
|
|
42738
|
+
width: typeof col.width === 'number' ? `${col.width}px` : col.width || undefined,
|
|
42739
|
+
minWidth: typeof col.minWidth === 'number' ? `${col.minWidth}px` : col.minWidth || undefined,
|
|
42740
|
+
maxWidth: typeof col.maxWidth === 'number' ? `${col.maxWidth}px` : col.maxWidth || undefined
|
|
42741
|
+
} }, index))) }));
|
|
42742
|
+
|
|
42619
42743
|
const TableEdit = React$5.forwardRef((props, ref) => {
|
|
42620
42744
|
const { t } = reactI18next.useTranslation();
|
|
42621
|
-
const { idTable, dataSource, columns, commandClick, dataSourceChange, rowChange, pagingSetting, setDataSource, height, maxHeight, minHeight, defaultValue, toolbarSetting, searchSetting, setSelectedItem, selectedItem, selectEnable, editDisable, addDisable, buttonSetting, formatSetting, handleSelect, haveSum, isMulti, disableAutoKey, onDuplicate } = props;
|
|
42745
|
+
const { idTable, dataSource, columns, commandClick, dataSourceChange, rowChange, pagingSetting, setDataSource, height, maxHeight, minHeight, defaultValue, toolbarSetting, searchSetting, setSelectedItem, selectedItem, selectEnable, editDisable, addDisable, buttonSetting, formatSetting, handleSelect, haveSum, isMulti, disableAutoKey, onDuplicate, allowFilter = true, allowOrder, optionsFilter } = props;
|
|
42622
42746
|
React$5.useImperativeHandle(ref, () => {
|
|
42623
42747
|
return {
|
|
42624
42748
|
refeshFocusRow: handleRefeshRow
|
|
@@ -42627,17 +42751,11 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
42627
42751
|
const [refreshRow, setRefreshRow] = React$5.useState(false);
|
|
42628
42752
|
const [indexFocus, setIndexFocus] = React$5.useState(-1);
|
|
42629
42753
|
const [selectedRows, setSelectedRows] = React$5.useState([]);
|
|
42630
|
-
const [headerColumns, setHeaderColumns] = React$5.useState([[]]);
|
|
42631
42754
|
const [contentColumns, setContentColumns] = React$5.useState([]);
|
|
42632
|
-
const [levelCol, setLevelCol] = React$5.useState(0);
|
|
42633
|
-
const [columnFistEdit, setColumnFistEdit] = React$5.useState(0);
|
|
42634
|
-
const [columnLastEdit, setColumnlastEdit] = React$5.useState(0);
|
|
42635
|
-
const [objWidthFixRight, setObjWidthFixRight] = React$5.useState({});
|
|
42636
|
-
const [objWidthFixLeft, setObjWidthFixLeft] = React$5.useState({});
|
|
42637
|
-
const [lastObjWidthFixLeft, setLastObjWidthFixLeft] = React$5.useState(0);
|
|
42638
|
-
const [fisrtObjWidthFixRight, setFisrtObjWidthFixRight] = React$5.useState(0);
|
|
42639
42755
|
const [openPopupSetupColumn, setOpenPopupSetupColumn] = React$5.useState(false);
|
|
42640
42756
|
const [searchTerm, setSearchTerm] = React$5.useState('');
|
|
42757
|
+
const [orderBy, setOrderBy] = React$5.useState([]);
|
|
42758
|
+
const [filterBy, setFilterBy] = React$5.useState([]);
|
|
42641
42759
|
const tableElement = React$5.useRef(null);
|
|
42642
42760
|
const gridRef = React$5.useRef(null);
|
|
42643
42761
|
const totalCount = dataSource.length;
|
|
@@ -42650,95 +42768,11 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
42650
42768
|
pagingSetting.setCurrentPage(1);
|
|
42651
42769
|
}
|
|
42652
42770
|
}, [dataSource]);
|
|
42653
|
-
React$5.
|
|
42654
|
-
|
|
42655
|
-
|
|
42656
|
-
|
|
42657
|
-
let rightWidthFix = 0;
|
|
42658
|
-
contentColumns.forEach((item, index) => {
|
|
42659
|
-
if (levelCol === 1) {
|
|
42660
|
-
headerColumns[0][index].width = item.width;
|
|
42661
|
-
headerColumns[0][index].visible = item.visible;
|
|
42662
|
-
headerColumns[0][index].fixedType = item.fixedType;
|
|
42663
|
-
}
|
|
42664
|
-
if (item.fixedType === 'left' && item.visible !== false) {
|
|
42665
|
-
setLastObjWidthFixLeft(index);
|
|
42666
|
-
objWidthFixLeft[index] = letfWidthFix;
|
|
42667
|
-
letfWidthFix += Number(item.width ?? 40);
|
|
42668
|
-
}
|
|
42669
|
-
const lasColumn = contentColumns[contentColumns.length - 1 - index];
|
|
42670
|
-
if (lasColumn.fixedType === 'right' && lasColumn.visible !== false) {
|
|
42671
|
-
setFisrtObjWidthFixRight(contentColumns.length - 1 - index);
|
|
42672
|
-
objWidthFixRight[contentColumns.length - 1 - index] = rightWidthFix;
|
|
42673
|
-
rightWidthFix += Number(lasColumn.width ?? 40);
|
|
42674
|
-
}
|
|
42675
|
-
if (item.editEnable && (item.visible !== false) && (!item.disabledCondition)) {
|
|
42676
|
-
if (indexFirst === -1) {
|
|
42677
|
-
indexFirst = index;
|
|
42678
|
-
}
|
|
42679
|
-
indexlast = index;
|
|
42680
|
-
}
|
|
42681
|
-
});
|
|
42682
|
-
if (levelCol === 1) {
|
|
42683
|
-
setHeaderColumns([...headerColumns]);
|
|
42684
|
-
}
|
|
42685
|
-
setObjWidthFixLeft(objWidthFixLeft);
|
|
42686
|
-
setObjWidthFixRight(objWidthFixRight);
|
|
42687
|
-
setColumnFistEdit(indexFirst + 1);
|
|
42688
|
-
setColumnlastEdit(indexlast + 1);
|
|
42689
|
-
}, [contentColumns]);
|
|
42690
|
-
React$5.useEffect(() => {
|
|
42691
|
-
const arrHeaderColumns = [];
|
|
42692
|
-
const arrContentColumns = [];
|
|
42693
|
-
let headerLevelRow = 0;
|
|
42694
|
-
if (levelCol) {
|
|
42695
|
-
headerLevelRow = levelCol;
|
|
42696
|
-
}
|
|
42697
|
-
else {
|
|
42698
|
-
headerLevelRow = stretchColumn(columns, 0);
|
|
42699
|
-
setLevelCol(headerLevelRow);
|
|
42700
|
-
}
|
|
42701
|
-
for (let i = 0; i < headerLevelRow; i++) {
|
|
42702
|
-
arrHeaderColumns.push([]);
|
|
42703
|
-
}
|
|
42704
|
-
getNestedChildren(columns, arrHeaderColumns, arrContentColumns, 0, headerLevelRow);
|
|
42705
|
-
setHeaderColumns(arrHeaderColumns);
|
|
42706
|
-
setContentColumns(arrContentColumns);
|
|
42771
|
+
const { levels: headerColumns, flatVisble, objWidthFixLeft, objWidthFixRight, lastObjWidthFixLeft, fisrtObjWidthFixRight, objHeaderWidthFixLeft, objHeaderWidthFixRight, firstEdit: columnFirstEdit, lastEdit: columnLastEdit } = React$5.useMemo(() => {
|
|
42772
|
+
const obj = calculateTableStructure(columns);
|
|
42773
|
+
setContentColumns(obj.flat);
|
|
42774
|
+
return obj;
|
|
42707
42775
|
}, [columns]);
|
|
42708
|
-
const getNestedChildren = (array, arrHeaderColumns, arrContentColumns, level, maxLevelRow) => {
|
|
42709
|
-
array.forEach((item) => {
|
|
42710
|
-
const ele = { ...item, visible: item.visible, rowspan: 1, index: 0 };
|
|
42711
|
-
if (item.columns && item.columns?.length > 0) {
|
|
42712
|
-
const countLevel = getNestedChildren(item.columns, arrHeaderColumns, arrContentColumns, level + 1, maxLevelRow);
|
|
42713
|
-
arrHeaderColumns[(maxLevelRow - 1) - countLevel].push(ele);
|
|
42714
|
-
}
|
|
42715
|
-
else {
|
|
42716
|
-
ele.rowspan = maxLevelRow - level;
|
|
42717
|
-
ele.index = arrContentColumns.length;
|
|
42718
|
-
if (maxLevelRow === 1) {
|
|
42719
|
-
ele.visible = (item.invisibleDisable ? item.visible : (contentColumns[arrContentColumns.length]?.visible ?? item.visible));
|
|
42720
|
-
ele.width = (contentColumns[arrContentColumns.length]?.width ?? item.width);
|
|
42721
|
-
ele.maxWidth = (contentColumns[arrContentColumns.length]?.maxWidth ?? item.maxWidth);
|
|
42722
|
-
ele.minWidth = (contentColumns[arrContentColumns.length]?.minWidth ?? item.minWidth);
|
|
42723
|
-
}
|
|
42724
|
-
arrHeaderColumns[level].push(ele);
|
|
42725
|
-
arrContentColumns.push(ele);
|
|
42726
|
-
}
|
|
42727
|
-
});
|
|
42728
|
-
return level;
|
|
42729
|
-
};
|
|
42730
|
-
const stretchColumn = (subColumns, headerLevelRow) => {
|
|
42731
|
-
let count = headerLevelRow + 1;
|
|
42732
|
-
subColumns.map((item) => {
|
|
42733
|
-
if (item.columns && item.columns.length > 0) {
|
|
42734
|
-
const newCount = stretchColumn(item.columns, headerLevelRow + 1);
|
|
42735
|
-
if (newCount > count) {
|
|
42736
|
-
count = newCount;
|
|
42737
|
-
}
|
|
42738
|
-
}
|
|
42739
|
-
});
|
|
42740
|
-
return count;
|
|
42741
|
-
};
|
|
42742
42776
|
const handleRefeshRow = () => {
|
|
42743
42777
|
setRefreshRow(true);
|
|
42744
42778
|
setTimeout(() => {
|
|
@@ -43068,7 +43102,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43068
43102
|
}
|
|
43069
43103
|
if (tableElement) {
|
|
43070
43104
|
setIndexFocus(totalCount);
|
|
43071
|
-
focusNewElement(
|
|
43105
|
+
focusNewElement(columnFirstEdit, totalCount + 1, true);
|
|
43072
43106
|
}
|
|
43073
43107
|
};
|
|
43074
43108
|
const checkKeyDown = (e, row, col, indexRow, indexCol) => {
|
|
@@ -43304,14 +43338,6 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43304
43338
|
};
|
|
43305
43339
|
const changeDataSource = (data, numberOfRows) => {
|
|
43306
43340
|
if (!editDisable && setDataSource) {
|
|
43307
|
-
if ((searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm)) {
|
|
43308
|
-
if (searchSetting?.setSearchTerm) {
|
|
43309
|
-
searchSetting?.setSearchTerm('');
|
|
43310
|
-
}
|
|
43311
|
-
else {
|
|
43312
|
-
setSearchTerm('');
|
|
43313
|
-
}
|
|
43314
|
-
}
|
|
43315
43341
|
if (numberOfRows && !addDisable) {
|
|
43316
43342
|
for (let index = 0; index < numberOfRows; index++) {
|
|
43317
43343
|
data.push(defaultValue ? { ...defaultValue, [fieldKey]: disableAutoKey ? undefined : generateUUID() } : {});
|
|
@@ -43512,22 +43538,52 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43512
43538
|
textAlign: col.textAlign ? col.textAlign : 'left'
|
|
43513
43539
|
}, children: jsxRuntime.jsxs("div", { className: "r-footer-div", children: [col.haveSum === true && col.editType === "numeric" && (Number(sumValue) >= 0) && jsxRuntime.jsx(jsxRuntime.Fragment, { children: formartNumberic(sumValue, formatSetting?.decimalSeparator ?? ',', formatSetting?.thousandSeparator ?? '.', col.numericSettings?.fraction, true, false) }), col.haveSum === true && col.editType === "numeric" && (Number(sumValue) < 0) && jsxRuntime.jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${formartNumberic(sumValue, formatSetting?.decimalSeparator ?? ',', formatSetting?.thousandSeparator ?? '.', col.numericSettings?.fraction, true, false)}${formatSetting?.suffixNegative ?? ''}`] })] }) }) }, `summarycell-${indexCol}`));
|
|
43514
43540
|
};
|
|
43515
|
-
|
|
43516
|
-
|
|
43517
|
-
|
|
43518
|
-
|
|
43519
|
-
|
|
43520
|
-
|
|
43521
|
-
|
|
43522
|
-
|
|
43541
|
+
/**
|
|
43542
|
+
* Kiểm tra row có thỏa mãn tất cả filter và chứa từ khóa tìm kiếm hay không
|
|
43543
|
+
*/
|
|
43544
|
+
function checkRowMatch(row, filters, keyword, searchKeys) {
|
|
43545
|
+
if ((!filters || filters.length === 0) && (!keyword || !searchClient))
|
|
43546
|
+
return true; // Không có filter thì mặc định là match
|
|
43547
|
+
const isFilterMatch = filters.every(filter => {
|
|
43548
|
+
const { key, value, ope } = filter;
|
|
43549
|
+
const rowValue = row[key];
|
|
43550
|
+
if (rowValue === undefined || rowValue === null || value === undefined || value === null)
|
|
43551
|
+
return false;
|
|
43552
|
+
const valStr = String(rowValue).toLowerCase();
|
|
43553
|
+
const filterStr = String(value).toLowerCase();
|
|
43554
|
+
switch (ope) {
|
|
43555
|
+
case 'startswith':
|
|
43556
|
+
return valStr.startsWith(filterStr);
|
|
43557
|
+
case 'endswith':
|
|
43558
|
+
return valStr.endsWith(filterStr);
|
|
43559
|
+
case 'contains':
|
|
43560
|
+
return valStr.includes(filterStr);
|
|
43561
|
+
case 'equal':
|
|
43562
|
+
return rowValue == value;
|
|
43563
|
+
case 'notequal':
|
|
43564
|
+
return rowValue != value;
|
|
43565
|
+
case 'greaterthan':
|
|
43566
|
+
return rowValue > value;
|
|
43567
|
+
case 'greaterthanorequal':
|
|
43568
|
+
return rowValue >= value;
|
|
43569
|
+
case 'lessthan':
|
|
43570
|
+
return rowValue < value;
|
|
43571
|
+
case 'lessthanorequal':
|
|
43572
|
+
return rowValue <= value;
|
|
43573
|
+
default:
|
|
43574
|
+
return false;
|
|
43523
43575
|
}
|
|
43524
|
-
}
|
|
43525
|
-
|
|
43526
|
-
|
|
43576
|
+
});
|
|
43577
|
+
const isSearchMatch = !keyword || searchKeys.some(key => {
|
|
43578
|
+
const val = row[key];
|
|
43579
|
+
return val?.toString().toLowerCase().includes(keyword.trim().toLowerCase());
|
|
43580
|
+
});
|
|
43581
|
+
return isFilterMatch && isSearchMatch;
|
|
43582
|
+
}
|
|
43527
43583
|
const renderData = () => {
|
|
43528
43584
|
return (dataSource.map((row, indexRow) => {
|
|
43529
43585
|
const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
|
|
43530
|
-
const flagSearch =
|
|
43586
|
+
const flagSearch = checkRowMatch(row, filterBy, searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm, searchSetting?.keyField ?? []);
|
|
43531
43587
|
if (flagSearch) {
|
|
43532
43588
|
const flagDisplay = !pagingClient || ((indexRow + 1) > ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0) - 1)) && (indexRow + 1) <= ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0))));
|
|
43533
43589
|
return (flagDisplay && jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("tr", { className: classNames$1('r-row'), children: contentColumns.map((col, indexCol) => renderContentCol(col, row, indexRow, indexCol, isSelected)) }, `row-${indexRow}`) }));
|
|
@@ -43539,14 +43595,18 @@ const TableEdit = React$5.forwardRef((props, ref) => {
|
|
|
43539
43595
|
pagingSetting?.setCurrentPage(1);
|
|
43540
43596
|
}
|
|
43541
43597
|
}, [searchTerm, searchSetting?.searchTerm]);
|
|
43542
|
-
return (jsxRuntime.jsxs(React$5.Fragment, { children: [jsxRuntime.jsxs("div", { className: "react-table-edit", children: [jsxRuntime.jsxs("div", { className: 'r-grid', ref: gridRef, children: [toolbarSetting?.showTopToolbar && jsxRuntime.jsx(RenderToolbarTop, { toolbarTopOption: toolbarTopOption }), jsxRuntime.jsx("div", { ref: tableElement, className: "r-gridtable", style: { height: `${height ? `${height}px` : 'auto'}`, minHeight: `${minHeight ? `${minHeight}px` : ''}`, maxHeight: `${maxHeight ? `${maxHeight}px` : '400px'}` }, children: jsxRuntime.jsxs("table", { style: { width: '100%' }, children: [jsxRuntime.jsx("thead", { className: 'r-gridheader', children: headerColumns.map((element, indexParent) => {
|
|
43598
|
+
return (jsxRuntime.jsxs(React$5.Fragment, { children: [jsxRuntime.jsxs("div", { className: "react-table-edit", children: [jsxRuntime.jsxs("div", { className: 'r-grid', ref: gridRef, children: [toolbarSetting?.showTopToolbar && jsxRuntime.jsx(RenderToolbarTop, { toolbarTopOption: toolbarTopOption }), jsxRuntime.jsx("div", { ref: tableElement, className: "r-gridtable", style: { height: `${height ? `${height}px` : 'auto'}`, minHeight: `${minHeight ? `${minHeight}px` : ''}`, maxHeight: `${maxHeight ? `${maxHeight}px` : '400px'}` }, children: jsxRuntime.jsxs("table", { style: { width: '100%' }, children: [jsxRuntime.jsx(RenderColGroup, { contentColumns: flatVisble }), jsxRuntime.jsx("thead", { className: 'r-gridheader', children: headerColumns.map((element, indexParent) => {
|
|
43543
43599
|
return (jsxRuntime.jsx("tr", { className: "r-row", role: "row", children: element?.map((col, index) => {
|
|
43544
|
-
return (jsxRuntime.jsx(HeaderTableCol$1, { col: col, dataSource: dataSource, indexCol: index, indexParent: indexParent, isMulti: isMulti ?? false,
|
|
43600
|
+
return (jsxRuntime.jsx(HeaderTableCol$1, { col: col, idTable: idTable ?? '', dataSource: dataSource, indexCol: index, indexParent: indexParent, isMulti: isMulti ?? false, objHeaderWidthFixLeft: objHeaderWidthFixLeft, objHeaderWidthFixRight: objHeaderWidthFixRight, selectEnable: selectEnable ?? false, selectedRows: selectedRows, setSelectedRows: setSelectedRows, container: tableElement, filterBy: filterBy, orderBy: orderBy, optionsFilter: optionsFilter, allowFilter: allowFilter, allowOrder: allowOrder, formatSetting: formatSetting, changeFilter: (val) => {
|
|
43601
|
+
setFilterBy([...val]);
|
|
43602
|
+
}, changeOrder: (val) => {
|
|
43603
|
+
setOrderBy([...val]);
|
|
43604
|
+
}, columns: contentColumns, setColumns: setContentColumns, fisrtObjWidthFixRight: fisrtObjWidthFixRight, lastObjWidthFixLeft: lastObjWidthFixLeft, totalCount: totalCount }, `header-${indexParent}-${index}`));
|
|
43545
43605
|
}) }, `header-${-indexParent}`));
|
|
43546
43606
|
}) }), 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) => {
|
|
43547
43607
|
return (renderFooterCol(col, index));
|
|
43548
43608
|
}) }) : jsxRuntime.jsx(jsxRuntime.Fragment, {}) })] }) }), toolbarSetting?.showBottomToolbar && jsxRuntime.jsx(ToolbarBottom, { handleAdd: (numberOfRows) => {
|
|
43549
|
-
handleAdd(dataSource, tableElement.current,
|
|
43609
|
+
handleAdd(dataSource, tableElement.current, columnFirstEdit, changeDataSource, pagingSetting, setIndexFocus, focusNewElement, numberOfRows);
|
|
43550
43610
|
}, handleDuplicate: () => {
|
|
43551
43611
|
handleDuplicate(dataSource, indexFocus, fieldKey, defaultValue, fieldUniKey, changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate);
|
|
43552
43612
|
}, handleInsertAfter: () => {
|
|
@@ -65662,12 +65722,6 @@ const RenderContentCol = (props) => {
|
|
|
65662
65722
|
}, children: RenderElement() }, `col-${indexRow}-${indexCol}`));
|
|
65663
65723
|
};
|
|
65664
65724
|
|
|
65665
|
-
const RenderColGroup = ({ contentColumns }) => (jsxRuntime.jsx("colgroup", { children: contentColumns.map((col, index) => (jsxRuntime.jsx("col", { style: {
|
|
65666
|
-
width: typeof col.width === 'number' ? `${col.width}px` : col.width || undefined,
|
|
65667
|
-
minWidth: typeof col.minWidth === 'number' ? `${col.minWidth}px` : col.minWidth || undefined,
|
|
65668
|
-
maxWidth: typeof col.maxWidth === 'number' ? `${col.maxWidth}px` : col.maxWidth || undefined
|
|
65669
|
-
} }, index))) }));
|
|
65670
|
-
|
|
65671
65725
|
const VirtualTable = ({ idTable, dataSource, rowHeight = 33, height = 400, columns, isMutil, isLoading, selectEnable, formatSetting, commandClick, allowFilter, allowOrder, setColumns, pagingSetting, changeFilter, changeOrder, searchSetting, columnsAggregate, toolbarSetting, optionsFilter }) => {
|
|
65672
65726
|
const gridRef = React$5.useRef(null);
|
|
65673
65727
|
const [startIndex, setStartIndex] = React$5.useState(0);
|