react-table-edit 1.3.6 → 1.3.8

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
@@ -16255,12 +16255,12 @@ const keydownHandler = (innerParams, event, dismissWith) => {
16255
16255
 
16256
16256
  // ENTER
16257
16257
  if (event.key === 'Enter') {
16258
- handleEnter(event, innerParams);
16258
+ handleEnter$1(event, innerParams);
16259
16259
  }
16260
16260
 
16261
16261
  // TAB
16262
16262
  else if (event.key === 'Tab') {
16263
- handleTab(event);
16263
+ handleTab$1(event);
16264
16264
  }
16265
16265
 
16266
16266
  // ARROWS - switch focus between buttons
@@ -16278,7 +16278,7 @@ const keydownHandler = (innerParams, event, dismissWith) => {
16278
16278
  * @param {KeyboardEvent} event
16279
16279
  * @param {SweetAlertOptions} innerParams
16280
16280
  */
16281
- const handleEnter = (event, innerParams) => {
16281
+ const handleEnter$1 = (event, innerParams) => {
16282
16282
  // https://github.com/sweetalert2/sweetalert2/issues/2386
16283
16283
  if (!callIfFunction(innerParams.allowEnterKey)) {
16284
16284
  return;
@@ -16296,7 +16296,7 @@ const handleEnter = (event, innerParams) => {
16296
16296
  /**
16297
16297
  * @param {KeyboardEvent} event
16298
16298
  */
16299
- const handleTab = event => {
16299
+ const handleTab$1 = event => {
16300
16300
  const targetElement = event.target;
16301
16301
  const focusableElements = getFocusableElements();
16302
16302
  let btnIndex = -1;
@@ -19191,7 +19191,7 @@ const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
19191
19191
  }
19192
19192
  };
19193
19193
  const isNullOrUndefined$1 = (d) => {
19194
- if (d === null || d === undefined) {
19194
+ if (d === null || d === undefined || d === '') {
19195
19195
  return true;
19196
19196
  }
19197
19197
  return false;
@@ -19282,6 +19282,21 @@ const formatDateTime = (data, format = 'dd/MM/yyyy') => {
19282
19282
  };
19283
19283
  return format.replace(/dd|MM|yyyy|HH|mm/g, (match) => map[match]);
19284
19284
  };
19285
+ // Hàm tìm vị trí theo chuỗi index
19286
+ const FindNodeByPath = (tree, path) => {
19287
+ const levels = path.split('-').map(num => parseInt(num, 10));
19288
+ let current = tree;
19289
+ let node = null;
19290
+ for (let index = 0; index < levels.length - 1; index++) {
19291
+ const level = levels[index];
19292
+ if (!current[level] || !current[level].children) {
19293
+ return null;
19294
+ }
19295
+ node = current[level];
19296
+ current = current[level].children ?? [];
19297
+ }
19298
+ return { parent: current, lastIndex: levels.at(-1), firstIndex: levels.length === 1 ? levels[0] : -1, node };
19299
+ };
19285
19300
 
19286
19301
  var isCheckBoxInput = (element) => element.type === 'checkbox';
19287
19302
 
@@ -22998,7 +23013,7 @@ const SelectTable = React$5.forwardRef((props, ref) => {
22998
23013
  inputRef?.current.focus();
22999
23014
  e.preventDefault();
23000
23015
  }
23001
- }, children: jsxRuntime.jsxs("div", { className: 'r-select-grid', children: [jsxRuntime.jsx("div", { className: classnames('r-select-gridtable', { 'no-header': noHeader || (columns?.length ?? 0) === 0 }), ref: selectMenuTableRef, style: { width: menuWidth, minWidth: selectTableRef?.current?.clientWidth, maxHeight: maxHeight ?? defaultMaxHeight$1 }, children: jsxRuntime.jsx(RenderTable, {}) }), jsxRuntime.jsxs("div", { className: classnames('r-select-footer', { 'd-none': !(showFooter === true || handleAdd) }), children: [jsxRuntime.jsxs(Button$1, { outline: true, color: "primary", onClick: e => handleAdd?.(), className: classnames('r-btn d-flex align-items-center', { 'd-none': !handleAdd }), children: [jsxRuntime.jsx(SvgPlus, { className: "me-50", fontSize: 16 }), t('AddNew'), " (F9)"] }), footerComponent ? footerComponent() : null] })] }) }) }) })] }) }) }));
23016
+ }, children: jsxRuntime.jsxs("div", { className: 'r-select-grid', children: [jsxRuntime.jsx("div", { className: classnames('r-select-gridtable', { 'no-header': noHeader || (columns?.length ?? 0) === 0 }), ref: selectMenuTableRef, style: { width: menuWidth, minWidth: selectTableRef?.current?.clientWidth, maxHeight: maxHeight ?? defaultMaxHeight$1 }, children: jsxRuntime.jsx(RenderTable, {}) }), jsxRuntime.jsxs("div", { className: classnames('r-select-footer', { 'd-none': !(showFooter === true || handleAdd) }), children: [jsxRuntime.jsxs(Button$1, { outline: true, color: "primary", onClick: () => handleAdd?.(), className: classnames('r-btn d-flex align-items-center', { 'd-none': !handleAdd }), children: [jsxRuntime.jsx(SvgPlus, { className: "me-50", fontSize: 16 }), t('AddNew'), " (F9)"] }), footerComponent ? footerComponent() : null] })] }) }) }) })] }) }) }));
23002
23017
  });
23003
23018
 
23004
23019
  const SelectTableBox = (props) => {
@@ -25402,15 +25417,15 @@ const IconCustom = (props) => {
25402
25417
  };
25403
25418
 
25404
25419
  const CommandElement = (props) => {
25405
- const { commandItems, rowData, indexRow, handleCommandClick, indexFocus, setIndexFocus } = props;
25420
+ const { commandItems, rowData, indexRow, handleCommandClick, itemFocus, setItemFocus, currentItem } = props;
25406
25421
  const { t } = reactI18next.useTranslation();
25407
25422
  return (jsxRuntime.jsx(React$5.Fragment, { children: jsxRuntime.jsx("div", { className: 'd-flex align-items-center', style: { columnGap: 10 }, children: commandItems.map((item, index) => {
25408
25423
  return (jsxRuntime.jsxs(Button$1, { id: `command-item-${indexRow}-${index}`, tabIndex: -1, style: { padding: '5px', minWidth: 45, height: '100%' }, className: classnames('command-item', {
25409
25424
  'btn-icon': item.tooltip === ''
25410
25425
  }), color: item.color ? item.color : '#000', onClick: (e) => {
25411
25426
  handleCommandClick(item.id, rowData, indexRow);
25412
- if (indexRow === indexFocus) {
25413
- setIndexFocus(undefined);
25427
+ if (currentItem === itemFocus) {
25428
+ setItemFocus('');
25414
25429
  }
25415
25430
  e.preventDefault();
25416
25431
  }, children: [item.icon && jsxRuntime.jsx(IconCustom, { iconName: item.icon, size: 16 }), jsxRuntime.jsx(UncontrolledTooltip, { className: "r-tooltip", target: `command-item-${indexRow}-${index}`, place: "top", children: t(item.tooltip ?? '') })] }, `command-${index}`));
@@ -25768,16 +25783,6 @@ const SelectTableTree = React$5.forwardRef((props, ref) => {
25768
25783
  }, children: jsxRuntime.jsxs("div", { className: 'r-select-grid r-select-tree-grid', children: [jsxRuntime.jsx("div", { className: "r-select-gridtable ", ref: selectMenuTableRef, style: { width: menuWidth, minWidth: selectTableRef?.current?.clientWidth, maxHeight: maxHeight ?? defaultMaxHeight }, children: jsxRuntime.jsx(RenderTable, {}) }), jsxRuntime.jsxs("div", { className: classnames('r-select-footer', { 'd-none': !(showFooter === true || handleAdd || isMulti) }), children: [jsxRuntime.jsxs(Button$1, { outline: true, color: "primary", onClick: handleAdd, className: classnames('r-btn d-flex align-items-center', { 'd-none': !handleAdd }), children: [jsxRuntime.jsx(SvgPlus, { className: "me-50", fontSize: 16 }), t('AddNew'), " (F9)"] }), isMulti && jsxRuntime.jsx("div", { className: "ms-50 text-primary h-100 d-flex align-items-center", onClick: handleAdd, children: t('countSelected', { item: value?.length ?? 0 }) }), footerComponent ? footerComponent() : null] })] }) }) }) })] }) }) }));
25769
25784
  });
25770
25785
 
