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.
@@ -375,7 +375,10 @@ export type IColumnVirtualizedTable = {
375
375
  visible?: boolean;
376
376
  /** Kiểu xem cột */
377
377
  type?: IViewType;
378
- settingFilter?: IFSettingFilterColumn;
378
+ /** Kiểu lọc cột */
379
+ filterType?: IFilterType;
380
+ /** Cho phép lọc cột */
381
+ allowFilter?: boolean;
379
382
  /** Căn lề */
380
383
  textAlign?: ITextAlign;
381
384
  /** Cố định trái/phải */
@@ -393,12 +396,6 @@ export type IColumnVirtualizedTable = {
393
396
  /** Số dòng chiếm (rowspan) */
394
397
  rowspan?: number;
395
398
  };
396
- export type IFSettingFilterColumn = {
397
- /** Kiểu lọc cột */
398
- filterType?: IFilterType;
399
- allowFilter?: boolean;
400
- options: any[];
401
- };
402
399
  export type IFOrderTable = {
403
400
  key: string;
404
401
  direction: 'asc' | 'desc';
@@ -2,6 +2,7 @@ import { Dispatch, SetStateAction } from 'react';
2
2
  import { IColumnVirtualizedTable, IFFilterTable, IFOrderTable, IFTableEditFormat } from "../type";
3
3
  import 'react-resizable/css/styles.css';
4
4
  type IFDataProps = {
5
+ idTable: string;
5
6
  selectEnable: boolean;
6
7
  dataSource: any[];
7
8
  setSelectedRows: Dispatch<SetStateAction<any[]>>;
@@ -24,6 +25,7 @@ type IFDataProps = {
24
25
  filterBy: IFFilterTable[];
25
26
  orderBy: IFOrderTable[];
26
27
  container: any;
28
+ optionsFilter: any;
27
29
  formatSetting?: IFTableEditFormat;
28
30
  };
29
31
  declare const HeaderTableCol: (props: IFDataProps) => import("react/jsx-runtime").JSX.Element;
@@ -16,10 +16,11 @@ type VirtualTableProps = {
16
16
  toolbarSetting?: IFTableEditToolbar;
17
17
  searchSetting?: IFTableEditSearchSetting;
18
18
  columnsAggregate?: IColumnsVirtualizedAgg[];
19
+ optionsFilter?: any;
19
20
  setColumns?: (columns: IColumnVirtualizedTable[]) => void;
20
21
  commandClick?: (data: any) => void;
21
22
  changeFilter?: (data: IFFilterTable[]) => void;
22
23
  changeOrder?: (data: IFOrderTable[]) => void;
23
24
  };
24
25
  declare const VirtualTable: React.FC<VirtualTableProps>;
25
- export default VirtualTable;
26
+ export { VirtualTable };
package/dist/index.d.ts CHANGED
@@ -379,7 +379,10 @@ type IColumnVirtualizedTable = {
379
379
  visible?: boolean;
380
380
  /** Kiểu xem cột */
381
381
  type?: IViewType;
382
- settingFilter?: IFSettingFilterColumn;
382
+ /** Kiểu lọc cột */
383
+ filterType?: IFilterType;
384
+ /** Cho phép lọc cột */
385
+ allowFilter?: boolean;
383
386
  /** Căn lề */
384
387
  textAlign?: ITextAlign;
385
388
  /** Cố định trái/phải */
@@ -397,12 +400,6 @@ type IColumnVirtualizedTable = {
397
400
  /** Số dòng chiếm (rowspan) */
398
401
  rowspan?: number;
399
402
  };
400
- type IFSettingFilterColumn = {
401
- /** Kiểu lọc cột */
402
- filterType?: IFilterType;
403
- allowFilter?: boolean;
404
- options: any[];
405
- };
406
403
  type IFOrderTable = {
407
404
  key: string;
408
405
  direction: 'asc' | 'desc';
@@ -713,4 +710,28 @@ type IFProps = {
713
710
  };
714
711
  declare const Wizard: React.ForwardRefExoticComponent<IFProps & React.RefAttributes<unknown>>;
715
712
 
716
- export { ExportExcelComponent, FindNodeByPath, type FromItemsField, type IColumnTable, type IColumnVirtualizedTable, type IColumnsVirtualizedAgg, type ICommandItem, type IFColumnSelectTable, type IFColumnSelectTableTree, type IFCurrentPage, type IFCurrentPageConfig, type IFFilterTable, type IFOrderTable, type IFPageSize, type IFPropsDetail, type IFSettingFilterColumn, type IFTableEditButton, type IFTableEditFormat, type IFTableEditPaging, type IFTableEditSearchSetting, type IFTableEditToolbar, type IFTableSelectFormat, type IFTableTreeSelectFormat, type IFToolbarOptions, type IHeaderColumnTable, type ISettingFormElement, type ISettingNumericElement, type ISettingSelectElement, ImportExcelComponent, InputStyleComponent, SelectTable, SelectTableTree, TabsMenuComponent, Wizard, calculateTableStructure, checkDecimalSeparator, checkThousandSeparator, TableEdit as default, formartNumberic, formatDateTime, generateUUID, isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, roundNumber, useOnClickOutside };
713
+ type VirtualTableProps = {
714
+ idTable: string;
715
+ dataSource: any[];
716
+ rowHeight?: number;
717
+ height?: number;
718
+ columns: IColumnVirtualizedTable[];
719
+ selectEnable?: boolean;
720
+ isMutil?: boolean;
721
+ isLoading?: boolean;
722
+ formatSetting?: IFTableEditFormat;
723
+ allowFilter?: boolean;
724
+ allowOrder?: boolean;
725
+ pagingSetting?: IFTableEditPaging;
726
+ toolbarSetting?: IFTableEditToolbar;
727
+ searchSetting?: IFTableEditSearchSetting;
728
+ columnsAggregate?: IColumnsVirtualizedAgg[];
729
+ optionsFilter?: any;
730
+ setColumns?: (columns: IColumnVirtualizedTable[]) => void;
731
+ commandClick?: (data: any) => void;
732
+ changeFilter?: (data: IFFilterTable[]) => void;
733
+ changeOrder?: (data: IFOrderTable[]) => void;
734
+ };
735
+ declare const VirtualTable: React__default.FC<VirtualTableProps>;
736
+
737
+ export { ExportExcelComponent, FindNodeByPath, type FromItemsField, type IColumnTable, type IColumnVirtualizedTable, type IColumnsVirtualizedAgg, type ICommandItem, type IFColumnSelectTable, type IFColumnSelectTableTree, type IFCurrentPage, type IFCurrentPageConfig, type IFFilterTable, type IFOrderTable, type IFPageSize, type IFPropsDetail, type IFTableEditButton, type IFTableEditFormat, type IFTableEditPaging, type IFTableEditSearchSetting, type IFTableEditToolbar, type IFTableSelectFormat, type IFTableTreeSelectFormat, type IFToolbarOptions, type IHeaderColumnTable, type ISettingFormElement, type ISettingNumericElement, type ISettingSelectElement, ImportExcelComponent, InputStyleComponent, SelectTable, SelectTableTree, TabsMenuComponent, VirtualTable, Wizard, calculateTableStructure, checkDecimalSeparator, checkThousandSeparator, TableEdit as default, formartNumberic, formatDateTime, generateUUID, isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, roundNumber, useOnClickOutside };
package/dist/index.js CHANGED
@@ -41807,7 +41807,7 @@ function styleInject(css, ref) {
41807
41807
  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}";
41808
41808
  styleInject(css_248z$1);
41809
41809
 
41810
- const HeaderTableCol = (props) => {
41810
+ const HeaderTableCol$1 = (props) => {
41811
41811
  const { selectEnable, dataSource, setSelectedRows, col, indexCol, indexParent, objWidthFixLeft, objWidthFixRight, totalCount, selectedRows, column, setColumn, fisrtObjWidthFixRight, lastObjWidthFixLeft, isMulti } = props;
41812
41812
  const { t } = reactI18next.useTranslation();
41813
41813
  const handleResize = (e, { size }) => {
@@ -43507,7 +43507,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
43507
43507
  }, [searchTerm, searchSetting?.searchTerm]);
43508
43508
  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) => {
43509
43509
  return (jsxRuntime.jsx("tr", { className: "r-row", role: "row", children: element?.map((col, index) => {
43510
- return (jsxRuntime.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}`));
43510
+ return (jsxRuntime.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}`));
43511
43511
  }) }, `header-${-indexParent}`));
43512
43512
  }) }), 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) => {
43513
43513
  return (renderFooterCol(col, index));
@@ -65406,6 +65406,353 @@ const ImportExcelComponent = (props) => {
65406
65406
  ] }) }));
