react-table-edit 1.4.22 → 1.4.24

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/index.js CHANGED
@@ -19358,6 +19358,9 @@ const calculateTableStructure = (columns) => {
19358
19358
  const flatVisble = flat.filter((e) => e.visible !== false);
19359
19359
  const lastObjWidthFixLeft = Math.max(...Object.keys(objWidthFixLeft).map(Number), 0);
19360
19360
  const fisrtObjWidthFixRight = Math.min(...Object.keys(objWidthFixRight).map(Number), flat.length);
19361
+ const editableColumns = flat.filter(item => item.editEnable && item.visible !== false && !item.disabledCondition);
19362
+ const firstEdit = editableColumns[0];
19363
+ const lastEdit = editableColumns[editableColumns.length - 1];
19361
19364
  return {
19362
19365
  levels,
19363
19366
  flat,
@@ -19365,7 +19368,9 @@ const calculateTableStructure = (columns) => {
19365
19368
  objWidthFixLeft,
19366
19369
  objWidthFixRight,
19367
19370
  lastObjWidthFixLeft,
19368
- fisrtObjWidthFixRight
19371
+ fisrtObjWidthFixRight,
19372
+ firstEdit,
19373
+ lastEdit
19369
19374
  };
19370
19375
  };
19371
19376
 
@@ -39911,13 +39916,18 @@ if (process.env.NODE_ENV === 'production') {
39911
39916
  var InputMask = reactInputMask.exports;
39912
39917
 
39913
39918
  const DateInput = (props) => {
39914
- const { id, onKeyDown, dateFormat, className, onChange, value } = props;
39919
+ const { id, onKeyDown, dateFormat, className, onChange, value, onPaste } = props;
39915
39920
  const [open, setOpen] = React$5.useState(false);
39916
39921
  return (jsxRuntime.jsx(DatePicker, { id: id, open: open, className: className, selected: value, onChange: (date) => {
39917
39922
  if (onChange) {
39918
39923
  onChange(date);
39919
39924
  }
39920
- }, dateFormat: dateFormat, locale: "vi", showMonthDropdown: true, showYearDropdown: true, dropdownMode: "select", isClearable: true, onCalendarClose: () => setOpen(false), onCalendarOpen: () => setOpen(true), customInput: jsxRuntime.jsx(InputMask, { mask: "99/99/9999", placeholder: dateFormat }), onKeyDown: (e) => {
39925
+ }, dateFormat: dateFormat, locale: "vi", showMonthDropdown: true, showYearDropdown: true, dropdownMode: "select", isClearable: true, onCalendarClose: () => setOpen(false), onCalendarOpen: () => setOpen(true), customInput: jsxRuntime.jsx(InputMask, { mask: "99/99/9999", placeholder: dateFormat, onPaste: (e) => {
39926
+ if (onPaste) {
39927
+ onPaste(e);
39928
+ setOpen(false);
39929
+ }
39930
+ } }), onKeyDown: (e) => {
39921
39931
  if (e.code === 'Space') {
39922
39932
  setOpen(!open);
39923
39933
  setTimeout(() => {
@@ -39927,12 +39937,10 @@ const DateInput = (props) => {
39927
39937
  }
39928
39938
  }, 100);
39929
39939
  }
39930
- else {
39931
- if (onKeyDown && !open) {
39932
- const rs = onKeyDown(e);
39933
- if (rs) {
39934
- setOpen(false);
39935
- }
39940
+ else if (onKeyDown && (!open || ((e.ctrlKey || e.metaKey || e.altKey) && e.shiftKey))) {
39941
+ const rs = onKeyDown(e);
39942
+ if (rs) {
39943
+ setOpen(false);
39936
39944
  }
39937
39945
  }
39938
39946
  } }));
@@ -41808,31 +41816,51 @@ var css_248z$1 = ".react-resizable {\n position: relative;\n}\n.react-resizable
41808
41816
  styleInject(css_248z$1);
41809
41817
 
41810
41818
  const HeaderTableCol$1 = (props) => {
41811
- const { selectEnable, dataSource, setSelectedRows, col, indexCol, indexParent, objWidthFixLeft, objWidthFixRight, totalCount, selectedRows, column, setColumn, fisrtObjWidthFixRight, lastObjWidthFixLeft, isMulti } = props;
41819
+ 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;
41812
41820
  const { t } = reactI18next.useTranslation();
41821
+ const headerRef = React$5.useRef(null);
41822
+ const order = orderBy.find((item) => item.key === col.field);
41823
+ const [openFilter, setOpenFilter] = React$5.useState(false);
41824
+ const filter = filterBy.find((item) => item.key === col.field);
41813
41825
  const handleResize = (e, { size }) => {
41814
41826
  // Update the column width here
41815
41827
  // You might need to update the state or call a callback to update the width
41816
41828
  if (size.width > 50) {
41817
- const newColumns = [...column];
41829
+ const newColumns = [...columns];
41818
41830
  newColumns[indexCol].width = size.width;
41819
- if ((column[indexCol]?.maxWidth ?? 0) < size.width) {
41831
+ if ((columns[indexCol]?.maxWidth ?? 0) < size.width) {
41820
41832
  newColumns[indexCol].maxWidth = size.width;
41821
41833
  }
41822
- if ((column[indexCol]?.minWidth ?? 0) > size.width) {
41834
+ if ((columns[indexCol]?.minWidth ?? 0) > size.width) {
41823
41835
  newColumns[indexCol].minWidth = size.width;
41824
41836
  }
41825
- setColumn(newColumns);
41837
+ if (setColumns) {
41838
+ setColumns(newColumns);
41839
+ }
41826
41840
  }
41827
41841
  };
41828
- 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 : undefined, 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: {
41842
+ const checkOverflow = () => {
41843
+ return headerRef.current && headerRef.current.scrollHeight > headerRef.current.clientHeight;
41844
+ };
41845
+ 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: {
41829
41846
  top: `${indexParent * 42}px`,
41830
- left: col.fixedType === 'left' ? objWidthFixLeft[col.index ?? 0] : undefined,
41831
- right: col.fixedType === 'right' ? objWidthFixRight[col.index ?? 0] : undefined,
41832
- width: col.width ? typeof col.width === 'number' ? col.width : col.width?.includes('px') || col.width?.includes('%') ? col.width : `${col.width}px` : 'auto',
41833
- minWidth: col.fixedType ? col.width : col.minWidth ? typeof col.minWidth === 'number' ? col.minWidth : col.minWidth?.includes('px') || col.minWidth?.includes('%') ? col.minWidth : `${col.minWidth}px` : 'auto',
41834
- maxWidth: col.fixedType ? col.width : col.maxWidth ? typeof col.maxWidth === 'number' ? col.maxWidth : col.maxWidth?.includes('px') || col.maxWidth?.includes('%') ? col.maxWidth : `${col.maxWidth}px` : 'auto'
41835
- }, children: jsxRuntime.jsxs("div", { style: { justifyContent: col.textAlign ?? 'left' }, className: classNames$1('r-headercell-div'), 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) => {
41847
+ left: col.fixedType === 'left' ? objWidthFixLeft[indexCol ?? 0] : undefined,
41848
+ right: col.fixedType === 'right' ? objWidthFixRight[indexCol ?? 0] : undefined
41849
+ }, children: jsxRuntime.jsxs("div", { style: { justifyContent: 'space-between' }, onClick: () => {
41850
+ if (order) {
41851
+ if (order.direction === 'asc') {
41852
+ order.direction = 'desc';
41853
+ changeOrder(orderBy);
41854
+ }
41855
+ else {
41856
+ changeOrder(orderBy.filter((x) => x.key !== col.field));
41857
+ }
41858
+ }
41859
+ else {
41860
+ orderBy.push({ direction: 'asc', key: col.field });
41861
+ changeOrder(orderBy);
41862
+ }
41863
+ }, 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) => {
41836
41864
  if (selectEnable) {
41837
41865
  if (e.target.checked) {
41838
41866
  setSelectedRows(dataSource.map((item) => { return item; }));
@@ -41841,7 +41869,89 @@ const HeaderTableCol$1 = (props) => {
41841
41869
  setSelectedRows([]);
41842
41870
  }
41843
41871
  }
41844
- } })), col.field !== 'checkbox' && jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("span", { className: 'header-content', children: t(col.headerText ?? '') }) })] }) }) })) }, `header-${indexCol}`));
41872
+ } })), 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 && jsxRuntime.jsxs(Dropdown$1, { isOpen: openFilter, toggle: (e) => {
41873
+ setOpenFilter(!openFilter);
41874
+ e.stopPropagation();
41875
+ }, onClick: (e) => {
41876
+ e.stopPropagation();
41877
+ }, 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: {
41878
+ borderRadius: 8,
41879
+ zIndex: 1056
41880
+ }, 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}`));
41881
+ };
41882
+ const RenderFilterElement$1 = ({ filter, optionsFilter, formatSetting, filterBy, setOpenFilter, changeFilter, column }) => {
41883
+ const { t } = reactI18next.useTranslation();
41884
+ const [operator, setOperator] = React$5.useState(filter?.ope ?? ((!column.filterType && column.editType === 'numeric') || column.filterType === 'select' ? 'equal' : 'contains'));
41885
+ const [valueFilter, setValueFilter] = React$5.useState(filter?.value ?? '');
41886
+ const RenderStringFilter = () => {
41887
+ const options = [
41888
+ { label: 'Bắt đầu bởi', value: 'startswith' },
41889
+ { label: 'Kết thúc bởi', value: 'endswith' },
41890
+ { label: 'Chứa', value: 'contains' },
41891
+ { label: 'Bằng', value: 'equal' },
41892
+ { label: 'Không bằng', value: 'notequal' }
41893
+ ];
41894
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(SelectTable, { value: options.find((x) => x.value === (operator)), options: options, onChange: (val) => {
41895
+ setOperator(val.value);
41896
+ }, placeholder: 'Select' }), jsxRuntime.jsx(Input$1, { className: 'my-1', value: valueFilter, onChange: (val) => {
41897
+ setValueFilter(val.target.value);
41898
+ } })] }));
41899
+ };
41900
+ const RenderNumberFilter = () => {
41901
+ const options = [
41902
+ { label: 'Lớn hơn', value: 'greaterthan' },
41903
+ { label: 'Lớn hơn hoặc bằng', value: 'greaterthanorequal' },
41904
+ { label: 'Bằng', value: 'equal' },
41905
+ { label: 'Bé hơn', value: 'lessthan' },
41906
+ { label: 'Bé hơn hoặc bằng', value: 'lessthanorequal' }
41907
+ ];
41908
+ const numericFormatProps = {
41909
+ value: !isNullOrUndefined$1(valueFilter) ? valueFilter.toString() : '',
41910
+ thousandSeparator: checkThousandSeparator(formatSetting?.thousandSeparator, formatSetting?.decimalSeparator),
41911
+ decimalSeparator: checkDecimalSeparator(formatSetting?.thousandSeparator, formatSetting?.decimalSeparator),
41912
+ allowNegative: column.numericSettings?.allowNegative ?? false,
41913
+ decimalScale: column.numericSettings?.fraction ?? 0
41914
+ };
41915
+ let floatValue = parseFloat(valueFilter ?? '0');
41916
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(SelectTable, { value: options.find((x) => x.value === (operator)), options: options, onChange: (val) => {
41917
+ setOperator(val.value);
41918
+ }, 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) => {
41919
+ floatValue = values?.floatValue;
41920
+ }, onFocus: (e) => {
41921
+ e.target.setSelectionRange(0, e.target.innerText.length - 1);
41922
+ }, onBlur: () => {
41923
+ if (floatValue !== valueFilter) {
41924
+ setValueFilter(!isNaN(floatValue) ? floatValue : 0);
41925
+ }
41926
+ } })] }));
41927
+ };
41928
+ const RenderSelectFilter = () => {
41929
+ 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) => {
41930
+ setValueFilter(val?.value);
41931
+ }, placeholder: t('Select') }) }));
41932
+ };
41933
+ const handleSave = () => {
41934
+ if (filter) {
41935
+ filter.ope = operator;
41936
+ filter.value = valueFilter ?? '';
41937
+ }
41938
+ else {
41939
+ filterBy.push({ key: column.field, ope: operator, value: valueFilter ?? '' });
41940
+ }
41941
+ changeFilter([...filterBy]);
41942
+ setOpenFilter(false);
41943
+ };
41944
+ return (jsxRuntime.jsxs("div", { className: 'r-filter-popup', onKeyDown: (e) => {
41945
+ if (e.code === 'Enter' || e.code === 'NumpadEnter') {
41946
+ handleSave();
41947
+ e.stopPropagation();
41948
+ }
41949
+ }, 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', outline: true, style: { borderRadius: 3 }, onClick: () => {
41950
+ if (filterBy) {
41951
+ changeFilter(filterBy.filter((x) => x.key !== column.field));
41952
+ }
41953
+ setOpenFilter(false);
41954
+ }, children: t('Clear') })] })] }));
41845
41955
  };
41846
41956
 
41847
41957
  const defaultMaxHeight = 250;
@@ -42613,9 +42723,15 @@ const EditFormInline = React$5.forwardRef((props, ref) => {
42613
42723
  }) })] }));
42614
42724
  });
42615
42725
 
42726
+ const RenderColGroup = ({ contentColumns }) => (jsxRuntime.jsx("colgroup", { children: contentColumns.map((col, index) => (jsxRuntime.jsx("col", { style: {
42727
+ width: typeof col.width === 'number' ? `${col.width}px` : col.width || undefined,
42728
+ minWidth: typeof col.minWidth === 'number' ? `${col.minWidth}px` : col.minWidth || undefined,
42729
+ maxWidth: typeof col.maxWidth === 'number' ? `${col.maxWidth}px` : col.maxWidth || undefined
42730
+ } }, index))) }));
42731
+
42616
42732
  const TableEdit = React$5.forwardRef((props, ref) => {
42617
42733
  const { t } = reactI18next.useTranslation();
42618
- 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;
42734
+ 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;
42619
42735
  React$5.useImperativeHandle(ref, () => {
42620
42736
  return {
42621
42737
  refeshFocusRow: handleRefeshRow
@@ -42624,17 +42740,11 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42624
42740
  const [refreshRow, setRefreshRow] = React$5.useState(false);
42625
42741
  const [indexFocus, setIndexFocus] = React$5.useState(-1);
42626
42742
  const [selectedRows, setSelectedRows] = React$5.useState([]);
42627
- const [headerColumns, setHeaderColumns] = React$5.useState([[]]);
42628
42743
  const [contentColumns, setContentColumns] = React$5.useState([]);
42629
- const [levelCol, setLevelCol] = React$5.useState(0);
42630
- const [columnFistEdit, setColumnFistEdit] = React$5.useState(0);
42631
- const [columnLastEdit, setColumnlastEdit] = React$5.useState(0);
42632
- const [objWidthFixRight, setObjWidthFixRight] = React$5.useState({});
42633
- const [objWidthFixLeft, setObjWidthFixLeft] = React$5.useState({});
42634
- const [lastObjWidthFixLeft, setLastObjWidthFixLeft] = React$5.useState(0);
42635
- const [fisrtObjWidthFixRight, setFisrtObjWidthFixRight] = React$5.useState(0);
42636
42744
  const [openPopupSetupColumn, setOpenPopupSetupColumn] = React$5.useState(false);
42637
42745
  const [searchTerm, setSearchTerm] = React$5.useState('');
42746
+ const [orderBy, setOrderBy] = React$5.useState([]);
42747
+ const [filterBy, setFilterBy] = React$5.useState([]);
42638
42748
  const tableElement = React$5.useRef(null);
42639
42749
  const gridRef = React$5.useRef(null);
42640
42750
  const totalCount = dataSource.length;
@@ -42647,95 +42757,11 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42647
42757
  pagingSetting.setCurrentPage(1);
42648
42758
  }
42649
42759
  }, [dataSource]);
42650
- React$5.useEffect(() => {
42651
- let indexFirst = -1;
42652
- let indexlast = -1;
42653
- let letfWidthFix = 0;
42654
- let rightWidthFix = 0;
42655
- contentColumns.forEach((item, index) => {
42656
- if (levelCol === 1) {
42657
- headerColumns[0][index].width = item.width;
42658
- headerColumns[0][index].visible = item.visible;
42659
- headerColumns[0][index].fixedType = item.fixedType;
42660
- }
42661
- if (item.fixedType === 'left' && item.visible !== false) {
42662
- setLastObjWidthFixLeft(index);
42663
- objWidthFixLeft[index] = letfWidthFix;
42664
- letfWidthFix += Number(item.width ?? 40);
42665
- }
42666
- const lasColumn = contentColumns[contentColumns.length - 1 - index];
42667
- if (lasColumn.fixedType === 'right' && lasColumn.visible !== false) {
42668
- setFisrtObjWidthFixRight(contentColumns.length - 1 - index);
42669
- objWidthFixRight[contentColumns.length - 1 - index] = rightWidthFix;
42670
- rightWidthFix += Number(lasColumn.width ?? 40);
42671
- }
42672
- if (item.editEnable && (item.visible !== false) && (!item.disabledCondition)) {
42673
- if (indexFirst === -1) {
42674
- indexFirst = index;
42675
- }
42676
- indexlast = index;
42677
- }
42678
- });
42679
- if (levelCol === 1) {
42680
- setHeaderColumns([...headerColumns]);
42681
- }
42682
- setObjWidthFixLeft(objWidthFixLeft);
42683
- setObjWidthFixRight(objWidthFixRight);
42684
- setColumnFistEdit(indexFirst + 1);
42685
- setColumnlastEdit(indexlast + 1);
42686
- }, [contentColumns]);
42687
- React$5.useEffect(() => {
42688
- const arrHeaderColumns = [];
42689
- const arrContentColumns = [];
42690
- let headerLevelRow = 0;
42691
- if (levelCol) {
42692
- headerLevelRow = levelCol;
42693
- }
42694
- else {
42695
- headerLevelRow = stretchColumn(columns, 0);
42696
- setLevelCol(headerLevelRow);
42697
- }
42698
- for (let i = 0; i < headerLevelRow; i++) {
42699
- arrHeaderColumns.push([]);
42700
- }
42701
- getNestedChildren(columns, arrHeaderColumns, arrContentColumns, 0, headerLevelRow);
42702
- setHeaderColumns(arrHeaderColumns);
42703
- setContentColumns(arrContentColumns);
42760
+ const { levels: headerColumns, flatVisble, objWidthFixLeft, objWidthFixRight, lastObjWidthFixLeft, fisrtObjWidthFixRight, firstEdit: columnFirstEdit, lastEdit: columnLastEdit } = React$5.useMemo(() => {
42761
+ const obj = calculateTableStructure(columns);
42762
+ setContentColumns(obj.flat);
42763
+ return obj;
42704
42764
  }, [columns]);
42705
- const getNestedChildren = (array, arrHeaderColumns, arrContentColumns, level, maxLevelRow) => {
42706
- array.forEach((item) => {
42707
- const ele = { ...item, visible: item.visible, rowspan: 1, index: 0 };
42708
- if (item.columns && item.columns?.length > 0) {
42709
- const countLevel = getNestedChildren(item.columns, arrHeaderColumns, arrContentColumns, level + 1, maxLevelRow);
42710
- arrHeaderColumns[(maxLevelRow - 1) - countLevel].push(ele);
42711
- }
42712
- else {
42713
- ele.rowspan = maxLevelRow - level;
42714
- ele.index = arrContentColumns.length;
42715
- if (maxLevelRow === 1) {
42716
- ele.visible = (item.invisibleDisable ? item.visible : (contentColumns[arrContentColumns.length]?.visible ?? item.visible));
42717
- ele.width = (contentColumns[arrContentColumns.length]?.width ?? item.width);
42718
- ele.maxWidth = (contentColumns[arrContentColumns.length]?.maxWidth ?? item.maxWidth);
42719
- ele.minWidth = (contentColumns[arrContentColumns.length]?.minWidth ?? item.minWidth);
42720
- }
42721
- arrHeaderColumns[level].push(ele);
42722
- arrContentColumns.push(ele);
42723
- }
42724
- });
42725
- return level;
42726
- };
42727
- const stretchColumn = (subColumns, headerLevelRow) => {
42728
- let count = headerLevelRow + 1;
42729
- subColumns.map((item) => {
42730
- if (item.columns && item.columns.length > 0) {
42731
- const newCount = stretchColumn(item.columns, headerLevelRow + 1);
42732
- if (newCount > count) {
42733
- count = newCount;
42734
- }
42735
- }
42736
- });
42737
- return count;
42738
- };
42739
42765
  const handleRefeshRow = () => {
42740
42766
  setRefreshRow(true);
42741
42767
  setTimeout(() => {
@@ -42791,6 +42817,11 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42791
42817
  if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) {
42792
42818
  return true;
42793
42819
  }
42820
+ }, onPaste: (e) => {
42821
+ if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable) {
42822
+ pasteDataFromExcel(indexRow, indexCol, e);
42823
+ e.preventDefault();
42824
+ }
42794
42825
  } }));
42795
42826
  case 'datetime':
42796
42827
  return (jsxRuntime.jsx(DateInput, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, className: classNames$1('form-control border-0 rounded-0 input-numeric', { 'is-invalid': col.validate && col.validate(row[col.field], row) }), value: row[col.field], onChange: (date) => {
@@ -42801,6 +42832,11 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42801
42832
  handleDataChange(row, col, indexRow);
42802
42833
  }, dateFormat: "dd/MM/yyyy HH:mm", onKeyDown: (e) => {
42803
42834
  checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
42835
+ }, onPaste: (e) => {
42836
+ if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable) {
42837
+ pasteDataFromExcel(indexRow, indexCol, e);
42838
+ e.preventDefault();
42839
+ }
42804
42840
  } }));
42805
42841
  case 'select':
42806
42842
  let valueSelect;
@@ -43055,7 +43091,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
43055
43091
  }
43056
43092
  if (tableElement) {
43057
43093
  setIndexFocus(totalCount);
43058
- focusNewElement(columnFistEdit, totalCount + 1, true);
43094
+ focusNewElement(columnFirstEdit, totalCount + 1, true);
43059
43095
  }
43060
43096
  };
43061
43097
  const checkKeyDown = (e, row, col, indexRow, indexCol) => {
@@ -43183,7 +43219,28 @@ const TableEdit = React$5.forwardRef((props, ref) => {
43183
43219
  }
43184
43220
  else {
43185
43221
  if (column.editType === 'date') {
43186
- const date = new Date(stringData);
43222
+ const [day, month, year] = stringData.split('/');
43223
+ const date = new Date(`${year}-${month}-${day}`);
43224
+ if (!isNaN(date.getTime())) {
43225
+ if (column.onPaste) {
43226
+ dataRow[column.field] = column.onPaste(dataRow, date);
43227
+ }
43228
+ else {
43229
+ dataRow[column.field] = date;
43230
+ }
43231
+ if (column.callback) {
43232
+ column.callback(date, currenRowIndex + indexRow, dataRow);
43233
+ }
43234
+ }
43235
+ else {
43236
+ notificationError(t('PasteExcelIncorrectFormat', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
43237
+ }
43238
+ }
43239
+ else if (column.editType === 'datetime') {
43240
+ const [datePart, timePart] = stringData.split(' ');
43241
+ const [day, month, year] = datePart.split('/');
43242
+ const [hour, minute] = timePart.split(':');
43243
+ const date = new Date(year, month - 1, day, hour, minute);
43187
43244
  if (!isNaN(date.getTime())) {
43188
43245
  if (column.onPaste) {
43189
43246
  dataRow[column.field] = column.onPaste(dataRow, date);
@@ -43270,14 +43327,6 @@ const TableEdit = React$5.forwardRef((props, ref) => {
43270
43327
  };
43271
43328
  const changeDataSource = (data, numberOfRows) => {
43272
43329
  if (!editDisable && setDataSource) {
43273
- if ((searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm)) {
43274
- if (searchSetting?.setSearchTerm) {
43275
- searchSetting?.setSearchTerm('');
43276
- }
43277
- else {
43278
- setSearchTerm('');
43279
- }
43280
- }
43281
43330
  if (numberOfRows && !addDisable) {
43282
43331
  for (let index = 0; index < numberOfRows; index++) {
43283
43332
  data.push(defaultValue ? { ...defaultValue, [fieldKey]: disableAutoKey ? undefined : generateUUID() } : {});
@@ -43478,22 +43527,52 @@ const TableEdit = React$5.forwardRef((props, ref) => {
43478
43527
  textAlign: col.textAlign ? col.textAlign : 'left'
43479
43528
  }, 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}`));