25771
- const renderToolbarTop = (toolbarTopOption) => {
25772
- return (jsxRuntime.jsx("div", { id: "table_custom_top_toolbar", className: "r-toolbar r-toolbar-top", "aria-orientation": "horizontal", children: jsxRuntime.jsxs("div", { className: "r-toolbar-items", children: [jsxRuntime.jsx("div", { className: "r-toolbar-left", children: toolbarTopOption?.map((item, index) => {
25773
- return ((item.align === 'left') ? jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-left-${index}`) }) : '');
25774
- }) }), jsxRuntime.jsx("div", { className: "r-toolbar-center", children: toolbarTopOption?.map((item, index) => {
25775
- return ((item.align === 'center') ? jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-center-${index}`) }) : '');
25776
- }) }), jsxRuntime.jsx("div", { className: "r-toolbar-right", children: toolbarTopOption?.map((item, index) => {
25777
- return ((item.align === 'right') ? jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-right-${index}`) }) : '');
25778
- }) })] }) }));
25779
- };
25780
-
25781
25786
  function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
25782
25787
 
25783
25788
  /**
@@ -42119,16 +42124,356 @@ const DateInput = (props) => {
42119
42124
  } }));
42120
42125
  };
42121
42126
 
42127
+ const handleArrowRight = (e, params) => {
42128
+ const { indexCol, contentColumns, row, parents, indexRow, focusNewElement } = params;
42129
+ let newIndexCol = -1;
42130
+ for (let i = indexCol; i < contentColumns.length; i++) {
42131
+ if (contentColumns[i].editEnable && contentColumns[i].visible !== false && !contentColumns[i].disabledCondition?.(row)) {
42132
+ newIndexCol = i + 1;
42133
+ break;
42134
+ }
42135
+ }
42136
+ if (newIndexCol > -1) {
42137
+ focusNewElement(newIndexCol, parents, indexRow);
42138
+ e.preventDefault();
42139
+ return e.code;
42140
+ }
42141
+ };
42142
+ const handleArrowLeft = (e, params) => {
42143
+ const { indexCol, contentColumns, row, parents, indexRow, focusNewElement } = params;
42144
+ let newIndexCol = -1;
42145
+ for (let i = indexCol - 2; i >= 0; i--) {
42146
+ if (contentColumns[i].editEnable && contentColumns[i].visible !== false && !contentColumns[i].disabledCondition?.(row)) {
42147
+ newIndexCol = i + 1;
42148
+ break;
42149
+ }
42150
+ }
42151
+ if (newIndexCol > -1) {
42152
+ focusNewElement(newIndexCol, parents, indexRow);
42153
+ e.preventDefault();
42154
+ return e.code;
42155
+ }
42156
+ };
42157
+ const isSelectMenuOpen = (element) => {
42158
+ return element && ["select__control--menu-is-open", "select-100__control--menu-is-open", "select-200__control--menu-is-open", "select-300__control--menu-is-open", "select-400__control--menu-is-open", "select-500__control--menu-is-open"].some(className => element.getElementsByClassName(className).length > 0);
42159
+ };
42160
+ const handleArrowUp = (e, params) => {
42161
+ const { idElement, indexCol, indexRow, parents, pagingClient, pagingSetting, setItemFocus, getNewParents, focusNewElement } = params;
42162
+ const element = document.getElementById(idElement);
42163
+ if (!isSelectMenuOpen(element)) {
42164
+ if (indexRow > 1) {
42165
+ if (parents === "" && pagingClient && pagingSetting?.currentPage !== 1 && indexRow % (pagingSetting?.pageSize ?? 0) === 1 && pagingSetting?.setCurrentPage) {
42166
+ pagingSetting.setCurrentPage((pagingSetting?.currentPage ?? 1) - 1);
42167
+ }
42168
+ setItemFocus(getNewParents(parents, indexRow - 2));
42169
+ focusNewElement(indexCol, parents, indexRow - 1, true);
42170
+ e.preventDefault();
42171
+ return e.code;
42172
+ }
42173
+ else if (parents !== "") {
42174
+ setItemFocus(parents);
42175
+ focusNewElement(indexCol, parents, undefined, true);
42176
+ e.preventDefault();
42177
+ return e.code;
42178
+ }
42179
+ }
42180
+ };
42181
+ const handleArrowDown = (e, params) => {
42182
+ const { idElement, row, fieldChildren, itemFocus, dataSource, indexCol, indexRow, parents, totalCount, pagingClient, pagingSetting, setItemFocus, getNewParents, focusNewElement } = params;
42183
+ const element = document.getElementById(idElement);
42184
+ if (!isSelectMenuOpen(element)) {
42185
+ if (row[fieldChildren ?? 'children']?.length > 0 && row.expanded) {
42186
+ setItemFocus(getNewParents(itemFocus, 0));
42187
+ focusNewElement(indexCol, itemFocus, 1, true);
42188
+ e.preventDefault();
42189
+ return e.code;
42190
+ }
42191
+ else {
42192
+ if (parents === '') {
42193
+ if (indexRow < totalCount) {
42194
+ if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42195
+ pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42196
+ }
42197
+ setItemFocus(getNewParents(parents, indexRow));
42198
+ focusNewElement(indexCol, parents, indexRow + 1, true);
42199
+ e.preventDefault();
42200
+ return e.code;
42201
+ }
42202
+ }
42203
+ else {
42204
+ const result = FindNodeByPath(dataSource, itemFocus);
42205
+ if (!result) {
42206
+ return;
42207
+ }
42208
+ const { parent, lastIndex } = result;
42209
+ if (!parent) {
42210
+ return;
42211
+ }
42212
+ if ((lastIndex ?? 0) < parent.length - 1) {
42213
+ setItemFocus(getNewParents(parents, indexRow));
42214
+ focusNewElement(indexCol, parents, indexRow + 1, true);
42215
+ e.preventDefault();
42216
+ return e.code;
42217
+ }
42218
+ else {
42219
+ const result = FindNodeByPath(dataSource, parents);
42220
+ if (!result) {
42221
+ return '';
42222
+ }
42223
+ const { lastIndex } = result;
42224
+ setItemFocus(getNewParents(parents.split('-').slice(0, -1).join('-'), (lastIndex ?? 0) + 1));
42225
+ focusNewElement(indexCol, parents.split('-').slice(0, -1).join('-'), (lastIndex ?? 0) + 2, true);
42226
+ e.preventDefault();
42227
+ return e.code;
42228
+ }
42229
+ }
42230
+ }
42231
+ }
42232
+ };
42233
+ const handleTab = (e, params) => {
42234
+ const { indexCol, columnLastEdit, indexRow, totalCount, moveIndexRowToNewPage, pagingClient, pagingSetting, setItemFocus, getNewParents, parents, focusNewElement } = params;
42235
+ if (indexCol === columnLastEdit) {
42236
+ if (indexRow === totalCount) {
42237
+ moveIndexRowToNewPage();
42238
+ }
42239
+ else {
42240
+ if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42241
+ pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42242
+ }
42243
+ setItemFocus(getNewParents(parents, indexRow));
42244
+ focusNewElement(indexCol, parents, indexRow + 1, true);
42245
+ }
42246
+ e.preventDefault();
42247
+ return e.code;
42248
+ }
42249
+ };
42250
+ const handleEnter = (e, params) => {
42251
+ const { idElement, row, fieldChildren, addDisable, dataSource, editDisable, moveIndexRowToNewPage, itemFocus, indexCol, indexRow, parents, totalCount, pagingClient, pagingSetting, setItemFocus, getNewParents, focusNewElement } = params;
42252
+ if (!editDisable && !addDisable) {
42253
+ const element = document.getElementById(idElement);
42254
+ if (!isSelectMenuOpen(element)) {
42255
+ if (row[fieldChildren ?? 'children']?.length > 0 && row.expanded) {
42256
+ setItemFocus(getNewParents(itemFocus, 0));
42257
+ focusNewElement(indexCol, itemFocus, 1, true);
42258
+ e.preventDefault();
42259
+ return e.code;
42260
+ }
42261
+ else {
42262
+ if (parents === '') {
42263
+ if (indexRow === totalCount) {
42264
+ moveIndexRowToNewPage();
42265
+ }
42266
+ else {
42267
+ if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42268
+ pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42269
+ }
42270
+ setItemFocus(getNewParents(parents, indexRow));
42271
+ focusNewElement(indexCol, parents, indexRow + 1, true);
42272
+ }
42273
+ e.preventDefault();
42274
+ return e.code;
42275
+ }
42276
+ else {
42277
+ const result = FindNodeByPath(dataSource, itemFocus);
42278
+ if (!result) {
42279
+ return;
42280
+ }
42281
+ const { parent, lastIndex } = result;
42282
+ if (!parent) {
42283
+ return;
42284
+ }
42285
+ if ((lastIndex ?? 0) < parent.length - 1) {
42286
+ setItemFocus(getNewParents(parents, indexRow));
42287
+ focusNewElement(indexCol, parents, indexRow + 1, true);
42288
+ e.preventDefault();
42289
+ return e.code;
42290
+ }
42291
+ else {
42292
+ const result = FindNodeByPath(dataSource, parents);
42293
+ if (!result) {
42294
+ return '';
42295
+ }
42296
+ const { lastIndex } = result;
42297
+ setItemFocus(getNewParents(parents.split('-').slice(0, -1).join('-'), (lastIndex ?? 0) + 1));
42298
+ focusNewElement(indexCol, parents.split('-').slice(0, -1).join('-'), (lastIndex ?? 0) + 2, true);
42299
+ e.preventDefault();
42300
+ return e.code;
42301
+ }
42302
+ }
42303
+ }
42304
+ }
42305
+ }
42306
+ };
42307
+ const handleCtrlD = (e, params) => {
42308
+ const { editDisable, addDisable, handleDuplicate } = params;
42309
+ if (!editDisable && !addDisable) {
42310
+ handleDuplicate();
42311
+ e.preventDefault();
42312
+ return e.code;
42313
+ }
42314
+ };
42315
+
42316
+ const ToolbarBottom = ({ handleAdd, handleDuplicate, handleInsertBefore, handleInsertAfter, handleDeleteAll, setOpenPopupSetupColumn, itemFocus, editDisable, addDisable, buttonSetting, toolbarSetting, headerColumns, t
42317
+ // isTree
42318
+ }) => {
42319
+ return (jsxRuntime.jsx("div", { id: "table_custom_bottom_toolbar", className: "r-toolbar r-toolbar-bottom", role: "toolbar", children: jsxRuntime.jsxs("div", { className: "r-toolbar-items", children: [jsxRuntime.jsxs("div", { className: "r-toolbar-left", children: [jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable }), children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: handleAdd, className: 'd-flex', children: t('Add item') }) }), itemFocus && jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.duplicateDisable }), children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: handleDuplicate, className: 'd-flex', children: t('Duplicate') }) }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.insertBeforeDisable }), children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: handleInsertBefore, className: 'd-flex', children: t('Insert item before') }) }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.insertAfterDisable }), children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: handleInsertAfter, className: 'd-flex', children: t('Insert item after') }) })] }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || buttonSetting?.deleteAllDisable }), children: jsxRuntime.jsx(Button$1, { color: 'primary', outline: true, onClick: handleDeleteAll, className: 'd-flex', children: t('Delete all item') }) }), toolbarSetting?.toolbarBottomOptions?.map((item, index) => (item.align === 'left' && (jsxRuntime.jsx("div", { className: "r-toolbar-item", children: item.template() }, `toolbar-bottom-left-${index}`))))] }), jsxRuntime.jsx("div", { className: "r-toolbar-center", children: toolbarSetting?.toolbarBottomOptions?.map((item, index) => (item.align === 'center' && (jsxRuntime.jsx("div", { className: "r-toolbar-item", children: item.template() }, `toolbar-bottom-center-${index}`)))) }), jsxRuntime.jsxs("div", { className: "r-toolbar-right", children: [toolbarSetting?.toolbarBottomOptions?.map((item, index) => (item.align === 'right' && (jsxRuntime.jsx("div", { className: "r-toolbar-item", children: item.template() }, `toolbar-bottom-right-${index}`)))), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item me-25', { 'd-none': headerColumns.length > 1 }), children: jsxRuntime.jsx(SvgSettings, { className: "text-primary cursor-pointer", onClick: () => setOpenPopupSetupColumn(true) }) }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item me-25', { 'd-none': editDisable || addDisable }), children: jsxRuntime.jsxs(UncontrolledDropdown, { className: 'dropdown-user nav-item', children: [jsxRuntime.jsx(DropdownToggle$1, { tag: 'div', color: "primary", onClick: (e) => e.preventDefault(), children: jsxRuntime.jsx(SvgInfo, { className: "cursor-pointer text-primary" }) }), jsxRuntime.jsx(DropdownMenu$1, { className: 'formula-dropdown icon-dropdown', children: jsxRuntime.jsxs("ul", { className: "mb-0 pe-50", children: [jsxRuntime.jsx("li", { style: { fontSize: 13 }, children: "Nh\u1EA5n v\u00E0o c\u1ED9t STT \u0111\u1EC3 ch\u1ECDn h\u00E0ng v\u00E0 nh\u1EA5n Ctrl + D \u0111\u1EC3 nh\u00E2n b\u1EA3n" }), jsxRuntime.jsx("li", { style: { fontSize: 13 }, children: "Ch\u1ECDn \u00F4 v\u00E0 Ctrl + V \u0111\u1EC3 d\u00E1n th\u00F4ng tin t\u1EEB excel" }), jsxRuntime.jsx("li", { style: { fontSize: 13 }, children: "Nh\u1EA5n v\u00E0o c\u1ED9t STT \u0111\u1EC3 ch\u1ECDn h\u00E0ng v\u00E0 nh\u1EA5n Ctrl + C \u0111\u1EC3 sao ch\u00E9p h\u00E0ng" }), jsxRuntime.jsx("li", { style: { fontSize: 13 }, children: "Nh\u1EA5n v\u00E0o c\u1ED9t STT \u0111\u1EC3 ch\u1ECDn h\u00E0ng v\u00E0 nh\u1EA5n Ctrl + V \u0111\u1EC3 d\u00E1n h\u00E0ng" })] }) })] }) })] })] }) }));
42320
+ };
42321
+
42322
+ const RenderToolbarTop = ({ toolbarTopOption }) => {
42323
+ return (jsxRuntime.jsx("div", { id: "table_custom_top_toolbar", className: "r-toolbar r-toolbar-top", "aria-orientation": "horizontal", children: jsxRuntime.jsxs("div", { className: "r-toolbar-items", children: [jsxRuntime.jsx("div", { className: "r-toolbar-left", children: toolbarTopOption?.map((item, index) => {
42324
+ return ((item.align === 'left') ? jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-left-${index}`) }) : '');
42325
+ }) }), jsxRuntime.jsx("div", { className: "r-toolbar-center", children: toolbarTopOption?.map((item, index) => {
42326
+ return ((item.align === 'center') ? jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-center-${index}`) }) : '');
42327
+ }) }), jsxRuntime.jsx("div", { className: "r-toolbar-right", children: toolbarTopOption?.map((item, index) => {
42328
+ return ((item.align === 'right') ? jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-right-${index}`) }) : '');
42329
+ }) })] }) }));
42330
+ };
42331
+
42332
+ const FooterCol = ({ col, indexCol, dataSource, objWidthFix, formatSetting }) => {
42333
+ const sumValue = (col.haveSum === true && col.editType === "numeric") ? dataSource.reduce(function (accumulator, currentValue) { return (Number(accumulator ?? 0) + Number(currentValue[col.field] ?? 0)); }, 0) : 0;
42334
+ return (jsxRuntime.jsx(React$5.Fragment, { children: col.visible !== false && (jsxRuntime.jsx("td", { className: classnames(`p-0 px-50 r-footer fix-${col.fixedType}`, { "cell-fixed": col.fixedType }), style: {
42335
+ left: col.fixedType === "left" ? objWidthFix[indexCol] : undefined,
42336
+ right: col.fixedType === "right" ? objWidthFix[indexCol] : undefined,
42337
+ textAlign: col.textAlign ?? "left"
42338
+ }, children: jsxRuntime.jsx("div", { className: "r-footer-div", children: col.haveSum === true && col.editType === "numeric" && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: Number(sumValue) >= 0 ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: formartNumberic(sumValue, formatSetting?.decimalSeparator ?? ",", formatSetting?.thousandSeparator ?? ".", col.numericSettings?.fraction, true, false) })) : (jsxRuntime.jsx("div", { style: { color: formatSetting?.colorNegative ?? "red" }, children: `${formatSetting?.prefixNegative ?? "-"}${formartNumberic(sumValue, formatSetting?.decimalSeparator ?? ",", formatSetting?.thousandSeparator ?? ".", col.numericSettings?.fraction, true, false)}${formatSetting?.suffixNegative ?? ""}` })) })) }) })) }, `summarycell-${indexCol}`));
42339
+ };
42340
+
42341
+ const handleAdd = (dataSource, tableElement, columnFistEdit,
42342
+ /*eslint-disable*/
42343
+ changeDataSource, pagingSetting, setItemFocus, focusNewElement
42344
+ /*eslint-enable*/
42345
+ ) => {
42346
+ const lengthData = dataSource.length;
42347
+ changeDataSource(dataSource, true);
42348
+ if (pagingSetting?.setCurrentPage) {
42349
+ pagingSetting.setCurrentPage(Math.floor(lengthData / (pagingSetting?.pageSize ?? 0)) + 1);
42350
+ }
42351
+ if (tableElement) {
42352
+ setItemFocus(`${lengthData}`);
42353
+ focusNewElement(columnFistEdit, '', lengthData + 1, true);
42354
+ }
42355
+ };
42356
+ const handleDuplicate = async (dataSource, itemFocus, fieldKey, defaultValue, fieldUniKey,
42357
+ /*eslint-disable*/
42358
+ changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate // sự kiện khi duplicate
42359
+ /*eslint-enable*/
42360
+ ) => {
42361
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.duplicateDisable && !editDisable && !addDisable) {
42362
+ const result = FindNodeByPath(dataSource, itemFocus);
42363
+ if (!result) {
42364
+ return;
42365
+ }
42366
+ const { parent, lastIndex, node } = result;
42367
+ if (!parent || !node) {
42368
+ return;
42369
+ }
42370
+ const newData = { ...node };
42371
+ if (fieldKey && defaultValue) {
42372
+ fieldUniKey.forEach((item) => {
42373
+ newData[item] = defaultValue[item];
42374
+ });
42375
+ newData[fieldKey] = defaultValue[fieldKey];
42376
+ }
42377
+ if (onDuplicate) {
42378
+ await onDuplicate(newData, (lastIndex ?? 0));
42379
+ }
42380
+ parent.splice((lastIndex ?? -1) + 1, 0, newData);
42381
+ changeDataSource([...dataSource]);
42382
+ if (tableElement && lastIndex === totalCount) {
42383
+ setTimeout(() => {
42384
+ tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
42385
+ }, 100);
42386
+ }
42387
+ }
42388
+ };
42389
+ const handleInsertAfter = (dataSource, itemFocus, defaultValue,
42390
+ /*eslint-disable*/
42391
+ changeDataSource,
42392
+ /*eslint-enable*/
42393
+ tableElement, totalCount, pagingClient, pagingSetting, toolbarSetting, buttonSetting, editDisable, addDisable) => {
42394
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertAfterDisable && !editDisable && !addDisable) {
42395
+ const result = FindNodeByPath(dataSource, itemFocus);
42396
+ if (!result) {
42397
+ return;
42398
+ }
42399
+ const { parent, lastIndex, firstIndex } = result;
42400
+ if (!parent) {
42401
+ return;
42402
+ }
42403
+ if (firstIndex >= 0) {
42404
+ if (pagingClient) {
42405
+ dataSource.splice(((((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0)) + (firstIndex ?? -1) + 1), 0, { ...defaultValue });
42406
+ }
42407
+ else {
42408
+ dataSource.splice((firstIndex ?? -1) + 1, 0, { ...defaultValue });
42409
+ }
42410
+ if (tableElement && firstIndex === totalCount) {
42411
+ setTimeout(() => {
42412
+ tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
42413
+ }, 100);
42414
+ }
42415
+ }
42416
+ else {
42417
+ // Chèn vào sau phần tử cuối cùng
42418
+ parent.splice((lastIndex ?? -1) + 1, 0, { ...defaultValue });
42419
+ }
42420
+ changeDataSource([...dataSource]);
42421
+ }
42422
+ };
42423
+ const handleInsertBefore = (dataSource, itemFocus, defaultValue,
42424
+ /*eslint-disable*/
42425
+ changeDataSource,
42426
+ /*eslint-enable*/
42427
+ pagingClient, pagingSetting, toolbarSetting, buttonSetting, editDisable, addDisable) => {
42428
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertAfterDisable && !editDisable && !addDisable) {
42429
+ const result = FindNodeByPath(dataSource, itemFocus);
42430
+ if (!result) {
42431
+ return;
42432
+ }
42433
+ const { parent, lastIndex, firstIndex } = result;
42434
+ if (!parent) {
42435
+ return;
42436
+ }
42437
+ if (firstIndex >= 0) {
42438
+ if (pagingClient) {
42439
+ dataSource.splice(((((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0)) + (firstIndex ?? -1)), 0, { ...defaultValue });
42440
+ }
42441
+ else {
42442
+ dataSource.splice((firstIndex ?? -1), 0, { ...defaultValue });
42443
+ }
42444
+ }
42445
+ else {
42446
+ // Chèn vào sau phần tử cuối cùng
42447
+ parent.splice((lastIndex ?? -1), 0, { ...defaultValue });
42448
+ }
42449
+ changeDataSource([...dataSource]);
42450
+ }
42451
+ };
42452
+ const handleDeleteAll = (t,
42453
+ /*eslint-disable*/
42454
+ messageBoxConfirmDelete, setItemFocus, changeDataSource,
42455
+ /*eslint-enable*/
42456
+ editDisable, addDisable, toolbarSetting, buttonSetting) => {
42457
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.deleteAllDisable && !editDisable && !addDisable) {
42458
+ messageBoxConfirmDelete(t, () => {
42459
+ if (!editDisable && !addDisable) {
42460
+ setItemFocus('');
42461
+ changeDataSource([], false);
42462
+ }
42463
+ }, '');
42464
+ }
42465
+ };
42466
+
42122
42467
  const TableEdit = React$5.forwardRef((props, ref) => {
42123
42468
  const { t } = reactI18next.useTranslation();
42124
- 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;
42469
+ 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, fieldChildren = "children", isTree = false, onDuplicate } = props;
42125
42470
  React$5.useImperativeHandle(ref, () => {
42126
42471
  return {
42127
42472
  refeshFocusRow: handleRefeshRow
42128
42473
  };
42129
42474
  });
42130
42475
  const [refreshRow, setRefreshRow] = React$5.useState(false);
42131
- const [indexFocus, setIndexFocus] = React$5.useState();
42476
+ const [itemFocus, setItemFocus] = React$5.useState('');
42132
42477
  const [selectedRows, setSelectedRows] = React$5.useState([]);
42133
42478
  const [headerColumns, setHeaderColumns] = React$5.useState([[]]);
42134
42479
  const [contentColumns, setContentColumns] = React$5.useState([]);
@@ -42145,6 +42490,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42145
42490
  const searchClient = searchSetting?.searchEnable && (searchSetting?.searchClient || !(editDisable || addDisable));
42146
42491
  const fieldKey = columns.find((item) => item.isPrimarykey === true)?.field ?? 'id';
42147
42492
  const fieldUniKey = columns.filter((item) => item.isUnikey === true)?.map((item) => item.field);
42493
+ const getNewParents = (parents, index) => (parents ? `${parents}-${index}` : `${index}`);
42148
42494
  React$5.useEffect(() => {
42149
42495
  if (pagingClient && pagingSetting.setCurrentPage && Math.ceil(totalCount / (pagingSetting?.pageSize ?? 1)) < (pagingSetting.currentPage ?? 1)) {
42150
42496
  pagingSetting.setCurrentPage(1);
@@ -42295,30 +42641,251 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42295
42641
  else {
42296
42642
  toolbarTopOption = [...defaultToolbarOption];
42297
42643
  }
42298
- const RenderEdit = (row, col, indexCol, indexRow) => {
42644
+ const onChangePage = (args) => {
42645
+ if (pagingSetting?.setCurrentPage) {
42646
+ if (args.currentPage === args.oldPage) {
42647
+ return;
42648
+ }
42649
+ pagingSetting.setCurrentPage(args.currentPage);
42650
+ }
42651
+ };
42652
+ const onChangePageSize = (args) => {
42653
+ if (pagingSetting?.allowPaging) {
42654
+ if (pagingSetting?.pageSize !== args.pageSize) {
42655
+ if (pagingSetting?.setPageSize) {
42656
+ pagingSetting.setPageSize(args.pageSize);
42657
+ }
42658
+ if (pagingSetting?.setCurrentPage) {
42659
+ pagingSetting.setCurrentPage(1);
42660
+ }
42661
+ }
42662
+ }
42663
+ };
42664
+ useOnClickOutside(gridRef, () => {
42665
+ setTimeout(() => {
42666
+ setItemFocus('');
42667
+ }, 50);
42668
+ });
42669
+ const getColumn = (col, index) => {
42670
+ const column = contentColumns.filter(e => e.visible !== false)[col + index];
42671
+ if (column) {
42672
+ return { ...column };
42673
+ }
42674
+ return undefined;
42675
+ };
42676
+ const pasteDataFromExcel = async (currenRowIndex, col, e) => {
42677
+ const clipboard = (e.clipboardData || window.Clipboard).getData('text');
42678
+ const rowsClipboard = clipboard.trimEnd().split('\n');
42679
+ setItemFocus('');
42680
+ if (rowsClipboard.length > 200) {
42681
+ messageBoxError(t, 'You can only paste up to 200 rows.');
42682
+ }
42683
+ if (rowsClipboard.length > 0) {
42684
+ const columnsDataChange = [];
42685
+ for (let index = 0; index < rowsClipboard[0].trimEnd().split('\t').length; index++) {
42686
+ const stringData = [];
42687
+ rowsClipboard.forEach((element) => {
42688
+ if (element.trimEnd().split('\t')[index] && !stringData.includes(element.trimEnd().split('\t')[index].toString().trim())) {
42689
+ stringData.push(element.trimEnd().split('\t')[index].toString().trim());
42690
+ }
42691
+ });
42692
+ const column = getColumn(col, index);
42693
+ if (column) {
42694
+ if ((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + 0])) && column.editEnable && column.onPasteValidate) {
42695
+ const rs = await column.onPasteValidate(stringData.join(','), currenRowIndex + 0, dataSource[currenRowIndex + 0]);
42696
+ if (rs) {
42697
+ column.resultValidate = rs;
42698
+ }
42699
+ }
42700
+ columnsDataChange.push(column);
42701
+ }
42702
+ }
42703
+ for (let indexRow = 0; indexRow < rowsClipboard.length; indexRow++) {
42704
+ const item = rowsClipboard[indexRow];
42705
+ const colsClipboard = item.trimEnd().split('\t');
42706
+ let dataRow = dataSource[currenRowIndex + indexRow];
42707
+ if (!dataRow) {
42708
+ dataRow = { ...defaultValue };
42709
+ dataSource.push(dataRow);
42710
+ }
42711
+ for (let index = 0; index < colsClipboard.length; index++) {
42712
+ const stringData = colsClipboard[index].toString().trim();
42713
+ const column = columnsDataChange[index];
42714
+ if (column) {
42715
+ if (((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + indexRow])) && column.editEnable) || column.onPaste) {
42716
+ if (column.onPasteValidate && column.resultValidate) {
42717
+ const rs = column.resultValidate.find((item) => item[column.selectSettings?.fieldValue ?? 'value'] === stringData);
42718
+ if (rs) {
42719
+ if (column.onPaste) {
42720
+ dataRow[column.field] = column.onPaste(dataRow, stringData);
42721
+ }
42722
+ else {
42723
+ dataRow[column.field] = stringData;
42724
+ }
42725
+ if (column.callback) {
42726
+ column.callback(rs, currenRowIndex + indexRow);
42727
+ }
42728
+ }
42729
+ else {
42730
+ notificationError(t('PasteExcelNotExist', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42731
+ }
42732
+ }
42733
+ else {
42734
+ if (column.editType === 'date') {
42735
+ const date = new Date(stringData);
42736
+ if (!isNaN(date.getTime())) {
42737
+ if (column.onPaste) {
42738
+ dataRow[column.field] = column.onPaste(dataRow, date);
42739
+ }
42740
+ else {
42741
+ dataRow[column.field] = date;
42742
+ }
42743
+ if (column.callback) {
42744
+ column.callback(date, currenRowIndex + indexRow);
42745
+ }
42746
+ }
42747
+ else {
42748
+ notificationError(t('PasteExcelIncorrectFormat', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42749
+ }
42750
+ }
42751
+ else if (column.editType === 'numeric') {
42752
+ const number = Number(stringData);
42753
+ if (!isNaN(number)) {
42754
+ if (column.onPaste) {
42755
+ dataRow[column.field] = column.onPaste(dataRow, number);
42756
+ }
42757
+ else {
42758
+ dataRow[column.field] = number;
42759
+ }
42760
+ if (column.callback) {
42761
+ column.callback(number, currenRowIndex + indexRow);
42762
+ }
42763
+ }
42764
+ else {
42765
+ notificationError(t('PasteExcelIncorrectFormat', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42766
+ }
42767
+ }
42768
+ else if (column.editType === 'select') {
42769
+ const rs = ((column.selectSettings?.optionsField ? item[column.selectSettings?.optionsField] : column.selectSettings?.options) ?? []).find((item) => item[column.selectSettings?.fieldValue ?? 'value'] === stringData);
42770
+ if (rs) {
42771
+ if (column.onPaste) {
42772
+ dataRow[column.field] = column.onPaste(dataRow, stringData);
42773
+ }
42774
+ else {
42775
+ dataRow[column.field] = stringData;
42776
+ }
42777
+ if (column.callback) {
42778
+ column.callback(rs, currenRowIndex + indexRow);
42779
+ }
42780
+ }
42781
+ else {
42782
+ notificationError(t('PasteExcelNotExist', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42783
+ }
42784
+ }
42785
+ else {
42786
+ if (column.onPaste) {
42787
+ column.onPaste(dataRow, stringData);
42788
+ }
42789
+ else {
42790
+ dataRow[column.field] = stringData;
42791
+ }
42792
+ if (column.callback) {
42793
+ column.callback(stringData, currenRowIndex + indexRow);
42794
+ }
42795
+ }
42796
+ }
42797
+ }
42798
+ }
42799
+ }
42800
+ if (rowChange) {
42801
+ rowChange(dataRow, currenRowIndex + indexRow, '');
42802
+ }
42803
+ }
42804
+ }
42805
+ changeDataSource(dataSource);
42806
+ };
42807
+ const changeDataSource = (data, haveNew = false) => {
42808
+ if (!editDisable && setDataSource) {
42809
+ if (haveNew && !addDisable) {
42810
+ data.push(defaultValue ? { ...defaultValue, [fieldKey]: disableAutoKey ? undefined : generateUUID() } : {});
42811
+ setDataSource([...data]);
42812
+ }
42813
+ else {
42814
+ setDataSource([...data]);
42815
+ }
42816
+ }
42817
+ };
42818
+ React$5.useEffect(() => {
42819
+ setItemFocus('');
42820
+ if (setSelectedItem) {
42821
+ if (isMulti) {
42822
+ if (dataSource && selectedRows && selectedRows?.length !== selectedItem?.length) {
42823
+ setSelectedItem([...selectedRows]);
42824
+ if (handleSelect) {
42825
+ handleSelect([...selectedRows]);
42826
+ }
42827
+ }
42828
+ }
42829
+ else {
42830
+ if (dataSource && selectedRows?.length > 0) {
42831
+ if ((!selectedItem || (selectedItem[fieldKey] !== selectedRows[0][fieldKey]))) {
42832
+ setSelectedItem({ ...selectedRows[0] });
42833
+ if (handleSelect) {
42834
+ handleSelect({ ...selectedRows[0] });
42835
+ }
42836
+ }
42837
+ }
42838
+ else {
42839
+ setSelectedItem(undefined);
42840
+ if (handleSelect) {
42841
+ handleSelect(undefined);
42842
+ }
42843
+ }
42844
+ }
42845
+ }
42846
+ }, [selectedRows]);
42847
+ React$5.useEffect(() => {
42848
+ if (!isMulti) {
42849
+ if (dataSource && selectedItem && selectedItem[fieldKey]) {
42850
+ if (selectedRows?.length === 0 || selectedItem[fieldKey] !== selectedRows[0][fieldKey]) {
42851
+ setSelectedRows([selectedItem]);
42852
+ }
42853
+ }
42854
+ else {
42855
+ setSelectedRows([]);
42856
+ }
42857
+ }
42858
+ else {
42859
+ if (dataSource && selectedItem && selectedRows?.length !== selectedItem.length) {
42860
+ setSelectedRows(selectedItem ? [...selectedItem] : []);
42861
+ }
42862
+ }
42863
+ }, [selectedItem]);
42864
+ const RenderEdit = (row, col, parents, indexCol, indexRow) => {
42865
+ const idElement = `${idTable}-col${indexCol + 1}-row${getNewParents(parents, indexRow + 1)}`;
42299
42866
  /*eslint-disable */
42300
42867
  switch (col?.editTypeCondition ? col?.editTypeCondition(row) : col.editType) {
42301
42868
  case 'date':
42302
- return (jsxRuntime.jsx(DateInput, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, className: classnames('form-control border-0 rounded-0 input-numeric', { 'is-invalid': col.validate && col.validate(row[col.field], row) }), value: row[col.field], onChange: (date) => {
42869
+ return (jsxRuntime.jsx(DateInput, { id: idElement, className: classnames('form-control border-0 rounded-0 input-numeric', { 'is-invalid': col.validate && col.validate(row[col.field], row) }), value: row[col.field], onChange: (date) => {
42303
42870
  row[col.field] = date ? new Date(date.getTime() + 7 * 60 * 60 * 1000) : undefined;
42304
42871
  if (col.callback) {
42305
- col.callback(row[col.field], indexRow);
42872
+ col.callback(row[col.field], indexRow, row);
42306
42873
  }
42307
42874
  handleDataChange(row, col, indexRow);
42308
42875
  }, dateFormat: "dd/MM/yyyy", onKeyDown: (e) => {
42309
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) {
42876
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) {
42310
42877
  return true;
42311
42878
  }
42312
42879
  } }));
42313
42880
  case 'datetime':
42314
- return (jsxRuntime.jsx(DateInput, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, className: classnames('form-control border-0 rounded-0 input-numeric', { 'is-invalid': col.validate && col.validate(row[col.field], row) }), value: row[col.field], onChange: (date) => {
42881
+ return (jsxRuntime.jsx(DateInput, { id: idElement, className: classnames('form-control border-0 rounded-0 input-numeric', { 'is-invalid': col.validate && col.validate(row[col.field], row) }), value: row[col.field], onChange: (date) => {
42315
42882
  row[col.field] = date;
42316
42883
  if (col.callback) {
42317
- col.callback(row[col.field], indexRow);
42884
+ col.callback(row[col.field], indexRow, row);
42318
42885
  }
42319
42886
  handleDataChange(row, col, indexRow);
42320
42887
  }, dateFormat: "dd/MM/yyyy HH:mm", onKeyDown: (e) => {
42321
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) {
42888
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) {
42322
42889
  return true;
42323
42890
  }
42324
42891
  } }));
@@ -42340,7 +42907,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42340
42907
  valueSelect = col.selectSettings?.defaultValue(row);
42341
42908
  }
42342
42909
  }
42343
- return (jsxRuntime.jsx(SelectTable, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, value: valueSelect, options: optionsSelect, onChange: (val) => {
42910
+ return (jsxRuntime.jsx(SelectTable, { id: idElement, value: valueSelect, options: optionsSelect, onChange: (val) => {
42344
42911
  if (col.selectSettings?.isMulti) {
42345
42912
  row[col.field] = (val?.length ?? 0) > 0 ? val.map((item) => item[col.selectSettings?.fieldValue ?? 'value']) : [];
42346
42913
  }
@@ -42362,11 +42929,11 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42362
42929
  }
42363
42930
  }
42364
42931
  if (col.callback) {
42365
- col.callback(val, indexRow);
42932
+ col.callback(val, indexRow, row);
42366
42933
  }
42367
42934
  handleDataChange(row, col, indexRow);
42368
- }, fieldValue: col.selectSettings?.fieldValue, fieldLabel: col.selectSettings?.fieldLabel, component: gridRef, columns: col.selectSettings?.columns, isClearable: col.selectSettings?.isClearable ?? false, formatSetting: formatSetting, placeholder: t('Select'), loadOptions: col.selectSettings?.loadOptions, handleAdd: col.selectSettings?.handAddNew ? (e) => col.selectSettings?.handAddNew(e, indexRow, row) : undefined, isMulti: col.selectSettings?.isMulti, noHeader: col.selectSettings?.noHeader, showFooter: col.selectSettings?.showFooter, formatOptionLabel: col.selectSettings?.formatOptionLabel, footerComponent: col.selectSettings?.footerComponent, invalid: col.validate && col.validate(row[col.field], row), maxHeight: col.selectSettings?.heightPopup ? Number(col.selectSettings?.heightPopup) : undefined, menuWidth: col.selectSettings?.widthPopup ? Number(col.selectSettings?.widthPopup) : undefined, textAlign: col.textAlign ?? 'left', allowCreate: col.selectSettings?.allowCreate, onKeyDown: (e) => {
42369
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) ;
42935
+ }, fieldValue: col.selectSettings?.fieldValue, fieldLabel: col.selectSettings?.fieldLabel, component: gridRef, columns: col.selectSettings?.columns, isClearable: col.selectSettings?.isClearable ?? false, formatSetting: formatSetting, placeholder: t('Select'), loadOptions: col.selectSettings?.loadOptions, handleAdd: col.selectSettings?.handAddNew ? (e) => col.selectSettings?.handAddNew(e, indexRow, row) : undefined, isMulti: col.selectSettings?.isMulti, noHeader: col.selectSettings?.noHeader, showFooter: col.selectSettings?.showFooter, formatOptionLabel: col.selectSettings?.formatOptionLabel, footerComponent: col.selectSettings?.footerComponent, invalid: (col.validate && !isNullOrUndefined$1(col.validate(row[col.field], row))), maxHeight: col.selectSettings?.heightPopup ? Number(col.selectSettings?.heightPopup) : undefined, menuWidth: col.selectSettings?.widthPopup ? Number(col.selectSettings?.widthPopup) : undefined, textAlign: col.textAlign ?? 'left', allowCreate: col.selectSettings?.allowCreate, onKeyDown: (e) => {
42936
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) ;
42370
42937
  }, onOpenMenu: () => {
42371
42938
  if (col.selectSettings?.onOpenMenu) {
42372
42939
  col.selectSettings?.onOpenMenu(row, col, indexRow);
@@ -42407,8 +42974,8 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42407
42974
  valueSelectTree = (!isNullOrUndefined$1(row[col.field]) && row[col.field] !== '') ? findItemInTree(optionsSelectTree, row[col.field]) : '';
42408
42975
  }
42409
42976
  return (jsxRuntime.jsx("div", { onKeyDown: (e) => {
42410
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) ;
42411
- }, children: jsxRuntime.jsx(SelectTableTree, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, value: valueSelectTree, options: optionsSelectTree, onChange: (val) => {
42977
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) ;
42978
+ }, children: jsxRuntime.jsx(SelectTableTree, { id: idElement, value: valueSelectTree, options: optionsSelectTree, onChange: (val) => {
42412
42979
  if (col.selectSettings?.isMulti) {
42413
42980
  row[col.field] = !isNullOrUndefined$1(val) ? val : [];
42414
42981
  }
@@ -42416,7 +42983,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42416
42983
  row[col.field] = !isNullOrUndefined$1(val) ? val[col.selectSettings?.fieldValue ?? 'value'] : undefined;
42417
42984
  }
42418
42985
  if (col.callback) {
42419
- col.callback(val, indexRow);
42986
+ col.callback(val, indexRow, row);
42420
42987
  }
42421
42988
  handleDataChange(row, col, indexRow);
42422
42989
  }, fieldValue: col.selectSettings?.fieldValue, fieldLabel: col.selectSettings?.fieldLabel, component: gridRef, columns: col.selectSettings?.columns, isClearable: col.selectSettings?.isClearable ?? false, formatSetting: formatSetting, placeholder: t('Select'), onOpenMenu: () => {
@@ -42424,7 +42991,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42424
42991
  col.selectSettings?.onOpenMenu(row, col, indexRow);
42425
42992
  }
42426
42993
  }, loadOptions: col.selectSettings?.loadOptions, handleAdd: col.selectSettings?.handAddNew ? (e) => col.selectSettings?.handAddNew(e, indexRow, row) : undefined, fieldChildren: col.selectSettings?.fieldChild ?? 'children', selectChilds: col.selectSettings?.selectChilds, showFooter: col.selectSettings?.showFooter, formatOptionLabel: col.selectSettings?.formatOptionLabel, footerComponent: col.selectSettings?.footerComponent, width: col.selectSettings?.widthPopup ? Number(col.selectSettings?.widthPopup) : undefined, isMulti: col.selectSettings?.isMulti, noHeader: col.selectSettings?.noHeader, invalid: col.validate && col.validate(row[col.field], row), maxHeight: col.selectSettings?.heightPopup ? Number(col.selectSettings?.heightPopup) : undefined, menuWidth: col.selectSettings?.widthPopup ? Number(col.selectSettings?.widthPopup) : undefined, textAlign: col.textAlign ?? 'left', onKeyDown: (e) => {
42427
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) ;
42994
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) ;
42428
42995
  }, onPaste: (e) => {
42429
42996
  if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
42430
42997
  pasteDataFromExcel(indexRow, indexCol, e);
@@ -42432,14 +42999,14 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42432
42999
  }
42433
43000
  } }) }));
42434
43001
  case 'checkbox':
42435
- return (jsxRuntime.jsx(Input$1, { checked: row[col.field], id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, type: "checkbox", className: "input-checkbox cursor-pointer", style: { textAlign: col.textAlign ?? 'left', marginTop: 6 }, onChange: (val) => {
43002
+ return (jsxRuntime.jsx(Input$1, { checked: row[col.field], id: idElement, type: "checkbox", className: "input-checkbox cursor-pointer", style: { textAlign: col.textAlign ?? 'left', marginTop: 6 }, onChange: (val) => {
42436
43003
  row[col.field] = val.currentTarget.checked;
42437
43004
  if (col.callback) {
42438
- col.callback(val.target.value, indexRow);
43005
+ col.callback(val.target.value, indexRow, row);
42439
43006
  }
42440
43007
  handleDataChange(row, col, indexRow);
42441
43008
  }, onKeyDown: (e) => {
42442
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) ;
43009
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) ;
42443
43010
  } }));
42444
43011
  case 'numeric':
42445
43012
  const numericFormatProps = {
@@ -42450,7 +43017,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42450
43017
  decimalScale: col.numericSettings?.fraction ?? 0
42451
43018
  };
42452
43019
  let floatValue = parseFloat(row[col.field]);
42453
- return (jsxRuntime.jsx(NumericFormat, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, style: { textAlign: col.textAlign, height: 29 }, ...numericFormatProps, defaultValue: formartNumberic(row[col.field], formatSetting?.decimalSeparator ?? ',', formatSetting?.thousandSeparator ?? '.', col.numericSettings?.fraction), className: classnames('form-control border-0 rounded-0 input-numeric', { 'is-invalid': col.validate && col.validate(row[col.field], row) }), onValueChange: (values) => {
43020
+ return (jsxRuntime.jsx(NumericFormat, { id: idElement, style: { textAlign: col.textAlign, height: 29 }, ...numericFormatProps, defaultValue: formartNumberic(row[col.field], formatSetting?.decimalSeparator ?? ',', formatSetting?.thousandSeparator ?? '.', col.numericSettings?.fraction), className: classnames('form-control border-0 rounded-0 input-numeric', { 'is-invalid': col.validate && col.validate(row[col.field], row) }), onValueChange: (values) => {
42454
43021
  floatValue = values?.floatValue;
42455
43022
  }, onFocus: (e) => {
42456
43023
  e.target.setSelectionRange(0, e.target.innerText.length - 1);
@@ -42458,7 +43025,7 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42458
43025
  if (floatValue !== row[col.field]) {
42459
43026
  row[col.field] = !isNaN(floatValue) ? floatValue : 0;
42460
43027
  if (col.callback) {
42461
- col.callback(row[col.field], indexRow);
43028
+ col.callback(row[col.field], indexRow, row);
42462
43029
  }
42463
43030
  handleDataChange(row, col, indexRow);
42464
43031
  }
@@ -42467,12 +43034,12 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42467
43034
  if (floatValue !== row[col.field]) {
42468
43035
  row[col.field] = !isNaN(floatValue) ? floatValue : 0;
42469
43036
  if (col.callback) {
42470
- col.callback(row[col.field], indexRow);
43037
+ col.callback(row[col.field], indexRow, row);
42471
43038
  }
42472
43039
  handleDataChange(row, col, indexRow);
42473
43040
  }
42474
43041
  }
42475
- checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
43042
+ checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1);
42476
43043
  }, onPaste: (e) => {
42477
43044
  if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
42478
43045
  pasteDataFromExcel(indexRow, indexCol, e);
@@ -42484,19 +43051,19 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42484
43051
  if (row[col.field] != val.target?.value) {
42485
43052
  row[col.field] = val.target?.value;
42486
43053
  if (col.callback) {
42487
- col.callback(val.target.value, indexRow);
43054
+ col.callback(val.target.value, indexRow, row);
42488
43055
  }
42489
43056
  handleDataChange(row, col, indexRow);
42490
43057
  }
42491
43058
  }, onKeyDown: (val) => {
42492
- checkKeyDown(val, row, col, indexRow + 1, indexCol + 1);
43059
+ checkKeyDown(val, row, parents, indexRow + 1, indexCol + 1);
42493
43060
  } }, `col-${indexRow}-${indexCol}`) }));
42494
43061
  case 'form':
42495
- return (jsxRuntime.jsx(EditForm, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, ...col.formSettings, field: col.field, displayValue: col.formSettings?.displayValue ? col.formSettings?.displayValue(row) : '', placeholder: col.placeholder ? t(col.placeholder) : '', rowData: row, indexRow: indexRow, onChange: (val) => {
43062
+ return (jsxRuntime.jsx(EditForm, { id: idElement, ...col.formSettings, field: col.field, displayValue: col.formSettings?.displayValue ? col.formSettings?.displayValue(row) : '', placeholder: col.placeholder ? t(col.placeholder) : '', rowData: row, indexRow: indexRow, onChange: (val) => {
42496
43063
  row = { ...row, ...val };
42497
43064
  handleDataChange(row, col, indexRow);
42498
43065
  }, invalid: col.validate && col.validate(row[col.field], row), textAlign: col.textAlign, onKeyDown: (e) => {
42499
- return checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
43066
+ return checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1);
42500
43067
  }, onPaste: (e) => {
42501
43068
  if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
42502
43069
  pasteDataFromExcel(indexRow, indexCol, e);
@@ -42504,16 +43071,16 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42504
43071
  }
42505
43072
  } }));
42506
43073
  default:
42507
- return (jsxRuntime.jsx(Input$1, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, style: { textAlign: col.textAlign, height: 29 }, value: isNullOrUndefined$1(row[col.field]) ? '' : row[col.field], className: classnames('border-0 rounded-0 input-element', { 'is-invalid': col.validate && col.validate(row[col.field], row) }), onChange: (val) => {
43074
+ return (jsxRuntime.jsx(Input$1, { id: idElement, style: { textAlign: col.textAlign, height: 29 }, value: isNullOrUndefined$1(row[col.field]) ? '' : row[col.field], className: classnames('border-0 rounded-0 input-element', { 'is-invalid': col.validate && col.validate(row[col.field], row) }), onChange: (val) => {
42508
43075
  if (row[col.field] != val.target?.value) {
42509
43076
  row[col.field] = val.target?.value;
42510
43077
  if (col.callback) {
42511
- col.callback(val.target.value, indexRow);
43078
+ col.callback(val.target.value, indexRow, row);
42512
43079
  }
42513
43080
  handleDataChange(row, col, indexRow);
42514
43081
  }
42515
43082
  }, onKeyDown: (e) => {
42516
- checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
43083
+ checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1);
42517
43084
  }, onPaste: (e) => {
42518
43085
  if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
42519
43086
  pasteDataFromExcel(indexRow, indexCol, e);
@@ -42528,9 +43095,14 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42528
43095
  }
42529
43096
  };
42530
43097
  // focus vào dòng mới
42531
- const focusNewElement = (col, row, onLoad = false) => {
43098
+ const focusNewElement = (col, parents, row, onLoad = false) => {
43099
+ let indexRow = row;
43100
+ if (indexRow === undefined) {
43101
+ indexRow = (parents.length > 0 ? parseInt(parents.split('-').pop() ?? '0') : 0) + 1;
43102
+ parents = parents.split('-').slice(0, -1).join('-');
43103
+ }
42532
43104
  setTimeout(() => {
42533
- const element = document.getElementById(`${idTable}-col${col}-row${row}`);
43105
+ const element = document.getElementById(`${idTable}-col${col}-row${getNewParents(parents, indexRow)}`);
42534
43106
  if (element) {
42535
43107
  if (element.className.includes('react-select') || element.className.includes('form-edit')) {
42536
43108
  element.getElementsByTagName('input')[0]?.focus();
@@ -42538,459 +43110,98 @@ const TableEdit = React$5.forwardRef((props, ref) => {
42538
43110
  else {
42539
43111
  element.focus();
42540
43112
  }
42541
- if (!onLoad) {
42542
- if (tableElement.current) {
42543
- const parentRect = tableElement.current.getBoundingClientRect();
42544
- const childRect = element.getBoundingClientRect();
42545
- const offset = childRect.left - parentRect.left + tableElement.current.scrollLeft - (parentRect.width / 2) + (childRect.width / 2);
42546
- tableElement.current.scrollTo({ left: offset, behavior: 'smooth' });
42547
- }
42548
- }
42549
- if ((tableElement.current?.scrollHeight ?? 0) > 0) {
42550
- if ((tableElement.current?.scrollTop ?? 0) > ((row - 1) % (pagingSetting?.pageSize ?? 1)) * 34) {
42551
- tableElement.current?.scrollTo({ behavior: 'smooth', top: ((row - 1) % (pagingSetting?.pageSize ?? 1)) * 34 });
43113
+ if (isTree) {
43114
+ if (!onLoad) {
43115
+ if (tableElement.current) {
43116
+ const parentRect = tableElement.current.getBoundingClientRect();
43117
+ const childRect = element.getBoundingClientRect();
43118
+ const offset = childRect.left - parentRect.left + tableElement.current.scrollLeft - (parentRect.width / 2) + (childRect.width / 2);
43119
+ tableElement.current.scrollTo({ left: offset, behavior: 'smooth' });
43120
+ }
42552
43121
  }
42553
- else if (((tableElement.current?.clientHeight ?? 0) - (haveSum ? 30 : 0) - (headerColumns.length * 42)) < (((row % (pagingSetting?.pageSize ?? 1)) * 34) - (tableElement.current?.scrollTop ?? 0))) {
42554
- tableElement.current?.scrollTo({ behavior: 'smooth', top: (tableElement.current?.scrollTop ?? 0) + 34 });
43122
+ if ((tableElement.current?.scrollHeight ?? 0) > 0) {
43123
+ if ((tableElement.current?.scrollTop ?? 0) > ((indexRow - 1) % (pagingSetting?.pageSize ?? 1)) * 34) {
43124
+ tableElement.current?.scrollTo({ behavior: 'smooth', top: ((indexRow - 1) % (pagingSetting?.pageSize ?? 1)) * 34 });
43125
+ }
43126
+ else if (((tableElement.current?.clientHeight ?? 0) - (haveSum ? 30 : 0) - (headerColumns.length * 42)) < (((indexRow % (pagingSetting?.pageSize ?? 1)) * 34) - (tableElement.current?.scrollTop ?? 0))) {
43127
+ tableElement.current?.scrollTo({ behavior: 'smooth', top: (tableElement.current?.scrollTop ?? 0) + 34 });
43128
+ }
42555
43129
  }
42556
43130
  }
42557
43131
  }
42558
43132
  }, onLoad ? 100 : 0);
42559
43133
  };
42560
- //Thêm dòng mới
43134
+ //cần sửa
42561
43135
  const moveIndexRowToNewPage = () => {
42562
43136
  changeDataSource(dataSource, true);
42563
43137
  if (pagingClient && pagingSetting?.setCurrentPage && (totalCount % (pagingSetting?.pageSize ?? 0)) === 0) {
42564
43138
  pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 0) + 1);
42565
43139
  }
42566
43140
  if (tableElement) {
42567
- setIndexFocus(totalCount);
42568
- focusNewElement(columnFistEdit, totalCount + 1, true);
43141
+ setItemFocus(`${totalCount}`);
43142
+ focusNewElement(columnFistEdit, '', totalCount + 1, true);
42569
43143
  }
42570
43144
  };
42571
- const checkKeyDown = (e, row, col, indexRow, indexCol) => {
42572
- if (e.code === 'ArrowRight') {
42573
- let newIndexCol = -1;
42574
- for (let i = indexCol; i < contentColumns.length; i++) {
42575
- if (contentColumns[i].editEnable && (contentColumns[i].visible !== false) && (!contentColumns[i].disabledCondition?.(row))) {
42576
- newIndexCol = i + 1;
42577
- break;
42578
- }
42579
- }
42580
- if (newIndexCol > -1) {
42581
- focusNewElement(newIndexCol, indexRow);
42582
- e.preventDefault();
42583
- return e.code;
42584
- }
42585
- }
42586
- else if (e.code === 'ArrowLeft') {
42587
- let newIndexCol = -1;
42588
- for (let i = indexCol - 2; i >= 0; i--) {
42589
- if (contentColumns[i].editEnable && (contentColumns[i].visible !== false) && (!contentColumns[i].disabledCondition?.(row))) {
42590
- newIndexCol = i + 1;
42591
- break;
42592
- }
42593
- }
42594
- if (newIndexCol > -1) {
42595
- focusNewElement(newIndexCol, indexRow);
42596
- e.preventDefault();
42597
- return e.code;
42598
- }
42599
- }
42600
- else if (e.code === 'ArrowUp') {
42601
- const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
42602
- if (element && !(element.getElementsByClassName('select__control--menu-is-open').length > 0 ||
42603
- element.getElementsByClassName('select-100__control--menu-is-open').length > 0 ||
42604
- element.getElementsByClassName('select-200__control--menu-is-open').length > 0 ||
42605
- element.getElementsByClassName('select-300__control--menu-is-open').length > 0 ||
42606
- element.getElementsByClassName('select-400__control--menu-is-open').length > 0 ||
42607
- element.getElementsByClassName('select-500__control--menu-is-open').length > 0)) {
42608
- if (indexRow > 1) {
42609
- if (pagingClient && (pagingSetting?.currentPage ?? 0) !== 1 && (indexRow % (pagingSetting?.pageSize ?? 0)) === 1 && pagingSetting?.setCurrentPage) {
42610
- pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) - 1);
42611
- }
42612
- setIndexFocus(indexRow - 2);
42613
- focusNewElement(indexCol, indexRow - 1, true);
42614
- e.preventDefault();
42615
- return e.code;
42616
- }
42617
- }
42618
- }
42619
- else if (e.code === 'ArrowDown') {
42620
- const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
42621
- if (element && !(element.getElementsByClassName('select__control--menu-is-open').length > 0 ||
42622
- element.getElementsByClassName('select-100__control--menu-is-open').length > 0 ||
42623
- element.getElementsByClassName('select-200__control--menu-is-open').length > 0 ||
42624
- element.getElementsByClassName('select-300__control--menu-is-open').length > 0 ||
42625
- element.getElementsByClassName('select-400__control--menu-is-open').length > 0 ||
42626
- element.getElementsByClassName('select-500__control--menu-is-open').length > 0)) {
42627
- if (indexRow < totalCount) {
42628
- if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42629
- pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42630
- }
42631
- setIndexFocus(indexRow);
42632
- focusNewElement(indexCol, indexRow + 1, true);
42633
- e.preventDefault();
42634
- return e.code;
42635
- }
42636
- }
42637
- }
42638
- else if (e.code === 'Tab' && indexCol === columnLastEdit) {
42639
- if (indexRow === totalCount) {
42640
- moveIndexRowToNewPage();
42641
- }
42642
- else {
42643
- if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42644
- pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42645
- }
42646
- setIndexFocus(indexRow);
42647
- focusNewElement(indexCol, indexRow + 1, true);
42648
- }
42649
- e.preventDefault();
42650
- return e.code;
42651
- }
42652
- else if ((e.code === 'Enter' || e.code === 'NumpadEnter') && (!editDisable && !addDisable)) {
42653
- const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
42654
- if (element && !(element.getElementsByClassName('select__control--menu-is-open').length > 0 ||
42655
- element.getElementsByClassName('select-100__control--menu-is-open').length > 0 ||
42656
- element.getElementsByClassName('select-200__control--menu-is-open').length > 0 ||
42657
- element.getElementsByClassName('select-300__control--menu-is-open').length > 0 ||
42658
- element.getElementsByClassName('select-400__control--menu-is-open').length > 0 ||
42659
- element.getElementsByClassName('select-500__control--menu-is-open').length > 0)) {
42660
- if (indexRow === totalCount) {
42661
- moveIndexRowToNewPage();
42662
- }
42663
- else {
42664
- if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42665
- pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42666
- }
42667
- setIndexFocus(indexRow);
42668
- focusNewElement(indexCol, indexRow + 1, true);
42669
- }
42670
- e.preventDefault();
42671
- return e.code;
42672
- }
42673
- }
42674
- else if (e.code === 'KeyD' && e.ctrlKey == true && (!editDisable && !addDisable)) {
42675
- handleDuplicate(dataSource[indexFocus ?? -1], indexRow);
42676
- e.preventDefault();
42677
- return e.code;
42678
- }
42679
- return '';
42680
- };
42681
- const onChangePage = (args) => {
42682
- if (pagingSetting?.setCurrentPage) {
42683
- if (args.currentPage === args.oldPage) {
42684
- return;
42685
- }
42686
- pagingSetting.setCurrentPage(args.currentPage);
42687
- }
42688
- };
42689
- const onChangePageSize = (args) => {
42690
- if (pagingSetting?.allowPaging) {
42691
- if (pagingSetting?.pageSize !== args.pageSize) {
42692
- if (pagingSetting?.setPageSize) {
42693
- pagingSetting.setPageSize(args.pageSize);
42694
- }
42695
- if (pagingSetting?.setCurrentPage) {
42696
- pagingSetting.setCurrentPage(1);
42697
- }
42698
- }
42699
- }
42700
- };
42701
- useOnClickOutside(gridRef, () => {
42702
- setTimeout(() => {
42703
- setIndexFocus(-1);
42704
- }, 50);
42705
- });
42706
- const handleAdd = () => {
42707
- const lengthData = dataSource.length;
42708
- changeDataSource(dataSource, true);
42709
- if (pagingSetting?.setCurrentPage) {
42710
- pagingSetting?.setCurrentPage(Math.floor(lengthData / (pagingSetting?.pageSize ?? 0)) + 1);
42711
- }
42712
- if (tableElement) {
42713
- setIndexFocus(lengthData);
42714
- focusNewElement(columnFistEdit, lengthData + 1, true);
42715
- }
42716
- };
42717
- const handleDuplicate = async (data, index) => {
42718
- const newData = { ...data };
42719
- if (toolbarSetting?.showBottomToolbar && !buttonSetting?.duplicateDisable && !editDisable && !addDisable) {
42720
- if (fieldKey && defaultValue) {
42721
- fieldUniKey.forEach((item) => {
42722
- newData[item] = defaultValue[item];
42723
- });
42724
- newData[fieldKey] = defaultValue[fieldKey];
42725
- }
42726
- if (onDuplicate) {
42727
- await onDuplicate(newData, index);
42728
- }
42729
- if (pagingClient) {
42730
- dataSource.splice((((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + index) + 1, 0, newData);
42731
- }
42732
- else {
42733
- dataSource.splice(index + 1, 0, newData);
42734
- }
42735
- changeDataSource(dataSource);
42736
- if (tableElement && index === totalCount) {
42737
- setTimeout(() => {
42738
- tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
42739
- }, 100);
42740
- }
42741
- }
42742
- };
42743
- const handleInsertAfter = () => {
42744
- if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertAfterDisable && !editDisable && !addDisable) {
42745
- if (pagingClient) {
42746
- dataSource.splice((((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + (indexFocus ?? -1) + 1), 0, { ...{ ...defaultValue } });
42747
- }
42748
- else {
42749
- dataSource.splice((indexFocus ?? -1) + 1, 0, { ...defaultValue });
42750
- }
42751
- changeDataSource(dataSource);
42752
- if (tableElement && indexFocus === totalCount) {
42753
- setTimeout(() => {
42754
- tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
42755
- }, 100);
42756
- }
42757
- }
42758
- };
42759
- const handleInsertBefore = () => {
42760
- if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertBeforeDisable && !editDisable && !addDisable) {
42761
- if (pagingClient) {
42762
- dataSource.splice((((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + (indexFocus ?? -1)), 0, { ...{ ...defaultValue } });
42763
- }
42764
- else {
42765
- dataSource.splice((indexFocus ?? -1), 0, { ...defaultValue });
42766
- }
42767
- changeDataSource(dataSource);
42768
- }
42769
- };
42770
- const handleDeleteAll = () => {
42771
- if (toolbarSetting?.showBottomToolbar && !buttonSetting?.deleteAllDisable && !editDisable && !addDisable) {
42772
- messageBoxConfirmDelete(t, deleteAll, '');
42773
- }
42774
- };
42775
- const deleteAll = () => {
42776
- if (!editDisable && !addDisable) {
42777
- setIndexFocus(-1);
42778
- changeDataSource([], false);
42779
- }
42780
- };
42781
- const getColumn = (col, index) => {
42782
- const column = contentColumns.filter(e => e.visible !== false)[col + index];
42783
- if (column) {
42784
- return { ...column };
42785
- }
42786
- return undefined;
43145
+ const checkKeyDown = (e, row, parents, indexRow, indexCol) => {
43146
+ const idElement = `${idTable}-col${indexCol}-row${getNewParents(parents, indexRow)}`;
43147
+ const params = {
43148
+ columnLastEdit,
43149
+ contentColumns,
43150
+ dataSource,
43151
+ addDisable,
43152
+ editDisable,
43153
+ focusNewElement,
43154
+ getNewParents,
43155
+ handleDuplicate: () => handleDuplicate(dataSource, itemFocus, fieldKey, defaultValue, fieldUniKey, changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate),
43156
+ idElement,
43157
+ indexCol,
43158
+ indexRow,
43159
+ itemFocus,
43160
+ moveIndexRowToNewPage,
43161
+ pagingClient,
43162
+ pagingSetting,
43163
+ parents,
43164
+ row,
43165
+ setItemFocus,
43166
+ totalCount,
43167
+ fieldChildren
43168
+ };
43169
+ const handlers = {
43170
+ ArrowRight: () => handleArrowRight(e, params),
43171
+ ArrowLeft: () => handleArrowLeft(e, params),
43172
+ ArrowUp: () => handleArrowUp(e, params),
43173
+ ArrowDown: () => handleArrowDown(e, params),
43174
+ Tab: () => handleTab(e, params),
43175
+ Enter: () => handleEnter(e, params),
43176
+ NumpadEnter: () => handleEnter(e, params),
43177
+ KeyD: () => (e.ctrlKey ? handleCtrlD(e, params) : undefined)
43178
+ };
43179
+ return handlers[e.code]?.() || "";
42787
43180
  };
42788
- const pasteDataFromExcel = async (currenRowIndex, col, e) => {
42789
- const clipboard = (e.clipboardData || window.Clipboard).getData('text');
42790
- const rowsClipboard = clipboard.trimEnd().split('\n');
42791
- setIndexFocus(undefined);
42792
- if (rowsClipboard.length > 200) {
42793
- messageBoxError(t, 'You can only paste up to 200 rows.');
42794
- }
42795
- if (rowsClipboard.length > 0) {
42796
- const columnsDataChange = [];
42797
- for (let index = 0; index < rowsClipboard[0].trimEnd().split('\t').length; index++) {
42798
- const stringData = [];
42799
- rowsClipboard.forEach((element) => {
42800
- if (element.trimEnd().split('\t')[index] && !stringData.includes(element.trimEnd().split('\t')[index].toString().trim())) {
42801
- stringData.push(element.trimEnd().split('\t')[index].toString().trim());
42802
- }
42803
- });
42804
- const column = getColumn(col, index);
42805
- if (column) {
42806
- if ((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + 0])) && column.editEnable && column.onPasteValidate) {
42807
- const rs = await column.onPasteValidate(stringData.join(','), currenRowIndex + 0, dataSource[currenRowIndex + 0]);
42808
- if (rs) {
42809
- column.resultValidate = rs;
42810
- }
42811
- }
42812
- columnsDataChange.push(column);
42813
- }
42814
- }
42815
- for (let indexRow = 0; indexRow < rowsClipboard.length; indexRow++) {
42816
- const item = rowsClipboard[indexRow];
42817
- const colsClipboard = item.trimEnd().split('\t');
42818
- let dataRow = dataSource[currenRowIndex + indexRow];
42819
- if (!dataRow) {
42820
- dataRow = { ...defaultValue };
42821
- dataSource.push(dataRow);
42822
- }
42823
- for (let index = 0; index < colsClipboard.length; index++) {
42824
- const stringData = colsClipboard[index].toString().trim();
42825
- const column = columnsDataChange[index];
42826
- if (column) {
42827
- if (((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + indexRow])) && column.editEnable) || column.onPaste) {
42828
- if (column.onPasteValidate && column.resultValidate) {
42829
- const rs = column.resultValidate.find((item) => item[column.selectSettings?.fieldValue ?? 'value'] === stringData);
42830
- if (rs) {
42831
- if (column.onPaste) {
42832
- dataRow[column.field] = column.onPaste(dataRow, stringData);
42833
- }
42834
- else {
42835
- dataRow[column.field] = stringData;
42836
- }
42837
- if (column.callback) {
42838
- column.callback(rs, currenRowIndex + indexRow);
42839
- }
42840
- }
42841
- else {
42842
- notificationError(t('PasteExcelNotExist', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42843
- }
42844
- }
42845
- else {
42846
- if (column.editType === 'date') {
42847
- const date = new Date(stringData);
42848
- if (!isNaN(date.getTime())) {
42849
- if (column.onPaste) {
42850
- dataRow[column.field] = column.onPaste(dataRow, date);
42851
- }
42852
- else {
42853
- dataRow[column.field] = date;
42854
- }
42855
- if (column.callback) {
42856
- column.callback(date, currenRowIndex + indexRow);
42857
- }
42858
- }
42859
- else {
42860
- notificationError(t('PasteExcelIncorrectFormat', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42861
- }
42862
- }
42863
- else if (column.editType === 'numeric') {
42864
- const number = Number(stringData);
42865
- if (!isNaN(number)) {
42866
- if (column.onPaste) {
42867
- dataRow[column.field] = column.onPaste(dataRow, number);
42868
- }
42869
- else {
42870
- dataRow[column.field] = number;
42871
- }
42872
- if (column.callback) {
42873
- column.callback(number, currenRowIndex + indexRow);
42874
- }
42875
- }
42876
- else {
42877
- notificationError(t('PasteExcelIncorrectFormat', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42878
- }
42879
- }
42880
- else if (column.editType === 'select') {
42881
- const rs = ((column.selectSettings?.optionsField ? item[column.selectSettings?.optionsField] : column.selectSettings?.options) ?? []).find((item) => item[column.selectSettings?.fieldValue ?? 'value'] === stringData);
42882
- if (rs) {
42883
- if (column.onPaste) {
42884
- dataRow[column.field] = column.onPaste(dataRow, stringData);
42885
- }
42886
- else {
42887
- dataRow[column.field] = stringData;
42888
- }
42889
- if (column.callback) {
42890
- column.callback(rs, currenRowIndex + indexRow);
42891
- }
42892
- }
42893
- else {
42894
- notificationError(t('PasteExcelNotExist', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42895
- }
42896
- }
42897
- else {
42898
- if (column.onPaste) {
42899
- column.onPaste(dataRow, stringData);
42900
- }
42901
- else {
42902
- dataRow[column.field] = stringData;
42903
- }
42904
- if (column.callback) {
42905
- column.callback(stringData, currenRowIndex + indexRow);
42906
- }
42907
- }
42908
- }
42909
- }
42910
- }
42911
- }
42912
- if (rowChange) {
42913
- rowChange(dataRow, currenRowIndex + indexRow, '');
42914
- }
42915
- }
43181
+ const checkSearch = (keyword, data, fieldKey) => {
43182
+ if (!keyword || fieldKey.length === 0) {
43183
+ return true;
42916
43184
  }
42917
- changeDataSource(dataSource);
42918
- };
42919
- const changeDataSource = (data, haveNew = false) => {
42920
- if (!editDisable && setDataSource) {
42921
- if ((searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm)) {
42922
- if (searchSetting?.setSearchTerm) {
42923
- searchSetting?.setSearchTerm('');
42924
- }
42925
- else {
42926
- setSearchTerm('');
42927
- }
42928
- }
42929
- if (haveNew && !addDisable) {
42930
- data.push(defaultValue ? { ...defaultValue, [fieldKey]: disableAutoKey ? undefined : generateUUID() } : {});
42931
- setDataSource([...data]);
42932
- }
42933
- else {
42934
- setDataSource([...data]);
43185
+ for (let index = 0; index < fieldKey.length; index++) {
43186
+ const key = fieldKey[index].trim();
43187
+ if (data[key] && data[key].toString().trim().toLowerCase().includes(keyword.trim().toLowerCase())) {
43188
+ return true;
42935
43189
  }
42936
43190
  }
43191
+ return false;
42937
43192
  };
42938
- React$5.useEffect(() => {
42939
- setIndexFocus(-1);
42940
- if (setSelectedItem) {
42941
- if (isMulti) {
42942
- if (dataSource && selectedRows && selectedRows?.length !== selectedItem?.length) {
42943
- setSelectedItem([...selectedRows]);
42944
- if (handleSelect) {
42945
- handleSelect([...selectedRows]);
42946
- }
42947
- }
42948
- }
42949
- else {
42950
- if (dataSource && selectedRows?.length > 0) {
42951
- if ((!selectedItem || (selectedItem[fieldKey] !== selectedRows[0][fieldKey]))) {
42952
- setSelectedItem({ ...selectedRows[0] });
42953
- if (handleSelect) {
42954
- handleSelect({ ...selectedRows[0] });
42955
- }
42956
- }
42957
- }
42958
- else {
42959
- setSelectedItem(undefined);
42960
- if (handleSelect) {
42961
- handleSelect(undefined);
42962
- }
42963
- }
42964
- }
42965
- }
42966
- }, [selectedRows]);
42967
- React$5.useEffect(() => {
42968
- if (!isMulti) {
42969
- if (dataSource && selectedItem && selectedItem[fieldKey]) {
42970
- if (selectedRows?.length === 0 || selectedItem[fieldKey] !== selectedRows[0][fieldKey]) {
42971
- setSelectedRows([selectedItem]);
42972
- }
42973
- }
42974
- else {
42975
- setSelectedRows([]);
42976
- }
42977
- }
42978
- else {
42979
- if (dataSource && selectedItem && selectedRows?.length !== selectedItem.length) {
42980
- setSelectedRows(selectedItem ? [...selectedItem] : []);
42981
- }
42982
- }
42983
- }, [selectedItem]);
42984
- const renderContentCol = (col, row, indexRow, indexCol, isSelected) => {
43193
+ const renderContentCol = (col, row, indexRow, indexCol, parents, isSelected) => {
43194
+ const currentItem = getNewParents(parents, indexRow);
43195
+ const level = parents ? parents.split('-').length : 0;
42985
43196
  if (col.field === 'command') {
42986
- return (col.visible !== false && jsxRuntime.jsx("td", { className: classnames(`r-rowcell p-0 fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || indexFocus === indexRow }), style: {
43197
+ return (col.visible !== false && jsxRuntime.jsx("td", { className: classnames(`r-rowcell p-0 fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || itemFocus === currentItem }), style: {
42987
43198
  left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
42988
43199
  right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
42989
43200
  textAlign: col.textAlign ? col.textAlign : 'left',
42990
- }, children: jsxRuntime.jsx("div", { className: "r-rowcell-div command", children: jsxRuntime.jsx(CommandElement, { commandItems: col.commandItems ?? [], handleCommandClick: handleCommandClick, indexRow: indexRow, rowData: row, setIndexFocus: setIndexFocus, indexFocus: indexFocus }) }) }, `col-${indexRow}-${indexCol}`));
43201
+ }, children: jsxRuntime.jsx("div", { className: "r-rowcell-div command", children: jsxRuntime.jsx(CommandElement, { commandItems: col.commandItems ?? [], handleCommandClick: handleCommandClick, indexRow: indexRow, rowData: row, currentItem: currentItem, setItemFocus: setItemFocus, itemFocus: itemFocus }) }) }, `col-${indexRow}-${indexCol}`));
42991
43202
  }
42992
43203
  else if (col.field === '#') {
42993
- return (col.visible !== false && jsxRuntime.jsx("td", { className: classnames(`r-rowcell p-0 cursor-pointer fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || indexFocus === indexRow }), tabIndex: Number(`${indexRow}${indexCol}`), style: {
43204
+ return (col.visible !== false && jsxRuntime.jsx("td", { className: classnames(`r-rowcell p-0 cursor-pointer fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || itemFocus === currentItem }), tabIndex: Number(`${indexRow}${indexCol}`), style: {
42994
43205
  left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
42995
43206
  right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
42996
43207
  textAlign: 'center',
@@ -43014,21 +43225,31 @@ const TableEdit = React$5.forwardRef((props, ref) => {
43014
43225
  }
43015
43226
  }, onClick: (e) => {
43016
43227
  if (e.target.nodeName === 'DIV' || e.target.nodeName === 'TD') {
43017
- if (!editDisable && indexRow != indexFocus) {
43018
- setIndexFocus(indexRow);
43228
+ if (!editDisable && itemFocus !== currentItem) {
43229
+ setItemFocus(currentItem);
43019
43230
  }
43020
43231
  e.stopPropagation();
43021
43232
  }
43022
43233
  }, onKeyDown: (e) => {
43023
43234
  if (e.code === 'KeyD' && e.ctrlKey == true && (!editDisable && !addDisable) && (e.target.nodeName === 'DIV' || e.target.nodeName === 'TD')) {
43024
- handleDuplicate(row, indexRow);
43235
+ handleDuplicate(dataSource, itemFocus, fieldKey, defaultValue, fieldUniKey, changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate);
43025
43236
  e.preventDefault();
43026
43237
  e.stopPropagation();
43027
43238
  }
43028
- }, children: jsxRuntime.jsx("div", { className: "r-rowcell-div", children: indexRow + 1 }) }, `col-${indexRow}-${indexCol}`));
43239
+ }, children: jsxRuntime.jsxs("div", { className: "r-rowcell-div", style: { paddingLeft: level * 10 }, children: [isTree && row[fieldChildren ?? 'children']?.length > 0 &&
43240
+ jsxRuntime.jsx(SvgChevronRight, { onClick: (e) => {
43241
+ if (row.expanded) {
43242
+ row.expanded = false;
43243
+ }
43244
+ else {
43245
+ row.expanded = true;
43246
+ }
43247
+ handleDataChange(row, col, indexRow);
43248
+ e.stopPropagation();
43249
+ }, fontSize: 18, className: classnames('r-icon-expand', { 'is-open': row.expanded }) }), indexRow + 1] }) }, `col-${indexRow}-${indexCol}`));
43029
43250
  }
43030
43251
  else if (col.field === 'checkbox') {
43031
- return (jsxRuntime.jsx("td", { className: classnames(`r-rowcell p-0 fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || indexFocus === indexRow }), style: {
43252
+ return (jsxRuntime.jsx("td", { className: classnames(`r-rowcell p-0 fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || itemFocus === currentItem }), style: {
43032
43253
  left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
43033
43254
  right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
43034
43255
  textAlign: col.textAlign ? col.textAlign : 'center',
@@ -43067,18 +43288,18 @@ const TableEdit = React$5.forwardRef((props, ref) => {
43067
43288
  else if (col.editType === 'datetime') {
43068
43289
  value = value ? formatDateTime(value, formatSetting?.dateFormat ?? 'DD/MM/yyyy HH:mm') : '';
43069
43290
  }
43070
- const typeDis = !editDisable && (indexFocus === indexRow || col.editType === 'checkbox') && (!col.disabledCondition || !col.disabledCondition(row)) ? (col.editEnable ? 1 : (col.template ? 2 : 3)) : (col.template ? 2 : 3);
43291
+ const typeDis = !editDisable && (itemFocus === currentItem || col.editType === 'checkbox') && (!col.disabledCondition || !col.disabledCondition(row)) ? (col.editEnable ? 1 : (col.template ? 2 : 3)) : (col.template ? 2 : 3);
43071
43292
  const errorMessage = typeDis === 1 || col.field === '' || !col.validate ? '' : col.validate(row[col.field], row);
43072
- return (jsxRuntime.jsx(React$5.Fragment, { children: col.visible !== false && jsxRuntime.jsx("td", { className: classnames(`r-rowcell fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || indexFocus === indexRow }), style: {
43293
+ return (jsxRuntime.jsx(React$5.Fragment, { children: col.visible !== false && jsxRuntime.jsx("td", { className: classnames(`r-rowcell fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || itemFocus === currentItem }), style: {
43073
43294
  left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
43074
43295
  right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
43075
43296
  padding: 0,
43076
43297
  textAlign: col.textAlign ? col.textAlign : 'left'
43077
43298
  }, onClick: (e) => {
43078
43299
  if (e.target.nodeName === 'DIV' || e.target.nodeName === 'TD') {
43079
- if (!editDisable && indexRow != indexFocus) {
43080
- setIndexFocus(indexRow);
43081
- focusNewElement(indexCol + 1, indexRow + 1, true);
43300
+ if (!editDisable && itemFocus !== currentItem) {
43301
+ setItemFocus(currentItem);
43302
+ focusNewElement(indexCol + 1, parents, indexRow + 1, true);
43082
43303
  }
43083
43304
  if (selectEnable && editDisable) {
43084
43305
  const index = selectedRows?.findIndex((x) => x[fieldKey] === row[fieldKey]);
@@ -43102,73 +43323,47 @@ const TableEdit = React$5.forwardRef((props, ref) => {
43102
43323
  }
43103
43324
  e.stopPropagation();
43104
43325
  }
43105
- }, children: jsxRuntime.jsx("div", { className: classnames('r-rowcell-div'), children: jsxRuntime.jsxs("div", { id: indexFocus === indexRow && typeDis !== 1 ? `${idTable}-col${indexCol + 1}-row${indexRow + 1}` : '', className: classnames('r-rowcell-content', { 'r-is-invalid': errorMessage }), style: {
43326
+ }, children: jsxRuntime.jsx("div", { className: classnames('r-rowcell-div'), children: jsxRuntime.jsxs("div", { id: itemFocus === currentItem && typeDis !== 1 ? `${idTable}-col${indexCol + 1}-row${indexRow + 1}` : '', className: classnames('r-rowcell-content', { 'r-is-invalid': errorMessage }), style: {
43106
43327
  margin: typeDis === 1 ? 2 : !errorMessage ? '7px 9px' : 2
43107
- }, children: [typeDis === 1 && !refreshRow ? RenderEdit(row, col, indexCol, indexRow) : jsxRuntime.jsx("div", { id: `content-${idTable}-row${indexRow}col-${indexCol}`, className: "r-cell-text", children: typeDis === 2 ? (col.template && col.template(row, indexRow)) ?? '' : (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxRuntime.jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsxRuntime.jsx("span", { id: `error-${indexRow}-${indexCol}`, className: classnames('cursor-pointer text-primary icon-table', { 'd-none': !errorMessage }), children: jsxRuntime.jsx(SvgAlertCircle, { fontSize: 15.5 }) }), (!(typeDis === 1 && !refreshRow)) && jsxRuntime.jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `content-${idTable}-row${indexRow}col-${indexCol}`, children: typeDis === 2 ? (col.template && col.template(row, indexRow)) ?? '' : (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxRuntime.jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsxRuntime.jsx(UncontrolledTooltip, { target: `error-${indexRow}-${indexCol}`, className: "r-tooltip tooltip-error", children: errorMessage?.toString() ?? '' })] }) }) }, `col-${indexRow}-${indexCol}`) }, indexCol));
43108
- }
43109
- };
43110
- const renderFooterCol = (col, indexCol) => {
43111
- const sumValue = (col.haveSum === true && col.editType === "numeric") ? dataSource.reduce(function (accumulator, currentValue) { return (Number(accumulator ?? 0) + Number(currentValue[col.field] ?? 0)); }, 0) : 0;
43112
- return (jsxRuntime.jsx(React$5.Fragment, { children: (col.visible !== false) && jsxRuntime.jsx("td", { className: classnames(`p-0 px-50 r-footer fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }), style: {
43113
- left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
43114
- right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
43115
- textAlign: col.textAlign ? col.textAlign : 'left'
43116
- }, 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}`));
43117
- };
43118
- const renderToolbarBottom = () => {
43119
- return (jsxRuntime.jsx("div", { id: "table_custom_bottom_toolbar", className: "r-toolbar r-toolbar-bottom", role: "toolbar", "aria-disabled": "false", "aria-haspopup": "false", "aria-orientation": "horizontal", children: jsxRuntime.jsxs("div", { className: "r-toolbar-items", children: [jsxRuntime.jsxs("div", { className: "r-toolbar-left", children: [jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable }), "aria-disabled": "false", children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: handleAdd, className: 'd-flex', children: t('Add item') }) }), (indexFocus ?? -1) > -1 ? jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.duplicateDisable }), "aria-disabled": "false", children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: () => { handleDuplicate(dataSource[indexFocus ?? -1], indexFocus ?? -1); }, className: 'd-flex', children: t('Duplicate') }) }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.insertBeforeDisable }), "aria-disabled": "false", children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: handleInsertBefore, className: 'd-flex', children: t('Insert item before') }) }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.insertAfterDisable }), "aria-disabled": "false", children: jsxRuntime.jsx(Button$1, { color: 'success', outline: true, onClick: handleInsertAfter, className: 'd-flex', children: t('Insert item after') }) })] }) : jsxRuntime.jsx(jsxRuntime.Fragment, { children: " " }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || buttonSetting?.deleteAllDisable }), "aria-disabled": "false", children: jsxRuntime.jsx(Button$1, { color: 'primary', outline: true, onClick: handleDeleteAll, className: 'd-flex', children: t('Delete all item') }) }), toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
43120
- return ((item.align === 'left') ?
43121
- jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-left-${index}`) : '');
43122
- })] }), jsxRuntime.jsx("div", { className: "r-toolbar-center", children: toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
43123
- return ((item.align === 'center') ?
43124
- jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-center-${index}`) : '');
43125
- }) }), jsxRuntime.jsxs("div", { className: "r-toolbar-right", children: [toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
43126
- return ((item.align === 'right') ?
43127
- jsxRuntime.jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-right-${index}`) : '');
43128
- }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item me-25', { 'd-none': headerColumns.length > 1 }), "aria-disabled": "false", children: jsxRuntime.jsx(SvgSettings, { className: "text-primary cursor-pointer", onClick: () => setOpenPopupSetupColumn(true) }) }), jsxRuntime.jsx("div", { className: classnames('r-toolbar-item me-25', { 'd-none': editDisable || addDisable }), "aria-disabled": "false", children: jsxRuntime.jsxs(UncontrolledDropdown, { className: 'dropdown-user nav-item', children: [jsxRuntime.jsx(DropdownToggle$1, { tag: 'div', color: "primary", onClick: (e) => e.preventDefault(), children: jsxRuntime.jsx(SvgInfo, { className: "cursor-pointer text-primary" }) }), jsxRuntime.jsx(DropdownMenu$1, { className: 'formula-dropdown icon-dropdown', children: jsxRuntime.jsxs("ul", { className: "mb-0 pe-50", children: [jsxRuntime.jsx("li", { style: { fontSize: 13 }, children: "Nh\u1EA5n v\u00E0o c\u1ED9t STT \u0111\u1EC3 ch\u1ECDn h\u00E0ng v\u00E0 nh\u1EA5n Ctrl + D \u0111\u1EC3 nh\u00E2n b\u1EA3n" }), jsxRuntime.jsx("li", { style: { fontSize: 13 }, children: "Ch\u1ECDn \u00F4 v\u00E0 Ctrl + V \u0111\u1EC3 d\u00E1n th\u00F4ng tin t\u1EEB excel" }), jsxRuntime.jsx("li", { style: { fontSize: 13 }, children: "Nh\u1EA5n v\u00E0o c\u1ED9t STT \u0111\u1EC3 ch\u1ECDn h\u00E0ng v\u00E0 nh\u1EA5n Ctrl + C \u0111\u1EC3 sao ch\u00E9p h\u00E0ng" }), jsxRuntime.jsx("li", { style: { fontSize: 13 }, children: "Nh\u1EA5n v\u00E0o c\u1ED9t STT \u0111\u1EC3 ch\u1ECDn h\u00E0ng v\u00E0 nh\u1EA5n Ctrl + V \u0111\u1EC3 d\u00E1n h\u00E0ng" })] }) })] }) })] })] }) }));
43129
- };
43130
- const checkSearch = (keyword, data, fieldKey) => {
43131
- if (!keyword || fieldKey.length === 0) {
43132
- return true;
43133
- }
43134
- for (let index = 0; index < fieldKey.length; index++) {
43135
- const key = fieldKey[index].trim();
43136
- if (data[key] && data[key].toString().trim().toLowerCase().includes(keyword.trim().toLowerCase())) {
43137
- return true;
43138
- }
43328
+ }, children: [typeDis === 1 && !refreshRow ? RenderEdit(row, col, parents, indexCol, indexRow) : jsxRuntime.jsx("div", { id: `content-${idTable}-row${indexRow}col-${indexCol}`, className: "r-cell-text", children: typeDis === 2 ? (col.template && col.template(row, indexRow)) ?? '' : (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxRuntime.jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsxRuntime.jsx("span", { id: `error-${indexRow}-${indexCol}`, className: classnames('cursor-pointer text-primary icon-table', { 'd-none': !errorMessage }), children: jsxRuntime.jsx(SvgAlertCircle, { fontSize: 15.5 }) }), (!(typeDis === 1 && !refreshRow)) && jsxRuntime.jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `content-${idTable}-row${indexRow}col-${indexCol}`, children: typeDis === 2 ? (col.template && col.template(row, indexRow)) ?? '' : (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxRuntime.jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsxRuntime.jsx(UncontrolledTooltip, { target: `error-${indexRow}-${indexCol}`, className: "r-tooltip tooltip-error", children: errorMessage?.toString() ?? '' })] }) }) }, `col-${indexRow}-${indexCol}`) }, indexCol));
43139
43329
  }
43140
- return false;
43141
43330
  };
43142
43331
  const renderData = () => {
43143
43332
  totalCount = 0;
43144
- let countDisplay = -1;
43145
- return (dataSource.map((row, indexRow) => {
43333
+ const renderRow = (row, indexRow, parents = '') => {
43146
43334
  const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
43147
- const flagSearch = !searchClient || checkSearch(searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm, row, searchSetting?.keyField ?? []);
43148
- if (flagSearch) {
43335
+ const flagSearch = !searchClient || checkSearch(searchSetting?.searchTerm ?? searchTerm, row, searchSetting?.keyField ?? []);
43336
+ if (!flagSearch)
43337
+ return null;
43338
+ if (parents === '')
43149
43339
  totalCount += 1;
43150
- const flagDisplay = !pagingClient || (totalCount > ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0) - 1)) && totalCount <= ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0))));
43151
- if (flagDisplay) {
43152
- countDisplay++;
43153
- return (jsxRuntime.jsx("tr", { className: classnames('r-row', { 'fisrt-row': countDisplay === 0 }), children: contentColumns.map((col, indexCol) => {
43154
- return (renderContentCol(col, row, indexRow, indexCol, isSelected));
43155
- }) }, `row-${indexRow}`));
43156
- }
43157
- }
43158
- }));
43340
+ const flagDisplay = !pagingClient || (totalCount > ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0) - 1)) && totalCount <= ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0))));
43341
+ return (flagDisplay && jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("tr", { className: classnames('r-row'), children: contentColumns.map((col, indexCol) => renderContentCol(col, row, indexRow, indexCol, parents, isSelected)) }, `row-${parents}-${indexRow}`), isTree && row.expanded && row[fieldChildren ?? 'children']?.length > 0 && row[fieldChildren ?? 'children'].map((child, indexChild) => renderRow(child, indexChild, getNewParents(parents, indexRow)))] }));
43342
+ };
43343
+ return dataSource.map((row, indexRow) => renderRow(row, indexRow));
43159
43344
  };
43160
43345
  React$5.useEffect(() => {
43161
43346
  if (pagingClient && pagingSetting?.setCurrentPage && (searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm)) {
43162
43347
  pagingSetting?.setCurrentPage(1);
43163
43348
  }
43164
43349
  }, [searchTerm, searchSetting?.searchTerm]);
43165
- 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(jsxRuntime.Fragment, { children: renderToolbarTop(toolbarTopOption) }) : jsxRuntime.jsx(jsxRuntime.Fragment, {}), 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) => {
43350
+ 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) => {
43166
43351
  return (jsxRuntime.jsx("tr", { className: "r-row", role: "row", children: element?.map((col, index) => {
43167
43352
  return (jsxRuntime.jsx(HeaderTableCol, { col: col, dataSource: dataSource, indexCol: index, indexParent: indexParent, isMulti: isMulti ?? false, objWidthFix: objWidthFix, selectEnable: selectEnable ?? false, selectedRows: selectedRows, setSelectedRows: setSelectedRows, column: contentColumns, setColumn: setContentColumns, totalCount: totalCount }, `header-${indexParent}-${index}`));
43168
43353
  }) }, `header-${-indexParent}`));
43169
43354
  }) }), 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) => {
43170
- return (renderFooterCol(col, index));
43171
- }) }) : jsxRuntime.jsx(jsxRuntime.Fragment, {}) })] }) }), toolbarSetting?.showBottomToolbar ? jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderToolbarBottom() }) : jsxRuntime.jsx(jsxRuntime.Fragment, {})] }), pagingSetting?.allowPaging ? jsxRuntime.jsx(PagingComponent, { onChangePage: onChangePage, pageSize: pagingSetting?.pageSize ?? 0, currentPage: pagingSetting?.currentPage ?? 0, pageOptions: pagingSetting?.pageOptions ?? [20, 30, 50, 100], totalItem: pagingClient ? totalCount : (pagingSetting?.totalItem ?? 0), onChangePageSize: onChangePageSize }) : jsxRuntime.jsx(jsxRuntime.Fragment, {})] }), jsxRuntime.jsx(SidebarSetColumn, { handleSidebar: () => { setOpenPopupSetupColumn(!openPopupSetupColumn); }, openSidebar: openPopupSetupColumn, column: [...contentColumns], setColumn: setContentColumns })] }));
43355
+ return jsxRuntime.jsx(FooterCol, { col: col, indexCol: index, dataSource: dataSource, objWidthFix: objWidthFix, formatSetting: formatSetting });
43356
+ }) }) : jsxRuntime.jsx(jsxRuntime.Fragment, {}) })] }) }), toolbarSetting?.showBottomToolbar && jsxRuntime.jsx(ToolbarBottom, { handleAdd: () => {
43357
+ handleAdd(dataSource, tableElement.current, columnFistEdit, changeDataSource, pagingSetting, setItemFocus, focusNewElement);
43358
+ }, handleDuplicate: () => {
43359
+ handleDuplicate(dataSource, itemFocus, fieldKey, defaultValue, fieldUniKey, changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate);
43360
+ }, handleInsertAfter: () => {
43361
+ handleInsertAfter(dataSource, itemFocus, defaultValue, changeDataSource, tableElement, totalCount, pagingClient, pagingSetting, toolbarSetting, buttonSetting, editDisable, addDisable);
43362
+ }, handleInsertBefore: () => {
43363
+ handleInsertBefore(dataSource, itemFocus, defaultValue, changeDataSource, pagingClient, pagingSetting, toolbarSetting, buttonSetting, editDisable, addDisable);
43364
+ }, handleDeleteAll: () => {
43365
+ handleDeleteAll(t, messageBoxConfirmDelete, setItemFocus, changeDataSource, editDisable, addDisable, toolbarSetting, buttonSetting);
43366
+ }, setOpenPopupSetupColumn: setOpenPopupSetupColumn, itemFocus: itemFocus, editDisable: editDisable, addDisable: addDisable, buttonSetting: buttonSetting, toolbarSetting: toolbarSetting, headerColumns: headerColumns, t: t })] }), pagingSetting?.allowPaging ? jsxRuntime.jsx(PagingComponent, { onChangePage: onChangePage, pageSize: pagingSetting?.pageSize ?? 0, currentPage: pagingSetting?.currentPage ?? 0, pageOptions: pagingSetting?.pageOptions ?? [20, 30, 50, 100], totalItem: pagingClient ? totalCount : (pagingSetting?.totalItem ?? 0), onChangePageSize: onChangePageSize }) : jsxRuntime.jsx(jsxRuntime.Fragment, {})] }), jsxRuntime.jsx(SidebarSetColumn, { handleSidebar: () => { setOpenPopupSetupColumn(!openPopupSetupColumn); }, openSidebar: openPopupSetupColumn, column: [...contentColumns], setColumn: setContentColumns })] }));
43172
43367
  });
43173
43368
 
43174
43369
  const TabsMenuComponent = ({ buttonWidth, tabParent, tabChild, resourceCodeParent, resources, resourceCode, windowSize, renderModal }) => {
@@ -64928,7 +65123,7 @@ const TabMergeImportExcel = (props) => {
64928
65123
  return jsxRuntime.jsx(jsxRuntime.Fragment, { children: data.isRequired ? jsxRuntime.jsx(SvgCheckSquare, { color: 'green', fontSize: 18 }) : jsxRuntime.jsx(SvgXSquare, { color: 'red', fontSize: 18 }) });
64929
65124
  },
64930
65125
  disabledCondition: (row) => {
64931
- return row.disableEdit;
65126
+ return row.disableEdit ?? false;
64932
65127
  },
64933
65128
  width: 80,
64934
65129
  minWidth: 80,
@@ -65504,10 +65699,10 @@ const ImportExcelComponent = (props) => {
65504
65699
  };
65505
65700
 
65506
65701
  exports.ExportExcelComponent = ExportExcelComponent;
65702
+ exports.FindNodeByPath = FindNodeByPath;
65507
65703
  exports.ImportExcelComponent = ImportExcelComponent;
65508
65704
  exports.InputStyleComponent = InputStyleComponent;
65509
65705
  exports.SelectTable = SelectTable;
65510
- exports.SelectTableTree = SelectTableTree;
65511
65706
  exports.TabsMenuComponent = TabsMenuComponent;
65512
65707
  exports.checkDecimalSeparator = checkDecimalSeparator;
65513
65708
  exports.checkThousandSeparator = checkThousandSeparator;