65407
65407
  };
65408
65408
 
65409
+ const HeaderTableCol = (props) => {
65410
+ 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;
65411
+ const { t } = reactI18next.useTranslation();
65412
+ const headerRef = React$5.useRef(null);
65413
+ const order = orderBy.find((item) => item.key === col.field);
65414
+ const [openFilter, setOpenFilter] = React$5.useState(false);
65415
+ const filter = filterBy.find((item) => item.key === col.field);
65416
+ const handleResize = (e, { size }) => {
65417
+ // Update the column width here
65418
+ // You might need to update the state or call a callback to update the width
65419
+ if (size.width > 50) {
65420
+ const newColumns = [...columns];
65421
+ newColumns[indexCol].width = size.width;
65422
+ if ((columns[indexCol]?.maxWidth ?? 0) < size.width) {
65423
+ newColumns[indexCol].maxWidth = size.width;
65424
+ }
65425
+ if ((columns[indexCol]?.minWidth ?? 0) > size.width) {
65426
+ newColumns[indexCol].minWidth = size.width;
65427
+ }
65428
+ if (setColumns) {
65429
+ setColumns(newColumns);
65430
+ }
65431
+ }
65432
+ };
65433
+ const checkOverflow = () => {
65434
+ return headerRef.current && headerRef.current.scrollHeight > headerRef.current.clientHeight;
65435
+ };
65436
+ 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: {
65437
+ top: `${indexParent * 42}px`,
65438
+ left: col.fixedType === 'left' ? objWidthFixLeft[indexCol ?? 0] : undefined,
65439
+ right: col.fixedType === 'right' ? objWidthFixRight[indexCol ?? 0] : undefined
65440
+ }, children: jsxRuntime.jsxs("div", { style: { justifyContent: 'space-between' }, onClick: () => {
65441
+ if (order) {
65442
+ if (order.direction === 'asc') {
65443
+ order.direction = 'desc';
65444
+ changeOrder(orderBy);
65445
+ }
65446
+ else {
65447
+ changeOrder(orderBy.filter((x) => x.key !== col.field));
65448
+ }
65449
+ }
65450
+ else {
65451
+ orderBy.push({ direction: 'asc', key: col.field });
65452
+ changeOrder(orderBy);
65453
+ }
65454
+ }, className: classNames$1('r-headercell-div', { 'cursor-pointer': allowOrder }), children: [col.type === '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) => {
65455
+ if (selectEnable) {
65456
+ if (e.target.checked) {
65457
+ setSelectedRows(dataSource.map((item) => { return item; }));
65458
+ }
65459
+ else {
65460
+ setSelectedRows([]);
65461
+ }
65462
+ }
65463
+ } })), col.type !== '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.type !== '#' && col.type !== '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 && jsxRuntime.jsxs(Dropdown$1, { isOpen: openFilter, toggle: (e) => {
65464
+ setOpenFilter(!openFilter);
65465
+ e.stopPropagation();
65466
+ }, onClick: (e) => {
65467
+ e.stopPropagation();
65468
+ }, children: [jsxRuntime.jsx(DropdownToggle$1, { tag: 'div', className: 'p-0 r-filter', children: jsxRuntime.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: [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: {
65469
+ borderRadius: 8,
65470
+ zIndex: 1056
65471
+ }, children: jsxRuntime.jsx(DropdownItem$1, { className: 'p-1', style: { borderRadius: '6px' }, tag: 'div', header: true, children: jsxRuntime.jsx(RenderFilterElement, { setOpenFilter: setOpenFilter, filter: filter, filterBy: filterBy, optionsFilter: optionsFilter, formatSetting: formatSetting, changeFilter: changeFilter, column: col }) }) })] })] })] })] }) }) })) }, `header-${indexCol}`));
65472
+ };
65473
+ const RenderFilterElement = ({ filter, optionsFilter, formatSetting, filterBy, setOpenFilter, changeFilter, column }) => {
65474
+ const { t } = reactI18next.useTranslation();
65475
+ const [operator, setOperator] = React$5.useState(filter?.ope ?? ((!column.filterType && column.type === 'numeric') || column.filterType === 'select' ? 'equal' : 'contains'));
65476
+ const [valueFilter, setValueFilter] = React$5.useState(filter?.value ?? '');
65477
+ const RenderStringFilter = () => {
65478
+ const options = [
65479
+ { label: 'Bắt đầu bởi', value: 'startswith' },
65480
+ { label: 'Kết thúc bởi', value: 'endswith' },
65481
+ { label: 'Chứa', value: 'contains' },
65482
+ { label: 'Bằng', value: 'equal' },
65483
+ { label: 'Không bằng', value: 'notequal' }
65484
+ ];
65485
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(SelectTable, { value: options.find((x) => x.value === (operator)), options: options, onChange: (val) => {
65486
+ setOperator(val.value);
65487
+ }, placeholder: 'Select' }), jsxRuntime.jsx(Input$1, { className: 'my-1', value: valueFilter, onChange: (val) => {
65488
+ setValueFilter(val.target.value);
65489
+ } })] }));
65490
+ };
65491
+ const RenderNumberFilter = () => {
65492
+ const options = [
65493
+ { label: 'Lớn hơn', value: 'greaterthan' },
65494
+ { label: 'Lớn hơn hoặc bằng', value: 'greaterthanorequal' },
65495
+ { label: 'Bằng', value: 'equal' },
65496
+ { label: 'Bé hơn', value: 'lessthan' },
65497
+ { label: 'Bé hơn hoặc bằng', value: 'lessthanorequal' }
65498
+ ];
65499
+ const numericFormatProps = {
65500
+ value: !isNullOrUndefined$1(valueFilter) ? valueFilter.toString() : '',
65501
+ thousandSeparator: checkThousandSeparator(formatSetting?.thousandSeparator, formatSetting?.decimalSeparator),
65502
+ decimalSeparator: checkDecimalSeparator(formatSetting?.thousandSeparator, formatSetting?.decimalSeparator),
65503
+ allowNegative: column.numericSettings?.allowNegative ?? false,
65504
+ decimalScale: column.numericSettings?.fraction ?? 0
65505
+ };
65506
+ let floatValue = parseFloat(valueFilter ?? '0');
65507
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(SelectTable, { value: options.find((x) => x.value === (operator)), options: options, onChange: (val) => {
65508
+ setOperator(val.value);
65509
+ }, 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) => {
65510
+ floatValue = values?.floatValue;
65511
+ }, onFocus: (e) => {
65512
+ e.target.setSelectionRange(0, e.target.innerText.length - 1);
65513
+ }, onBlur: () => {
65514
+ if (floatValue !== valueFilter) {
65515
+ setValueFilter(!isNaN(floatValue) ? floatValue : 0);
65516
+ }
65517
+ } })] }));
65518
+ };
65519
+ const RenderSelectFilter = () => {
65520
+ 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) => {
65521
+ setValueFilter(val?.value);
65522
+ }, placeholder: t('Select') }) }));
65523
+ };
65524
+ const handleSave = () => {
65525
+ if (valueFilter || valueFilter === 0) {
65526
+ if (filter) {
65527
+ filter.ope = operator;
65528
+ filter.value = valueFilter;
65529
+ }
65530
+ else {
65531
+ filterBy.push({ key: column.field, ope: operator, value: valueFilter });
65532
+ }
65533
+ changeFilter([...filterBy]);
65534
+ }
65535
+ else {
65536
+ changeFilter(filterBy.filter((x) => x.key !== column.field));
65537
+ }
65538
+ setOpenFilter(false);
65539
+ };
65540
+ return (jsxRuntime.jsxs("div", { className: 'r-filter-popup', onKeyDown: (e) => {
65541
+ if (e.code === 'Enter' || e.code === 'NumpadEnter') {
65542
+ handleSave();
65543
+ e.stopPropagation();
65544
+ }
65545
+ }, children: [((!column.filterType && column.type === '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, { outline: true, color: 'primary', style: { borderRadius: 3 }, className: 'me-50 py-25 px-50', onClick: handleSave, children: t('Filter') }), jsxRuntime.jsx(Button$1, { className: 'py-25 px-50', outline: true, style: { borderRadius: 3 }, onClick: () => {
65546
+ if (filterBy) {
65547
+ changeFilter(filterBy.filter((x) => x.key !== column.field));
65548
+ }
65549
+ setOpenFilter(false);
65550
+ }, children: t('Clear') })] })] }));
65551
+ };
65552
+
65553
+ const RenderContentCol = (props) => {
65554
+ const { col, indexCol, indexRow, isSelected, row, formatSetting, idTable, fisrtObjWidthFixRight, lastObjWidthFixLeft, objWidthFixLeft, objWidthFixRight, selectedRows, selectEnable, setSelectedRows, handleCommandClick, fieldKey, isMulti } = props;
65555
+ const RenderElement = () => {
65556
+ if (col.type === 'command') {
65557
+ return jsxRuntime.jsx("div", { className: "r-rowcell-div command", children: jsxRuntime.jsx(CommandElement, { commandItems: col.commandItems ?? [], handleCommandClick: handleCommandClick, indexRow: indexRow, rowData: row }) });
65558
+ }
65559
+ else if (col.type === '#') {
65560
+ jsxRuntime.jsx("div", { className: "r-rowcell-div", children: indexRow + 1 });
65561
+ }
65562
+ else if (col.type === 'checkbox') {
65563
+ return (jsxRuntime.jsx("div", { className: "r-rowcell-div cursor-pointer", style: { alignItems: 'center' }, onClick: (e) => {
65564
+ if (selectEnable) {
65565
+ const index = selectedRows?.findIndex((x) => x[fieldKey] === row[fieldKey]);
65566
+ if (index > -1) {
65567
+ if (isMulti) {
65568
+ selectedRows?.splice(index, 1);
65569
+ setSelectedRows([...selectedRows]);
65570
+ }
65571
+ else {
65572
+ setSelectedRows([]);
65573
+ }
65574
+ }
65575
+ else {
65576
+ if (isMulti) {
65577
+ setSelectedRows([...selectedRows, row]);
65578
+ }
65579
+ else {
65580
+ setSelectedRows([row]);
65581
+ }
65582
+ }
65583
+ e.stopPropagation();
65584
+ }
65585
+ }, children: jsxRuntime.jsx(Input$1, { checked: isSelected, type: "checkbox", className: "cursor-pointer", style: { textAlign: col.textAlign ?? 'center' } }) }));
65586
+ }
65587
+ else {
65588
+ let value = row[col.field];
65589
+ if (col.type === 'numeric') {
65590
+ value = formartNumberic(row[col.field], formatSetting?.decimalSeparator ?? ',', formatSetting?.thousandSeparator ?? '.', col.numericSettings?.fraction, true, false) ?? 0;
65591
+ }
65592
+ else if (col.type === 'date') {
65593
+ value = value ? formatDateTime(value, formatSetting?.dateFormat) : '';
65594
+ }
65595
+ else if (col.type === 'datetime') {
65596
+ value = value ? formatDateTime(value, formatSetting?.dateFormat ?? 'DD/MM/yyyy HH:mm') : '';
65597
+ }
65598
+ if (col.template) {
65599
+ value = col.template(row, indexRow) ?? '';
65600
+ }
65601
+ return (jsxRuntime.jsx("div", { className: classNames$1('r-rowcell-div'), children: jsxRuntime.jsxs("div", { className: classNames$1('r-rowcell-content'), style: {
65602
+ textAlign: col.textAlign ? col.textAlign : 'left'
65603
+ }, children: [jsxRuntime.jsx("div", { id: `content-${idTable}-row${indexRow}col-${indexCol}`, className: "r-cell-text", children: (col.type === 'numeric' && Number(row[col.field]) < 0 ? jsxRuntime.jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), col.haveToolTip && jsxRuntime.jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `content-${idTable}-row${indexRow}col-${indexCol}`, children: (col.type === 'numeric' && Number(row[col.field]) < 0 ? jsxRuntime.jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) })] }) }));
65604
+ }
65605
+ };
65606
+ return (col.visible !== false && jsxRuntime.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: {
65607
+ left: col.fixedType === 'left' ? objWidthFixLeft[indexCol] : undefined,
65608
+ right: col.fixedType === 'right' ? objWidthFixRight[indexCol] : undefined
65609
+ }, onClick: (e) => {
65610
+ if (e.target.nodeName === 'DIV' || e.target.nodeName === 'TD') {
65611
+ if (selectEnable) {
65612
+ const index = selectedRows?.findIndex((x) => x[fieldKey] === row[fieldKey]);
65613
+ if (index > -1) {
65614
+ if (isMulti) {
65615
+ selectedRows?.splice(index, 1);
65616
+ setSelectedRows([...selectedRows]);
65617
+ }
65618
+ else {
65619
+ setSelectedRows([]);
65620
+ }
65621
+ }
65622
+ else {
65623
+ if (isMulti) {
65624
+ setSelectedRows([...selectedRows, row]);
65625
+ }
65626
+ else {
65627
+ setSelectedRows([row]);
65628
+ }
65629
+ }
65630
+ }
65631
+ e.stopPropagation();
65632
+ }
65633
+ }, children: RenderElement() }, `col-${indexRow}-${indexCol}`));
65634
+ };
65635
+
65636
+ const RenderColGroup = ({ contentColumns }) => (jsxRuntime.jsx("colgroup", { children: contentColumns.map((col, index) => (jsxRuntime.jsx("col", { style: {
65637
+ width: typeof col.width === 'number' ? `${col.width}px` : col.width || undefined,
65638
+ minWidth: typeof col.minWidth === 'number' ? `${col.minWidth}px` : col.minWidth || undefined,
65639
+ maxWidth: typeof col.maxWidth === 'number' ? `${col.maxWidth}px` : col.maxWidth || undefined
65640
+ } }, index))) }));
65641
+
65642
+ const VirtualTable = ({ idTable, dataSource, rowHeight = 33, height = 400, columns, isMutil, isLoading, selectEnable, formatSetting, commandClick, allowFilter, allowOrder, setColumns, pagingSetting, changeFilter, changeOrder, searchSetting, columnsAggregate, toolbarSetting, optionsFilter }) => {
65643
+ const gridRef = React$5.useRef(null);
65644
+ const [startIndex, setStartIndex] = React$5.useState(0);
65645
+ const [selectedRows, setSelectedRows] = React$5.useState([]);
65646
+ const [orderBy, setOrderBy] = React$5.useState([]);
65647
+ const [filterBy, setFilterBy] = React$5.useState([]);
65648
+ const [searchTerm, setSearchTerm] = React$5.useState('');
65649
+ const fieldKey = columns.find((item) => item.isPrimarykey === true)?.field ?? 'id';
65650
+ //trường liên quan đến virtul loading
65651
+ const visibleRowCount = Math.ceil(height / rowHeight) + 5;
65652
+ const buffer = 10; // số dòng dự phòng phía trên và dưới
65653
+ const adjustedStartIndex = Math.max(startIndex - buffer, 0);
65654
+ const adjustedEndIndex = Math.min(startIndex + visibleRowCount + buffer, dataSource.length);
65655
+ const visibleData = dataSource.slice(adjustedStartIndex, adjustedEndIndex);
65656
+ const { t } = reactI18next.useTranslation();
65657
+ const { levels: headerColumns, flat: contentColumns, flatVisble, objWidthFixLeft, objWidthFixRight, lastObjWidthFixLeft, fisrtObjWidthFixRight } = React$5.useMemo(() => calculateTableStructure(columns), [columns]);
65658
+ const scrollTimeoutRef = React$5.useRef(null);
65659
+ const lastScrollTop = React$5.useRef(0);
65660
+ const handleScroll = (e) => {
65661
+ if (!gridRef.current) {
65662
+ return;
65663
+ }
65664
+ // Nếu không có sự thay đổi về scrollTop => người dùng chỉ scroll ngang => không xử lý
65665
+ if (e.target.scrollTop === lastScrollTop.current) {
65666
+ return;
65667
+ }
65668
+ lastScrollTop.current = e.target.scrollTop;
65669
+ if (scrollTimeoutRef.current !== null) {
65670
+ cancelAnimationFrame(scrollTimeoutRef.current);
65671
+ }
65672
+ scrollTimeoutRef.current = requestAnimationFrame(() => {
65673
+ const scrollTop = gridRef.current.scrollTop;
65674
+ const newStartIndex = Math.floor(scrollTop / rowHeight);
65675
+ if (newStartIndex !== startIndex) {
65676
+ setStartIndex(newStartIndex);
65677
+ }
65678
+ });
65679
+ };
65680
+ const handleCommandClick = (id, rowData, index) => {
65681
+ if (commandClick) {
65682
+ commandClick({ id, rowData, index });
65683
+ }
65684
+ };
65685
+ const handleKeyPress = (e) => {
65686
+ if ((e.code === 'Enter' || e.code === 'NumpadEnter')) {
65687
+ if (searchSetting?.setSearchTerm) {
65688
+ searchSetting?.setSearchTerm(e.target.value);
65689
+ }
65690
+ else {
65691
+ setSearchTerm(e.target.value);
65692
+ }
65693
+ e.stopPropagation();
65694
+ e.preventDefault();
65695
+ }
65696
+ };
65697
+ const searchTemplate = () => {
65698
+ return (jsxRuntime.jsx("div", { className: "me-50 r-search", children: jsxRuntime.jsx(ReactInput, { style: { width: '230px' }, value: searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm, setSearchTerm: searchSetting?.setSearchTerm ? searchSetting?.setSearchTerm : setSearchTerm, placeholder: t('Search'), onKeyPress: handleKeyPress }) }));
65699
+ };
65700
+ const defaultToolbarOption = searchSetting?.searchEnable ? [{ template: searchTemplate, align: 'left' }] : [];
65701
+ let toolbarTopOption = [];
65702
+ if (toolbarSetting?.toolbarOptions) {
65703
+ toolbarTopOption = [...defaultToolbarOption, ...toolbarSetting?.toolbarOptions];
65704
+ }
65705
+ else {
65706
+ toolbarTopOption = [...defaultToolbarOption];
65707
+ }
65708
+ const onChangePage = (args) => {
65709
+ if (pagingSetting?.setCurrentPage) {
65710
+ if (args.currentPage === args.oldPage) {
65711
+ return;
65712
+ }
65713
+ pagingSetting.setCurrentPage(args.currentPage);
65714
+ }
65715
+ };
65716
+ const onChangePageSize = (args) => {
65717
+ if (pagingSetting?.allowPaging) {
65718
+ if (pagingSetting?.pageSize !== args.pageSize) {
65719
+ if (pagingSetting?.setPageSize) {
65720
+ pagingSetting.setPageSize(args.pageSize);
65721
+ }
65722
+ if (pagingSetting?.setCurrentPage) {
65723
+ pagingSetting.setCurrentPage(1);
65724
+ }
65725
+ }
65726
+ }
65727
+ };
65728
+ return (jsxRuntime.jsxs("div", { className: "react-table-edit", children: [jsxRuntime.jsxs("div", { className: 'r-grid', children: [toolbarSetting?.showTopToolbar && jsxRuntime.jsx(RenderToolbarTop, { toolbarTopOption: toolbarTopOption }), jsxRuntime.jsxs("div", { ref: gridRef, className: "r-gridtable", onScroll: handleScroll, style: { height: `${height ? `${height}px` : 'auto'}` }, children: [jsxRuntime.jsxs("table", { style: { width: '100%' }, children: [jsxRuntime.jsx(RenderColGroup, { contentColumns: flatVisble }), jsxRuntime.jsx("thead", { className: 'r-gridheader', children: headerColumns.map((rowColumn, indexParent) => (jsxRuntime.jsx("tr", { className: "r-row", role: "row", children: rowColumn.map((column, indexColumn) => (jsxRuntime.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) => {
65729
+ setFilterBy([...val]);
65730
+ if (changeFilter) {
65731
+ changeFilter(val);
65732
+ }
65733
+ }, changeOrder: (val) => {
65734
+ setOrderBy([...val]);
65735
+ if (changeOrder) {
65736
+ changeOrder(val);
65737
+ }
65738
+ }, container: gridRef, totalCount: dataSource.length }, `header-${indexParent}-${indexColumn}`))) }, indexParent))) }), jsxRuntime.jsxs("tbody", { className: 'r-gridcontent', children: [adjustedStartIndex > 0 && (jsxRuntime.jsx("tr", { style: { height: adjustedStartIndex * rowHeight }, children: jsxRuntime.jsx("td", { style: { padding: 0 }, colSpan: flatVisble.length }) })), visibleData.map((row, index) => {
65739
+ const indexRow = index + startIndex;
65740
+ const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
65741
+ return (jsxRuntime.jsx("tr", { className: classNames$1('r-row'), children: contentColumns.map((column, indexCol) => (jsxRuntime.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}`));
65742
+ }), dataSource.length > adjustedEndIndex && (jsxRuntime.jsx("tr", { style: { height: (dataSource.length - adjustedEndIndex) * rowHeight }, children: jsxRuntime.jsx("td", { style: { padding: 0 }, colSpan: flatVisble.length }) }))] }), dataSource.length > 0 && jsxRuntime.jsx("tfoot", { className: "r-gridfoot", children: (columnsAggregate?.length ?? 0) > 0 ? jsxRuntime.jsx("tr", { className: 'r-row', children: contentColumns.map((col, indexCol) => {
65743
+ const item = columnsAggregate?.find((x) => x.field === col.field);
65744
+ let sumValue = item?.value;
65745
+ if (!item && col.haveSum === true && col.type === "numeric") {
65746
+ sumValue = dataSource.reduce(function (accumulator, currentValue) { return (Number(accumulator ?? 0) + Number(currentValue[col.field] ?? 0)); }, 0);
65747
+ }
65748
+ return col.visible !== false && jsxRuntime.jsx("td", { className: classNames$1(`p-0 px-50 r-footer fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }), style: {
65749
+ left: col.fixedType === 'left' ? objWidthFixLeft[indexCol] : undefined,
65750
+ right: col.fixedType === 'right' ? objWidthFixRight[indexCol] : undefined,
65751
+ textAlign: col.textAlign ? col.textAlign : 'left'
65752
+ }, children: jsxRuntime.jsxs("div", { className: "r-footer-div", children: [(item || (col.haveSum === true && col.type === "numeric")) && col.type === "numeric" && (Number(sumValue) >= 0) && jsxRuntime.jsx(jsxRuntime.Fragment, { 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) && 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}`);
65753
+ }) }) : jsxRuntime.jsx(jsxRuntime.Fragment, {}) })] }), (((dataSource.length ?? 0) === 0) && !isLoading) && jsxRuntime.jsxs("div", { className: "r-no-data", children: [jsxRuntime.jsx("svg", { width: "64", height: "41", viewBox: "0 0 64 41", xmlns: "http://www.w3.org/2000/svg", children: jsxRuntime.jsxs("g", { transform: "translate(0 1)", fill: "none", fillRule: "evenodd", children: [jsxRuntime.jsx("ellipse", { fill: "#f5f5f5", cx: "32", cy: "33", rx: "32", ry: "7" }), jsxRuntime.jsxs("g", { fillRule: "nonzero", stroke: "#d9d9d9", children: [jsxRuntime.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" }), jsxRuntime.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 && jsxRuntime.jsx("div", { className: "r-loading-overlay", children: jsxRuntime.jsxs("div", { className: "r-loading", children: [jsxRuntime.jsx(Spinner$1, { className: "me-1" }), t('Loading...')] }) })] })] }), pagingSetting?.allowPaging ? jsxRuntime.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 }) : jsxRuntime.jsx(jsxRuntime.Fragment, {})] }));
65754
+ };
65755
+
65409
65756
  exports.ExportExcelComponent = ExportExcelComponent;
65410
65757
  exports.FindNodeByPath = FindNodeByPath;
65411
65758
  exports.ImportExcelComponent = ImportExcelComponent;
@@ -65413,6 +65760,7 @@ exports.InputStyleComponent = InputStyleComponent;
65413
65760
  exports.SelectTable = SelectTable;
65414
65761
  exports.SelectTableTree = SelectTableTree;
65415
65762
  exports.TabsMenuComponent = TabsMenuComponent;
65763
+ exports.VirtualTable = VirtualTable;
65416
65764
  exports.Wizard = Wizard;
65417
65765
  exports.calculateTableStructure = calculateTableStructure;
65418
65766
  exports.checkDecimalSeparator = checkDecimalSeparator;