43480
43529
  };
43481
- const checkSearch = (keyword, data, fieldKey) => {
43482
- if (!keyword || fieldKey.length === 0) {
43483
- return true;
43484
- }
43485
- for (let index = 0; index < fieldKey.length; index++) {
43486
- const key = fieldKey[index].trim();
43487
- if (data[key] && data[key].toString().trim().toLowerCase().includes(keyword.trim().toLowerCase())) {
43488
- return true;
43530
+ /**
43531
+ * Kiểm tra row thỏa mãn tất cả filter và chứa từ khóa tìm kiếm hay không
43532
+ */
43533
+ function checkRowMatch(row, filters, keyword, searchKeys) {
43534
+ if ((!filters || filters.length === 0) && (!keyword || !searchClient))
43535
+ return true; // Không có filter thì mặc định là match
43536
+ const isFilterMatch = filters.every(filter => {
43537
+ const { key, value, ope } = filter;
43538
+ const rowValue = row[key];
43539
+ if (rowValue === undefined || rowValue === null || value === undefined || value === null)
43540
+ return false;
43541
+ const valStr = String(rowValue).toLowerCase();
43542
+ const filterStr = String(value).toLowerCase();
43543
+ switch (ope) {
43544
+ case 'startswith':
43545
+ return valStr.startsWith(filterStr);
43546
+ case 'endswith':
43547
+ return valStr.endsWith(filterStr);
43548
+ case 'contains':
43549
+ return valStr.includes(filterStr);
43550
+ case 'equal':
43551
+ return rowValue == value;
43552
+ case 'notequal':
43553
+ return rowValue != value;
43554
+ case 'greaterthan':
43555
+ return rowValue > value;
43556
+ case 'greaterthanorequal':
43557
+ return rowValue >= value;
43558
+ case 'lessthan':
43559
+ return rowValue < value;
43560
+ case 'lessthanorequal':
43561
+ return rowValue <= value;
43562
+ default:
43563
+ return false;
43489
43564
  }
43490
- }
43491
- return false;
43492
- };
43565
+ });
43566
+ const isSearchMatch = !keyword || searchKeys.some(key => {
43567
+ const val = row[key];
43568
+ return val?.toString().toLowerCase().includes(keyword.trim().toLowerCase());
43569
+ });
43570
+ return isFilterMatch && isSearchMatch;
43571
+ }
43493
43572
  const renderData = () => {
43494
43573
  return (dataSource.map((row, indexRow) => {
43495
43574
  const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
43496
- const flagSearch = !searchClient || checkSearch(searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm, row, searchSetting?.keyField ?? []);
43575
+ const flagSearch = checkRowMatch(row, filterBy, searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm, searchSetting?.keyField ?? []);
43497
43576
  if (flagSearch) {
43498
43577
  const flagDisplay = !pagingClient || ((indexRow + 1) > ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0) - 1)) && (indexRow + 1) <= ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0))));
