react-table-edit 1.4.19 → 1.4.21
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/type/index.d.ts +4 -7
- package/dist/component/virtualized-table/header.d.ts +2 -0
- package/dist/component/virtualized-table/index.d.ts +2 -1
- package/dist/index.d.ts +29 -8
- package/dist/index.js +350 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +350 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -41779,7 +41779,7 @@ function styleInject(css, ref) {
|
|
|
41779
41779
|
var css_248z$1 = ".react-resizable {\n position: relative;\n}\n.react-resizable-handle {\n position: absolute;\n width: 20px;\n height: 20px;\n background-repeat: no-repeat;\n background-origin: content-box;\n box-sizing: border-box;\n background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+');\n background-position: bottom right;\n padding: 0 3px 3px 0;\n}\n.react-resizable-handle-sw {\n bottom: 0;\n left: 0;\n cursor: sw-resize;\n transform: rotate(90deg);\n}\n.react-resizable-handle-se {\n bottom: 0;\n right: 0;\n cursor: se-resize;\n}\n.react-resizable-handle-nw {\n top: 0;\n left: 0;\n cursor: nw-resize;\n transform: rotate(180deg);\n}\n.react-resizable-handle-ne {\n top: 0;\n right: 0;\n cursor: ne-resize;\n transform: rotate(270deg);\n}\n.react-resizable-handle-w,\n.react-resizable-handle-e {\n top: 50%;\n margin-top: -10px;\n cursor: ew-resize;\n}\n.react-resizable-handle-w {\n left: 0;\n transform: rotate(135deg);\n}\n.react-resizable-handle-e {\n right: 0;\n transform: rotate(315deg);\n}\n.react-resizable-handle-n,\n.react-resizable-handle-s {\n left: 50%;\n margin-left: -10px;\n cursor: ns-resize;\n}\n.react-resizable-handle-n {\n top: 0;\n transform: rotate(225deg);\n}\n.react-resizable-handle-s {\n bottom: 0;\n transform: rotate(45deg);\n}";
|
|
41780
41780
|
styleInject(css_248z$1);
|
|
41781
41781
|
|
|
41782
|
-
const HeaderTableCol = (props) => {
|
|
41782
|
+
const HeaderTableCol$1 = (props) => {
|
|
41783
41783
|
const { selectEnable, dataSource, setSelectedRows, col, indexCol, indexParent, objWidthFixLeft, objWidthFixRight, totalCount, selectedRows, column, setColumn, fisrtObjWidthFixRight, lastObjWidthFixLeft, isMulti } = props;
|
|
41784
41784
|
const { t } = useTranslation();
|
|
41785
41785
|
const handleResize = (e, { size }) => {
|
|
@@ -43479,7 +43479,7 @@ const TableEdit = forwardRef((props, ref) => {
|
|
|
43479
43479
|
}, [searchTerm, searchSetting?.searchTerm]);
|
|
43480
43480
|
return (jsxs(Fragment, { children: [jsxs("div", { className: "react-table-edit", children: [jsxs("div", { className: 'r-grid', ref: gridRef, children: [toolbarSetting?.showTopToolbar && jsx(RenderToolbarTop, { toolbarTopOption: toolbarTopOption }), jsx("div", { ref: tableElement, className: "r-gridtable", style: { height: `${height ? `${height}px` : 'auto'}`, minHeight: `${minHeight ? `${minHeight}px` : ''}`, maxHeight: `${maxHeight ? `${maxHeight}px` : '400px'}` }, children: jsxs("table", { style: { width: '100%' }, children: [jsx("thead", { className: 'r-gridheader', children: headerColumns.map((element, indexParent) => {
|
|
43481
43481
|
return (jsx("tr", { className: "r-row", role: "row", children: element?.map((col, index) => {
|
|
43482
|
-
return (jsx(HeaderTableCol, { col: col, dataSource: dataSource, indexCol: index, indexParent: indexParent, isMulti: isMulti ?? false, objWidthFixLeft: objWidthFixLeft, objWidthFixRight: objWidthFixRight, selectEnable: selectEnable ?? false, selectedRows: selectedRows, setSelectedRows: setSelectedRows, column: contentColumns, setColumn: setContentColumns, fisrtObjWidthFixRight: fisrtObjWidthFixRight, lastObjWidthFixLeft: lastObjWidthFixLeft, totalCount: totalCount }, `header-${indexParent}-${index}`));
|
|
43482
|
+
return (jsx(HeaderTableCol$1, { col: col, dataSource: dataSource, indexCol: index, indexParent: indexParent, isMulti: isMulti ?? false, objWidthFixLeft: objWidthFixLeft, objWidthFixRight: objWidthFixRight, selectEnable: selectEnable ?? false, selectedRows: selectedRows, setSelectedRows: setSelectedRows, column: contentColumns, setColumn: setContentColumns, fisrtObjWidthFixRight: fisrtObjWidthFixRight, lastObjWidthFixLeft: lastObjWidthFixLeft, totalCount: totalCount }, `header-${indexParent}-${index}`));
|
|
43483
43483
|
}) }, `header-${-indexParent}`));
|
|
43484
43484
|
}) }), jsx("tbody", { className: 'r-gridcontent', children: renderData() }), jsx("tfoot", { className: "r-gridfoot", children: haveSum == true ? jsx("tr", { className: 'r-row', children: contentColumns.map((col, index) => {
|
|
43485
43485
|
return (renderFooterCol(col, index));
|
|
@@ -65378,5 +65378,352 @@ const ImportExcelComponent = (props) => {
|
|
|
65378
65378
|
] }) }));
|
|
65379
65379
|
};
|
|
65380
65380
|
|
|
65381
|
-
|
|
65381
|
+
const HeaderTableCol = (props) => {
|
|
65382
|
+
const { selectEnable, dataSource, setSelectedRows, col, indexCol, indexParent, objWidthFixLeft, objWidthFixRight, totalCount, selectedRows, columns, setColumns, orderBy, changeFilter, filterBy, changeOrder, allowFilter, allowOrder, container, fisrtObjWidthFixRight, lastObjWidthFixLeft, formatSetting, optionsFilter, idTable, isMulti } = props;
|
|
65383
|
+
const { t } = useTranslation();
|
|
65384
|
+
const headerRef = useRef(null);
|
|
65385
|
+
const order = orderBy.find((item) => item.key === col.field);
|
|
65386
|
+
const [openFilter, setOpenFilter] = useState(false);
|
|
65387
|
+
const filter = filterBy.find((item) => item.key === col.field);
|
|
65388
|
+
const handleResize = (e, { size }) => {
|
|
65389
|
+
// Update the column width here
|
|
65390
|
+
// You might need to update the state or call a callback to update the width
|
|
65391
|
+
if (size.width > 50) {
|
|
65392
|
+
const newColumns = [...columns];
|
|
65393
|
+
newColumns[indexCol].width = size.width;
|
|
65394
|
+
if ((columns[indexCol]?.maxWidth ?? 0) < size.width) {
|
|
65395
|
+
newColumns[indexCol].maxWidth = size.width;
|
|
65396
|
+
}
|
|
65397
|
+
if ((columns[indexCol]?.minWidth ?? 0) > size.width) {
|
|
65398
|
+
newColumns[indexCol].minWidth = size.width;
|
|
65399
|
+
}
|
|
65400
|
+
if (setColumns) {
|
|
65401
|
+
setColumns(newColumns);
|
|
65402
|
+
}
|
|
65403
|
+
}
|
|
65404
|
+
};
|
|
65405
|
+
const checkOverflow = () => {
|
|
65406
|
+
return headerRef.current && headerRef.current.scrollHeight > headerRef.current.clientHeight;
|
|
65407
|
+
};
|
|
65408
|
+
return (jsx(Fragment, { children: col.visible !== false && (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: 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: {
|
|
65409
|
+
top: `${indexParent * 42}px`,
|
|
65410
|
+
left: col.fixedType === 'left' ? objWidthFixLeft[indexCol ?? 0] : undefined,
|
|
65411
|
+
right: col.fixedType === 'right' ? objWidthFixRight[indexCol ?? 0] : undefined
|
|
65412
|
+
}, children: jsxs("div", { style: { justifyContent: 'space-between' }, onClick: () => {
|
|
65413
|
+
if (order) {
|
|
65414
|
+
if (order.direction === 'asc') {
|
|
65415
|
+
order.direction = 'desc';
|
|
65416
|
+
changeOrder(orderBy);
|
|
65417
|
+
}
|
|
65418
|
+
else {
|
|
65419
|
+
changeOrder(orderBy.filter((x) => x.key !== col.field));
|
|
65420
|
+
}
|
|
65421
|
+
}
|
|
65422
|
+
else {
|
|
65423
|
+
orderBy.push({ direction: 'asc', key: col.field });
|
|
65424
|
+
changeOrder(orderBy);
|
|
65425
|
+
}
|
|
65426
|
+
}, className: classNames$1('r-headercell-div', { 'cursor-pointer': allowOrder }), children: [col.type === 'checkbox' && (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) => {
|
|
65427
|
+
if (selectEnable) {
|
|
65428
|
+
if (e.target.checked) {
|
|
65429
|
+
setSelectedRows(dataSource.map((item) => { return item; }));
|
|
65430
|
+
}
|
|
65431
|
+
else {
|
|
65432
|
+
setSelectedRows([]);
|
|
65433
|
+
}
|
|
65434
|
+
}
|
|
65435
|
+
} })), col.type !== 'checkbox' && jsxs(Fragment$1, { children: [jsxs("div", { className: 'header-content', style: { justifyContent: col.textAlign ?? 'left' }, children: [jsx("span", { id: `header-${idTable}-${indexParent}-${indexCol}`, ref: headerRef, className: 'text-content', children: t(col.headerText ?? '') }), checkOverflow() && jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `header-${idTable}-${indexParent}-${indexCol}`, children: t(col.headerText ?? '') })] }), col.type !== '#' && col.type !== 'command' && jsxs("div", { className: 'd-flex', children: [allowOrder && order?.direction === 'asc' && jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", className: 'ms-25', width: "10", height: "10", viewBox: "0 0 16 18", fill: "none", children: [jsx("g", { "clip-path": "url(#clip0_520_6)", children: 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" }) }), jsx("defs", { children: jsx("clipPath", { id: "clip0_520_6", children: jsx("rect", { width: "16", height: "18", fill: "white" }) }) })] }), allowOrder && order?.direction === 'desc' && jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", className: 'ms-25', width: "10", height: "10", viewBox: "0 0 16 18", fill: "none", children: [jsx("g", { "clip-path": "url(#clip0_520_2)", children: 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" }) }), jsx("defs", { children: jsx("clipPath", { id: "clip0_520_2", children: jsx("rect", { width: "16", height: "18", fill: "white" }) }) })] }), allowFilter && jsxs(Dropdown$1, { isOpen: openFilter, toggle: (e) => {
|
|
65436
|
+
setOpenFilter(!openFilter);
|
|
65437
|
+
e.stopPropagation();
|
|
65438
|
+
}, onClick: (e) => {
|
|
65439
|
+
e.stopPropagation();
|
|
65440
|
+
}, children: [jsx(DropdownToggle$1, { tag: 'div', className: 'p-0 r-filter', children: jsxs("svg", { className: classNames$1('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: [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" }), " "] }) }), jsx(DropdownMenu$1, { container: container, className: 'formula-dropdown icon-dropdown p-0', style: {
|
|
65441
|
+
borderRadius: 8,
|
|
65442
|
+
zIndex: 1056
|
|
65443
|
+
}, children: jsx(DropdownItem$1, { className: 'p-1', style: { borderRadius: '6px' }, tag: 'div', header: true, children: jsx(RenderFilterElement, { setOpenFilter: setOpenFilter, filter: filter, filterBy: filterBy, optionsFilter: optionsFilter, formatSetting: formatSetting, changeFilter: changeFilter, column: col }) }) })] })] })] })] }) }) })) }, `header-${indexCol}`));
|
|
65444
|
+
};
|
|
65445
|
+
const RenderFilterElement = ({ filter, optionsFilter, formatSetting, filterBy, setOpenFilter, changeFilter, column }) => {
|
|
65446
|
+
const { t } = useTranslation();
|
|
65447
|
+
const [operator, setOperator] = useState(filter?.ope ?? ((!column.filterType && column.type === 'numeric') || column.filterType === 'select' ? 'equal' : 'contains'));
|
|
65448
|
+
const [valueFilter, setValueFilter] = useState(filter?.value ?? '');
|
|
65449
|
+
const RenderStringFilter = () => {
|
|
65450
|
+
const options = [
|
|
65451
|
+
{ label: 'Bắt đầu bởi', value: 'startswith' },
|
|
65452
|
+
{ label: 'Kết thúc bởi', value: 'endswith' },
|
|
65453
|
+
{ label: 'Chứa', value: 'contains' },
|
|
65454
|
+
{ label: 'Bằng', value: 'equal' },
|
|
65455
|
+
{ label: 'Không bằng', value: 'notequal' }
|
|
65456
|
+
];
|
|
65457
|
+
return (jsxs(Fragment$1, { children: [jsx(SelectTable, { value: options.find((x) => x.value === (operator)), options: options, onChange: (val) => {
|
|
65458
|
+
setOperator(val.value);
|
|
65459
|
+
}, placeholder: 'Select' }), jsx(Input$1, { className: 'my-1', value: valueFilter, onChange: (val) => {
|
|
65460
|
+
setValueFilter(val.target.value);
|
|
65461
|
+
} })] }));
|
|
65462
|
+
};
|
|
65463
|
+
const RenderNumberFilter = () => {
|
|
65464
|
+
const options = [
|
|
65465
|
+
{ label: 'Lớn hơn', value: 'greaterthan' },
|
|
65466
|
+
{ label: 'Lớn hơn hoặc bằng', value: 'greaterthanorequal' },
|
|
65467
|
+
{ label: 'Bằng', value: 'equal' },
|
|
65468
|
+
{ label: 'Bé hơn', value: 'lessthan' },
|
|
65469
|
+
{ label: 'Bé hơn hoặc bằng', value: 'lessthanorequal' }
|
|
65470
|
+
];
|
|
65471
|
+
const numericFormatProps = {
|
|
65472
|
+
value: !isNullOrUndefined$1(valueFilter) ? valueFilter.toString() : '',
|
|
65473
|
+
thousandSeparator: checkThousandSeparator(formatSetting?.thousandSeparator, formatSetting?.decimalSeparator),
|
|
65474
|
+
decimalSeparator: checkDecimalSeparator(formatSetting?.thousandSeparator, formatSetting?.decimalSeparator),
|
|
65475
|
+
allowNegative: column.numericSettings?.allowNegative ?? false,
|
|
65476
|
+
decimalScale: column.numericSettings?.fraction ?? 0
|
|
65477
|
+
};
|
|
65478
|
+
let floatValue = parseFloat(valueFilter ?? '0');
|
|
65479
|
+
return (jsxs(Fragment$1, { children: [jsx(SelectTable, { value: options.find((x) => x.value === (operator)), options: options, onChange: (val) => {
|
|
65480
|
+
setOperator(val.value);
|
|
65481
|
+
}, placeholder: t('Select') }), 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) => {
|
|
65482
|
+
floatValue = values?.floatValue;
|
|
65483
|
+
}, onFocus: (e) => {
|
|
65484
|
+
e.target.setSelectionRange(0, e.target.innerText.length - 1);
|
|
65485
|
+
}, onBlur: () => {
|
|
65486
|
+
if (floatValue !== valueFilter) {
|
|
65487
|
+
setValueFilter(!isNaN(floatValue) ? floatValue : 0);
|
|
65488
|
+
}
|
|
65489
|
+
} })] }));
|
|
65490
|
+
};
|
|
65491
|
+
const RenderSelectFilter = () => {
|
|
65492
|
+
return (jsx("div", { className: 'mb-1', children: jsx(SelectTable, { value: optionsFilter ? optionsFilter[column.field]?.find((x) => x.value === valueFilter) : undefined, options: (optionsFilter && optionsFilter[column.field]) ?? [], isClearable: true, onChange: (val) => {
|
|
65493
|
+
setValueFilter(val?.value);
|
|
65494
|
+
}, placeholder: t('Select') }) }));
|
|
65495
|
+
};
|
|
65496
|
+
const handleSave = () => {
|
|
65497
|
+
if (valueFilter || valueFilter === 0) {
|
|
65498
|
+
if (filter) {
|
|
65499
|
+
filter.ope = operator;
|
|
65500
|
+
filter.value = valueFilter;
|
|
65501
|
+
}
|
|
65502
|
+
else {
|
|
65503
|
+
filterBy.push({ key: column.field, ope: operator, value: valueFilter });
|
|
65504
|
+
}
|
|
65505
|
+
changeFilter([...filterBy]);
|
|
65506
|
+
}
|
|
65507
|
+
else {
|
|
65508
|
+
changeFilter(filterBy.filter((x) => x.key !== column.field));
|
|
65509
|
+
}
|
|
65510
|
+
setOpenFilter(false);
|
|
65511
|
+
};
|
|
65512
|
+
return (jsxs("div", { className: 'r-filter-popup', onKeyDown: (e) => {
|
|
65513
|
+
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
|
|
65514
|
+
handleSave();
|
|
65515
|
+
e.stopPropagation();
|
|
65516
|
+
}
|
|
65517
|
+
}, children: [((!column.filterType && column.type === 'numeric') || column.filterType === 'numeric') ? jsxs(Fragment$1, { children: [RenderNumberFilter(), " "] }) : (column.filterType === 'select' ? jsxs(Fragment$1, { children: [RenderSelectFilter(), " "] }) : RenderStringFilter()), jsxs("div", { className: 'd-flex justify-content-end', children: [jsx(Button$1, { outline: true, color: 'primary', style: { borderRadius: 3 }, className: 'me-50 py-25 px-50', onClick: handleSave, children: t('Filter') }), jsx(Button$1, { className: 'py-25 px-50', outline: true, style: { borderRadius: 3 }, onClick: () => {
|
|
65518
|
+
if (filterBy) {
|
|
65519
|
+
changeFilter(filterBy.filter((x) => x.key !== column.field));
|
|
65520
|
+
}
|
|
65521
|
+
setOpenFilter(false);
|
|
65522
|
+
}, children: t('Clear') })] })] }));
|
|
65523
|
+
};
|
|
65524
|
+
|
|
65525
|
+
const RenderContentCol = (props) => {
|
|
65526
|
+
const { col, indexCol, indexRow, isSelected, row, formatSetting, idTable, fisrtObjWidthFixRight, lastObjWidthFixLeft, objWidthFixLeft, objWidthFixRight, selectedRows, selectEnable, setSelectedRows, handleCommandClick, fieldKey, isMulti } = props;
|
|
65527
|
+
const RenderElement = () => {
|
|
65528
|
+
if (col.type === 'command') {
|
|
65529
|
+
return jsx("div", { className: "r-rowcell-div command", children: jsx(CommandElement, { commandItems: col.commandItems ?? [], handleCommandClick: handleCommandClick, indexRow: indexRow, rowData: row }) });
|
|
65530
|
+
}
|
|
65531
|
+
else if (col.type === '#') {
|
|
65532
|
+
jsx("div", { className: "r-rowcell-div", children: indexRow + 1 });
|
|
65533
|
+
}
|
|
65534
|
+
else if (col.type === 'checkbox') {
|
|
65535
|
+
return (jsx("div", { className: "r-rowcell-div cursor-pointer", style: { alignItems: 'center' }, onClick: (e) => {
|
|
65536
|
+
if (selectEnable) {
|
|
65537
|
+
const index = selectedRows?.findIndex((x) => x[fieldKey] === row[fieldKey]);
|
|
65538
|
+
if (index > -1) {
|
|
65539
|
+
if (isMulti) {
|
|
65540
|
+
selectedRows?.splice(index, 1);
|
|
65541
|
+
setSelectedRows([...selectedRows]);
|
|
65542
|
+
}
|
|
65543
|
+
else {
|
|
65544
|
+
setSelectedRows([]);
|
|
65545
|
+
}
|
|
65546
|
+
}
|
|
65547
|
+
else {
|
|
65548
|
+
if (isMulti) {
|
|
65549
|
+
setSelectedRows([...selectedRows, row]);
|
|
65550
|
+
}
|
|
65551
|
+
else {
|
|
65552
|
+
setSelectedRows([row]);
|
|
65553
|
+
}
|
|
65554
|
+
}
|
|
65555
|
+
e.stopPropagation();
|
|
65556
|
+
}
|
|
65557
|
+
}, children: jsx(Input$1, { checked: isSelected, type: "checkbox", className: "cursor-pointer", style: { textAlign: col.textAlign ?? 'center' } }) }));
|
|
65558
|
+
}
|
|
65559
|
+
else {
|
|
65560
|
+
let value = row[col.field];
|
|
65561
|
+
if (col.type === 'numeric') {
|
|
65562
|
+
value = formartNumberic(row[col.field], formatSetting?.decimalSeparator ?? ',', formatSetting?.thousandSeparator ?? '.', col.numericSettings?.fraction, true, false) ?? 0;
|
|
65563
|
+
}
|
|
65564
|
+
else if (col.type === 'date') {
|
|
65565
|
+
value = value ? formatDateTime(value, formatSetting?.dateFormat) : '';
|
|
65566
|
+
}
|
|
65567
|
+
else if (col.type === 'datetime') {
|
|
65568
|
+
value = value ? formatDateTime(value, formatSetting?.dateFormat ?? 'DD/MM/yyyy HH:mm') : '';
|
|
65569
|
+
}
|
|
65570
|
+
if (col.template) {
|
|
65571
|
+
value = col.template(row, indexRow) ?? '';
|
|
65572
|
+
}
|
|
65573
|
+
return (jsx("div", { className: classNames$1('r-rowcell-div'), children: jsxs("div", { className: classNames$1('r-rowcell-content'), style: {
|
|
65574
|
+
textAlign: col.textAlign ? col.textAlign : 'left'
|
|
65575
|
+
}, children: [jsx("div", { id: `content-${idTable}-row${indexRow}col-${indexCol}`, className: "r-cell-text", children: (col.type === 'numeric' && Number(row[col.field]) < 0 ? jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), col.haveToolTip && jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `content-${idTable}-row${indexRow}col-${indexCol}`, children: (col.type === 'numeric' && Number(row[col.field]) < 0 ? jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) })] }) }));
|
|
65576
|
+
}
|
|
65577
|
+
};
|
|
65578
|
+
return (col.visible !== false && jsx("td", { className: classNames$1(`r-rowcell fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'fixed-last': (col.fixedType === 'left' && indexCol === lastObjWidthFixLeft) || (col.fixedType === 'right' && indexCol === fisrtObjWidthFixRight) }, { 'r-active': isSelected }), style: {
|
|
65579
|
+
left: col.fixedType === 'left' ? objWidthFixLeft[indexCol] : undefined,
|
|
65580
|
+
right: col.fixedType === 'right' ? objWidthFixRight[indexCol] : undefined
|
|
65581
|
+
}, onClick: (e) => {
|
|
65582
|
+
if (e.target.nodeName === 'DIV' || e.target.nodeName === 'TD') {
|
|
65583
|
+
if (selectEnable) {
|
|
65584
|
+
const index = selectedRows?.findIndex((x) => x[fieldKey] === row[fieldKey]);
|
|
65585
|
+
if (index > -1) {
|
|
65586
|
+
if (isMulti) {
|
|
65587
|
+
selectedRows?.splice(index, 1);
|
|
65588
|
+
setSelectedRows([...selectedRows]);
|
|
65589
|
+
}
|
|
65590
|
+
else {
|
|
65591
|
+
setSelectedRows([]);
|
|
65592
|
+
}
|
|
65593
|
+
}
|
|
65594
|
+
else {
|
|
65595
|
+
if (isMulti) {
|
|
65596
|
+
setSelectedRows([...selectedRows, row]);
|
|
65597
|
+
}
|
|
65598
|
+
else {
|
|
65599
|
+
setSelectedRows([row]);
|
|
65600
|
+
}
|
|
65601
|
+
}
|
|
65602
|
+
}
|
|
65603
|
+
e.stopPropagation();
|
|
65604
|
+
}
|
|
65605
|
+
}, children: RenderElement() }, `col-${indexRow}-${indexCol}`));
|
|
65606
|
+
};
|
|
65607
|
+
|
|
65608
|
+
const RenderColGroup = ({ contentColumns }) => (jsx("colgroup", { children: contentColumns.map((col, index) => (jsx("col", { style: {
|
|
65609
|
+
width: typeof col.width === 'number' ? `${col.width}px` : col.width || undefined,
|
|
65610
|
+
minWidth: typeof col.minWidth === 'number' ? `${col.minWidth}px` : col.minWidth || undefined,
|
|
65611
|
+
maxWidth: typeof col.maxWidth === 'number' ? `${col.maxWidth}px` : col.maxWidth || undefined
|
|
65612
|
+
} }, index))) }));
|
|
65613
|
+
|
|
65614
|
+
const VirtualTable = ({ idTable, dataSource, rowHeight = 33, height = 400, columns, isMutil, isLoading, selectEnable, formatSetting, commandClick, allowFilter, allowOrder, setColumns, pagingSetting, changeFilter, changeOrder, searchSetting, columnsAggregate, toolbarSetting, optionsFilter }) => {
|
|
65615
|
+
const gridRef = useRef(null);
|
|
65616
|
+
const [startIndex, setStartIndex] = useState(0);
|
|
65617
|
+
const [selectedRows, setSelectedRows] = useState([]);
|
|
65618
|
+
const [orderBy, setOrderBy] = useState([]);
|
|
65619
|
+
const [filterBy, setFilterBy] = useState([]);
|
|
65620
|
+
const [searchTerm, setSearchTerm] = useState('');
|
|
65621
|
+
const fieldKey = columns.find((item) => item.isPrimarykey === true)?.field ?? 'id';
|
|
65622
|
+
//trường liên quan đến virtul loading
|
|
65623
|
+
const visibleRowCount = Math.ceil(height / rowHeight) + 5;
|
|
65624
|
+
const buffer = 10; // số dòng dự phòng phía trên và dưới
|
|
65625
|
+
const adjustedStartIndex = Math.max(startIndex - buffer, 0);
|
|
65626
|
+
const adjustedEndIndex = Math.min(startIndex + visibleRowCount + buffer, dataSource.length);
|
|
65627
|
+
const visibleData = dataSource.slice(adjustedStartIndex, adjustedEndIndex);
|
|
65628
|
+
const { t } = useTranslation();
|
|
65629
|
+
const { levels: headerColumns, flat: contentColumns, flatVisble, objWidthFixLeft, objWidthFixRight, lastObjWidthFixLeft, fisrtObjWidthFixRight } = useMemo(() => calculateTableStructure(columns), [columns]);
|
|
65630
|
+
const scrollTimeoutRef = useRef(null);
|
|
65631
|
+
const lastScrollTop = useRef(0);
|
|
65632
|
+
const handleScroll = (e) => {
|
|
65633
|
+
if (!gridRef.current) {
|
|
65634
|
+
return;
|
|
65635
|
+
}
|
|
65636
|
+
// Nếu không có sự thay đổi về scrollTop => người dùng chỉ scroll ngang => không xử lý
|
|
65637
|
+
if (e.target.scrollTop === lastScrollTop.current) {
|
|
65638
|
+
return;
|
|
65639
|
+
}
|
|
65640
|
+
lastScrollTop.current = e.target.scrollTop;
|
|
65641
|
+
if (scrollTimeoutRef.current !== null) {
|
|
65642
|
+
cancelAnimationFrame(scrollTimeoutRef.current);
|
|
65643
|
+
}
|
|
65644
|
+
scrollTimeoutRef.current = requestAnimationFrame(() => {
|
|
65645
|
+
const scrollTop = gridRef.current.scrollTop;
|
|
65646
|
+
const newStartIndex = Math.floor(scrollTop / rowHeight);
|
|
65647
|
+
if (newStartIndex !== startIndex) {
|
|
65648
|
+
setStartIndex(newStartIndex);
|
|
65649
|
+
}
|
|
65650
|
+
});
|
|
65651
|
+
};
|
|
65652
|
+
const handleCommandClick = (id, rowData, index) => {
|
|
65653
|
+
if (commandClick) {
|
|
65654
|
+
commandClick({ id, rowData, index });
|
|
65655
|
+
}
|
|
65656
|
+
};
|
|
65657
|
+
const handleKeyPress = (e) => {
|
|
65658
|
+
if ((e.code === 'Enter' || e.code === 'NumpadEnter')) {
|
|
65659
|
+
if (searchSetting?.setSearchTerm) {
|
|
65660
|
+
searchSetting?.setSearchTerm(e.target.value);
|
|
65661
|
+
}
|
|
65662
|
+
else {
|
|
65663
|
+
setSearchTerm(e.target.value);
|
|
65664
|
+
}
|
|
65665
|
+
e.stopPropagation();
|
|
65666
|
+
e.preventDefault();
|
|
65667
|
+
}
|
|
65668
|
+
};
|
|
65669
|
+
const searchTemplate = () => {
|
|
65670
|
+
return (jsx("div", { className: "me-50 r-search", children: jsx(ReactInput, { style: { width: '230px' }, value: searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm, setSearchTerm: searchSetting?.setSearchTerm ? searchSetting?.setSearchTerm : setSearchTerm, placeholder: t('Search'), onKeyPress: handleKeyPress }) }));
|
|
65671
|
+
};
|
|
65672
|
+
const defaultToolbarOption = searchSetting?.searchEnable ? [{ template: searchTemplate, align: 'left' }] : [];
|
|
65673
|
+
let toolbarTopOption = [];
|
|
65674
|
+
if (toolbarSetting?.toolbarOptions) {
|
|
65675
|
+
toolbarTopOption = [...defaultToolbarOption, ...toolbarSetting?.toolbarOptions];
|
|
65676
|
+
}
|
|
65677
|
+
else {
|
|
65678
|
+
toolbarTopOption = [...defaultToolbarOption];
|
|
65679
|
+
}
|
|
65680
|
+
const onChangePage = (args) => {
|
|
65681
|
+
if (pagingSetting?.setCurrentPage) {
|
|
65682
|
+
if (args.currentPage === args.oldPage) {
|
|
65683
|
+
return;
|
|
65684
|
+
}
|
|
65685
|
+
pagingSetting.setCurrentPage(args.currentPage);
|
|
65686
|
+
}
|
|
65687
|
+
};
|
|
65688
|
+
const onChangePageSize = (args) => {
|
|
65689
|
+
if (pagingSetting?.allowPaging) {
|
|
65690
|
+
if (pagingSetting?.pageSize !== args.pageSize) {
|
|
65691
|
+
if (pagingSetting?.setPageSize) {
|
|
65692
|
+
pagingSetting.setPageSize(args.pageSize);
|
|
65693
|
+
}
|
|
65694
|
+
if (pagingSetting?.setCurrentPage) {
|
|
65695
|
+
pagingSetting.setCurrentPage(1);
|
|
65696
|
+
}
|
|
65697
|
+
}
|
|
65698
|
+
}
|
|
65699
|
+
};
|
|
65700
|
+
return (jsxs("div", { className: "react-table-edit", children: [jsxs("div", { className: 'r-grid', children: [toolbarSetting?.showTopToolbar && jsx(RenderToolbarTop, { toolbarTopOption: toolbarTopOption }), jsxs("div", { ref: gridRef, className: "r-gridtable", onScroll: handleScroll, style: { height: `${height ? `${height}px` : 'auto'}` }, children: [jsxs("table", { style: { width: '100%' }, children: [jsx(RenderColGroup, { contentColumns: flatVisble }), jsx("thead", { className: 'r-gridheader', children: headerColumns.map((rowColumn, indexParent) => (jsx("tr", { className: "r-row", role: "row", children: rowColumn.map((column, indexColumn) => (jsx(HeaderTableCol, { idTable: idTable, col: column, dataSource: dataSource, indexCol: indexColumn, indexParent: indexParent, isMulti: isMutil ?? false, selectEnable: selectEnable ?? false, selectedRows: selectedRows, setSelectedRows: setSelectedRows, columns: contentColumns, setColumns: setColumns, objWidthFixLeft: objWidthFixLeft, objWidthFixRight: objWidthFixRight, fisrtObjWidthFixRight: fisrtObjWidthFixRight, lastObjWidthFixLeft: lastObjWidthFixLeft, orderBy: orderBy, allowFilter: allowFilter, allowOrder: allowOrder, filterBy: filterBy, optionsFilter: optionsFilter, changeFilter: (val) => {
|
|
65701
|
+
setFilterBy([...val]);
|
|
65702
|
+
if (changeFilter) {
|
|
65703
|
+
changeFilter(val);
|
|
65704
|
+
}
|
|
65705
|
+
}, changeOrder: (val) => {
|
|
65706
|
+
setOrderBy([...val]);
|
|
65707
|
+
if (changeOrder) {
|
|
65708
|
+
changeOrder(val);
|
|
65709
|
+
}
|
|
65710
|
+
}, container: gridRef, totalCount: dataSource.length }, `header-${indexParent}-${indexColumn}`))) }, indexParent))) }), jsxs("tbody", { className: 'r-gridcontent', children: [adjustedStartIndex > 0 && (jsx("tr", { style: { height: adjustedStartIndex * rowHeight }, children: jsx("td", { style: { padding: 0 }, colSpan: flatVisble.length }) })), visibleData.map((row, index) => {
|
|
65711
|
+
const indexRow = index + startIndex;
|
|
65712
|
+
const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
|
|
65713
|
+
return (jsx("tr", { className: classNames$1('r-row'), children: contentColumns.map((column, indexCol) => (jsx(RenderContentCol, { idTable: idTable, col: column, fieldKey: 'field', objWidthFixLeft: objWidthFixLeft, objWidthFixRight: objWidthFixRight, fisrtObjWidthFixRight: fisrtObjWidthFixRight, lastObjWidthFixLeft: lastObjWidthFixLeft, isMulti: isMutil ?? false, selectEnable: selectEnable ?? false, selectedRows: selectedRows, setSelectedRows: setSelectedRows, formatSetting: formatSetting, handleCommandClick: handleCommandClick, indexCol: indexCol, indexRow: indexRow, isSelected: isSelected, row: row }, indexCol))) }, `row-${indexRow}`));
|
|
65714
|
+
}), dataSource.length > adjustedEndIndex && (jsx("tr", { style: { height: (dataSource.length - adjustedEndIndex) * rowHeight }, children: jsx("td", { style: { padding: 0 }, colSpan: flatVisble.length }) }))] }), dataSource.length > 0 && jsx("tfoot", { className: "r-gridfoot", children: (columnsAggregate?.length ?? 0) > 0 ? jsx("tr", { className: 'r-row', children: contentColumns.map((col, indexCol) => {
|
|
65715
|
+
const item = columnsAggregate?.find((x) => x.field === col.field);
|
|
65716
|
+
let sumValue = item?.value;
|
|
65717
|
+
if (!item && col.haveSum === true && col.type === "numeric") {
|
|
65718
|
+
sumValue = dataSource.reduce(function (accumulator, currentValue) { return (Number(accumulator ?? 0) + Number(currentValue[col.field] ?? 0)); }, 0);
|
|
65719
|
+
}
|
|
65720
|
+
return col.visible !== false && jsx("td", { className: classNames$1(`p-0 px-50 r-footer fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }), style: {
|
|
65721
|
+
left: col.fixedType === 'left' ? objWidthFixLeft[indexCol] : undefined,
|
|
65722
|
+
right: col.fixedType === 'right' ? objWidthFixRight[indexCol] : undefined,
|
|
65723
|
+
textAlign: col.textAlign ? col.textAlign : 'left'
|
|
65724
|
+
}, children: jsxs("div", { className: "r-footer-div", children: [(item || (col.haveSum === true && col.type === "numeric")) && col.type === "numeric" && (Number(sumValue) >= 0) && jsx(Fragment$1, { children: formartNumberic(sumValue, formatSetting?.decimalSeparator ?? ',', formatSetting?.thousandSeparator ?? '.', col.numericSettings?.fraction, true, false) }), (item || (col.haveSum === true && col.type === "numeric")) && col.type === "numeric" && (Number(sumValue) < 0) && 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}`);
|
|
65725
|
+
}) }) : jsx(Fragment$1, {}) })] }), (((dataSource.length ?? 0) === 0) && !isLoading) && jsxs("div", { className: "r-no-data", children: [jsx("svg", { width: "64", height: "41", viewBox: "0 0 64 41", xmlns: "http://www.w3.org/2000/svg", children: jsxs("g", { transform: "translate(0 1)", fill: "none", fillRule: "evenodd", children: [jsx("ellipse", { fill: "#f5f5f5", cx: "32", cy: "33", rx: "32", ry: "7" }), jsxs("g", { fillRule: "nonzero", stroke: "#d9d9d9", children: [jsx("path", { d: "M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z" }), jsx("path", { d: "M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z", fill: "#fafafa" })] })] }) }), t('No data available.')] }), isLoading && jsx("div", { className: "r-loading-overlay", children: jsxs("div", { className: "r-loading", children: [jsx(Spinner$1, { className: "me-1" }), t('Loading...')] }) })] })] }), pagingSetting?.allowPaging ? jsx(PagingComponent, { onChangePage: onChangePage, pageSize: pagingSetting?.pageSize ?? 0, currentPage: pagingSetting?.currentPage ?? 0, pageOptions: pagingSetting?.pageOptions ?? [20, 30, 50, 100], totalItem: (pagingSetting?.totalItem ?? 0), onChangePageSize: onChangePageSize }) : jsx(Fragment$1, {})] }));
|
|
65726
|
+
};
|
|
65727
|
+
|
|
65728
|
+
export { ExportExcelComponent, FindNodeByPath, ImportExcelComponent, InputStyleComponent, SelectTable, SelectTableTree, TabsMenuComponent, VirtualTable, Wizard, calculateTableStructure, checkDecimalSeparator, checkThousandSeparator, TableEdit as default, formartNumberic, formatDateTime, generateUUID, isNullOrUndefined$1 as isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, roundNumber, useOnClickOutside };
|
|
65382
65729
|
//# sourceMappingURL=index.mjs.map
|