43499
43578
  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}`) }));
@@ -43505,14 +43584,18 @@ const TableEdit = React$5.forwardRef((props, ref) => {
43505
43584
  pagingSetting?.setCurrentPage(1);
43506
43585
  }
43507
43586
  }, [searchTerm, searchSetting?.searchTerm]);
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) => {
43587
+ 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) => {
43509
43588
  return (jsxRuntime.jsx("tr", { className: "r-row", role: "row", children: element?.map((col, 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}`));
43589
+ return (jsxRuntime.jsx(HeaderTableCol$1, { col: col, idTable: idTable ?? '', dataSource: dataSource, indexCol: index, indexParent: indexParent, isMulti: isMulti ?? false, objWidthFixLeft: objWidthFixLeft, objWidthFixRight: objWidthFixRight, selectEnable: selectEnable ?? false, selectedRows: selectedRows, setSelectedRows: setSelectedRows, container: tableElement, filterBy: filterBy, orderBy: orderBy, optionsFilter: optionsFilter, allowFilter: allowFilter, allowOrder: allowOrder, formatSetting: formatSetting, changeFilter: (val) => {
43590
+ setFilterBy([...val]);
43591
+ }, changeOrder: (val) => {
43592
+ setOrderBy([...val]);
43593
+ }, columns: contentColumns, setColumns: setContentColumns, fisrtObjWidthFixRight: fisrtObjWidthFixRight, lastObjWidthFixLeft: lastObjWidthFixLeft, totalCount: totalCount }, `header-${indexParent}-${index}`));
43511
43594
  }) }, `header-${-indexParent}`));
43512
43595
  }) }), 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
43596
  return (renderFooterCol(col, index));
43514
43597
  }) }) : jsxRuntime.jsx(jsxRuntime.Fragment, {}) })] }) }), toolbarSetting?.showBottomToolbar && jsxRuntime.jsx(ToolbarBottom, { handleAdd: (numberOfRows) => {
43515
- handleAdd(dataSource, tableElement.current, columnFistEdit, changeDataSource, pagingSetting, setIndexFocus, focusNewElement, numberOfRows);
43598
+ handleAdd(dataSource, tableElement.current, columnFirstEdit, changeDataSource, pagingSetting, setIndexFocus, focusNewElement, numberOfRows);
43516
43599
  }, handleDuplicate: () => {
43517
43600
  handleDuplicate(dataSource, indexFocus, fieldKey, defaultValue, fieldUniKey, changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate);
43518
43601
  }, handleInsertAfter: () => {
@@ -65628,12 +65711,6 @@ const RenderContentCol = (props) => {
65628
65711
  }, children: RenderElement() }, `col-${indexRow}-${indexCol}`));
65629
65712
  };
65630
65713
 
65631
- const RenderColGroup = ({ contentColumns }) => (jsxRuntime.jsx("colgroup", { children: contentColumns.map((col, index) => (jsxRuntime.jsx("col", { style: {
65632
- width: typeof col.width === 'number' ? `${col.width}px` : col.width || undefined,
65633
- minWidth: typeof col.minWidth === 'number' ? `${col.minWidth}px` : col.minWidth || undefined,
65634
- maxWidth: typeof col.maxWidth === 'number' ? `${col.maxWidth}px` : col.maxWidth || undefined
65635
- } }, index))) }));
65636
-
65637
65714
  const VirtualTable = ({ idTable, dataSource, rowHeight = 33, height = 400, columns, isMutil, isLoading, selectEnable, formatSetting, commandClick, allowFilter, allowOrder, setColumns, pagingSetting, changeFilter, changeOrder, searchSetting, columnsAggregate, toolbarSetting, optionsFilter }) => {
65638
65715
  const gridRef = React$5.useRef(null);
65639
65716
  const [startIndex, setStartIndex] = React$5.useState(0);