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.mjs CHANGED
@@ -16227,12 +16227,12 @@ const keydownHandler = (innerParams, event, dismissWith) => {
16227
16227
 
16228
16228
  // ENTER
16229
16229
  if (event.key === 'Enter') {
16230
- handleEnter(event, innerParams);
16230
+ handleEnter$1(event, innerParams);
16231
16231
  }
16232
16232
 
16233
16233
  // TAB
16234
16234
  else if (event.key === 'Tab') {
16235
- handleTab(event);
16235
+ handleTab$1(event);
16236
16236
  }
16237
16237
 
16238
16238
  // ARROWS - switch focus between buttons
@@ -16250,7 +16250,7 @@ const keydownHandler = (innerParams, event, dismissWith) => {
16250
16250
  * @param {KeyboardEvent} event
16251
16251
  * @param {SweetAlertOptions} innerParams
16252
16252
  */
16253
- const handleEnter = (event, innerParams) => {
16253
+ const handleEnter$1 = (event, innerParams) => {
16254
16254
  // https://github.com/sweetalert2/sweetalert2/issues/2386
16255
16255
  if (!callIfFunction(innerParams.allowEnterKey)) {
16256
16256
  return;
@@ -16268,7 +16268,7 @@ const handleEnter = (event, innerParams) => {
16268
16268
  /**
16269
16269
  * @param {KeyboardEvent} event
16270
16270
  */
16271
- const handleTab = event => {
16271
+ const handleTab$1 = event => {
16272
16272
  const targetElement = event.target;
16273
16273
  const focusableElements = getFocusableElements();
16274
16274
  let btnIndex = -1;
@@ -19163,7 +19163,7 @@ const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
19163
19163
  }
19164
19164
  };
19165
19165
  const isNullOrUndefined$1 = (d) => {
19166
- if (d === null || d === undefined) {
19166
+ if (d === null || d === undefined || d === '') {
19167
19167
  return true;
19168
19168
  }
19169
19169
  return false;
@@ -19254,6 +19254,21 @@ const formatDateTime = (data, format = 'dd/MM/yyyy') => {
19254
19254
  };
19255
19255
  return format.replace(/dd|MM|yyyy|HH|mm/g, (match) => map[match]);
19256
19256
  };
19257
+ // Hàm tìm vị trí theo chuỗi index
19258
+ const FindNodeByPath = (tree, path) => {
19259
+ const levels = path.split('-').map(num => parseInt(num, 10));
19260
+ let current = tree;
19261
+ let node = null;
19262
+ for (let index = 0; index < levels.length - 1; index++) {
19263
+ const level = levels[index];
19264
+ if (!current[level] || !current[level].children) {
19265
+ return null;
19266
+ }
19267
+ node = current[level];
19268
+ current = current[level].children ?? [];
19269
+ }
19270
+ return { parent: current, lastIndex: levels.at(-1), firstIndex: levels.length === 1 ? levels[0] : -1, node };
19271
+ };
19257
19272
 
19258
19273
  var isCheckBoxInput = (element) => element.type === 'checkbox';
19259
19274
 
@@ -22970,7 +22985,7 @@ const SelectTable = forwardRef((props, ref) => {
22970
22985
  inputRef?.current.focus();
22971
22986
  e.preventDefault();
22972
22987
  }
22973
- }, children: jsxs("div", { className: 'r-select-grid', children: [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: jsx(RenderTable, {}) }), jsxs("div", { className: classnames('r-select-footer', { 'd-none': !(showFooter === true || handleAdd) }), children: [jsxs(Button$1, { outline: true, color: "primary", onClick: e => handleAdd?.(), className: classnames('r-btn d-flex align-items-center', { 'd-none': !handleAdd }), children: [jsx(SvgPlus, { className: "me-50", fontSize: 16 }), t('AddNew'), " (F9)"] }), footerComponent ? footerComponent() : null] })] }) }) }) })] }) }) }));
22988
+ }, children: jsxs("div", { className: 'r-select-grid', children: [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: jsx(RenderTable, {}) }), jsxs("div", { className: classnames('r-select-footer', { 'd-none': !(showFooter === true || handleAdd) }), children: [jsxs(Button$1, { outline: true, color: "primary", onClick: () => handleAdd?.(), className: classnames('r-btn d-flex align-items-center', { 'd-none': !handleAdd }), children: [jsx(SvgPlus, { className: "me-50", fontSize: 16 }), t('AddNew'), " (F9)"] }), footerComponent ? footerComponent() : null] })] }) }) }) })] }) }) }));
22974
22989
  });
22975
22990
 
22976
22991
  const SelectTableBox = (props) => {
@@ -25374,15 +25389,15 @@ const IconCustom = (props) => {
25374
25389
  };
25375
25390
 
25376
25391
  const CommandElement = (props) => {
25377
- const { commandItems, rowData, indexRow, handleCommandClick, indexFocus, setIndexFocus } = props;
25392
+ const { commandItems, rowData, indexRow, handleCommandClick, itemFocus, setItemFocus, currentItem } = props;
25378
25393
  const { t } = useTranslation();
25379
25394
  return (jsx(Fragment, { children: jsx("div", { className: 'd-flex align-items-center', style: { columnGap: 10 }, children: commandItems.map((item, index) => {
25380
25395
  return (jsxs(Button$1, { id: `command-item-${indexRow}-${index}`, tabIndex: -1, style: { padding: '5px', minWidth: 45, height: '100%' }, className: classnames('command-item', {
25381
25396
  'btn-icon': item.tooltip === ''
25382
25397
  }), color: item.color ? item.color : '#000', onClick: (e) => {
25383
25398
  handleCommandClick(item.id, rowData, indexRow);
25384
- if (indexRow === indexFocus) {
25385
- setIndexFocus(undefined);
25399
+ if (currentItem === itemFocus) {
25400
+ setItemFocus('');
25386
25401
  }
25387
25402
  e.preventDefault();
25388
25403
  }, children: [item.icon && jsx(IconCustom, { iconName: item.icon, size: 16 }), jsx(UncontrolledTooltip, { className: "r-tooltip", target: `command-item-${indexRow}-${index}`, place: "top", children: t(item.tooltip ?? '') })] }, `command-${index}`));
@@ -25740,16 +25755,6 @@ const SelectTableTree = forwardRef((props, ref) => {
25740
25755
  }, children: jsxs("div", { className: 'r-select-grid r-select-tree-grid', children: [jsx("div", { className: "r-select-gridtable ", ref: selectMenuTableRef, style: { width: menuWidth, minWidth: selectTableRef?.current?.clientWidth, maxHeight: maxHeight ?? defaultMaxHeight }, children: jsx(RenderTable, {}) }), jsxs("div", { className: classnames('r-select-footer', { 'd-none': !(showFooter === true || handleAdd || isMulti) }), children: [jsxs(Button$1, { outline: true, color: "primary", onClick: handleAdd, className: classnames('r-btn d-flex align-items-center', { 'd-none': !handleAdd }), children: [jsx(SvgPlus, { className: "me-50", fontSize: 16 }), t('AddNew'), " (F9)"] }), isMulti && 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] })] }) }) }) })] }) }) }));
25741
25756
  });
25742
25757
 
25743
- const renderToolbarTop = (toolbarTopOption) => {
25744
- return (jsx("div", { id: "table_custom_top_toolbar", className: "r-toolbar r-toolbar-top", "aria-orientation": "horizontal", children: jsxs("div", { className: "r-toolbar-items", children: [jsx("div", { className: "r-toolbar-left", children: toolbarTopOption?.map((item, index) => {
25745
- return ((item.align === 'left') ? jsx(Fragment$1, { children: jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-left-${index}`) }) : '');
25746
- }) }), jsx("div", { className: "r-toolbar-center", children: toolbarTopOption?.map((item, index) => {
25747
- return ((item.align === 'center') ? jsx(Fragment$1, { children: jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-center-${index}`) }) : '');
25748
- }) }), jsx("div", { className: "r-toolbar-right", children: toolbarTopOption?.map((item, index) => {
25749
- return ((item.align === 'right') ? jsx(Fragment$1, { children: jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-right-${index}`) }) : '');
25750
- }) })] }) }));
25751
- };
25752
-
25753
25758
  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}
25754
25759
 
25755
25760
  /**
@@ -42091,16 +42096,356 @@ const DateInput = (props) => {
42091
42096
  } }));
42092
42097
  };
42093
42098
 
42099
+ const handleArrowRight = (e, params) => {
42100
+ const { indexCol, contentColumns, row, parents, indexRow, focusNewElement } = params;
42101
+ let newIndexCol = -1;
42102
+ for (let i = indexCol; i < contentColumns.length; i++) {
42103
+ if (contentColumns[i].editEnable && contentColumns[i].visible !== false && !contentColumns[i].disabledCondition?.(row)) {
42104
+ newIndexCol = i + 1;
42105
+ break;
42106
+ }
42107
+ }
42108
+ if (newIndexCol > -1) {
42109
+ focusNewElement(newIndexCol, parents, indexRow);
42110
+ e.preventDefault();
42111
+ return e.code;
42112
+ }
42113
+ };
42114
+ const handleArrowLeft = (e, params) => {
42115
+ const { indexCol, contentColumns, row, parents, indexRow, focusNewElement } = params;
42116
+ let newIndexCol = -1;
42117
+ for (let i = indexCol - 2; i >= 0; i--) {
42118
+ if (contentColumns[i].editEnable && contentColumns[i].visible !== false && !contentColumns[i].disabledCondition?.(row)) {
42119
+ newIndexCol = i + 1;
42120
+ break;
42121
+ }
42122
+ }
42123
+ if (newIndexCol > -1) {
42124
+ focusNewElement(newIndexCol, parents, indexRow);
42125
+ e.preventDefault();
42126
+ return e.code;
42127
+ }
42128
+ };
42129
+ const isSelectMenuOpen = (element) => {
42130
+ 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);
42131
+ };
42132
+ const handleArrowUp = (e, params) => {
42133
+ const { idElement, indexCol, indexRow, parents, pagingClient, pagingSetting, setItemFocus, getNewParents, focusNewElement } = params;
42134
+ const element = document.getElementById(idElement);
42135
+ if (!isSelectMenuOpen(element)) {
42136
+ if (indexRow > 1) {
42137
+ if (parents === "" && pagingClient && pagingSetting?.currentPage !== 1 && indexRow % (pagingSetting?.pageSize ?? 0) === 1 && pagingSetting?.setCurrentPage) {
42138
+ pagingSetting.setCurrentPage((pagingSetting?.currentPage ?? 1) - 1);
42139
+ }
42140
+ setItemFocus(getNewParents(parents, indexRow - 2));
42141
+ focusNewElement(indexCol, parents, indexRow - 1, true);
42142
+ e.preventDefault();
42143
+ return e.code;
42144
+ }
42145
+ else if (parents !== "") {
42146
+ setItemFocus(parents);
42147
+ focusNewElement(indexCol, parents, undefined, true);
42148
+ e.preventDefault();
42149
+ return e.code;
42150
+ }
42151
+ }
42152
+ };
42153
+ const handleArrowDown = (e, params) => {
42154
+ const { idElement, row, fieldChildren, itemFocus, dataSource, indexCol, indexRow, parents, totalCount, pagingClient, pagingSetting, setItemFocus, getNewParents, focusNewElement } = params;
42155
+ const element = document.getElementById(idElement);
42156
+ if (!isSelectMenuOpen(element)) {
42157
+ if (row[fieldChildren ?? 'children']?.length > 0 && row.expanded) {
42158
+ setItemFocus(getNewParents(itemFocus, 0));
42159
+ focusNewElement(indexCol, itemFocus, 1, true);
42160
+ e.preventDefault();
42161
+ return e.code;
42162
+ }
42163
+ else {
42164
+ if (parents === '') {
42165
+ if (indexRow < totalCount) {
42166
+ if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42167
+ pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42168
+ }
42169
+ setItemFocus(getNewParents(parents, indexRow));
42170
+ focusNewElement(indexCol, parents, indexRow + 1, true);
42171
+ e.preventDefault();
42172
+ return e.code;
42173
+ }
42174
+ }
42175
+ else {
42176
+ const result = FindNodeByPath(dataSource, itemFocus);
42177
+ if (!result) {
42178
+ return;
42179
+ }
42180
+ const { parent, lastIndex } = result;
42181
+ if (!parent) {
42182
+ return;
42183
+ }
42184
+ if ((lastIndex ?? 0) < parent.length - 1) {
42185
+ setItemFocus(getNewParents(parents, indexRow));
42186
+ focusNewElement(indexCol, parents, indexRow + 1, true);
42187
+ e.preventDefault();
42188
+ return e.code;
42189
+ }
42190
+ else {
42191
+ const result = FindNodeByPath(dataSource, parents);
42192
+ if (!result) {
42193
+ return '';
42194
+ }
42195
+ const { lastIndex } = result;
42196
+ setItemFocus(getNewParents(parents.split('-').slice(0, -1).join('-'), (lastIndex ?? 0) + 1));
42197
+ focusNewElement(indexCol, parents.split('-').slice(0, -1).join('-'), (lastIndex ?? 0) + 2, true);
42198
+ e.preventDefault();
42199
+ return e.code;
42200
+ }
42201
+ }
42202
+ }
42203
+ }
42204
+ };
42205
+ const handleTab = (e, params) => {
42206
+ const { indexCol, columnLastEdit, indexRow, totalCount, moveIndexRowToNewPage, pagingClient, pagingSetting, setItemFocus, getNewParents, parents, focusNewElement } = params;
42207
+ if (indexCol === columnLastEdit) {
42208
+ if (indexRow === totalCount) {
42209
+ moveIndexRowToNewPage();
42210
+ }
42211
+ else {
42212
+ if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42213
+ pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42214
+ }
42215
+ setItemFocus(getNewParents(parents, indexRow));
42216
+ focusNewElement(indexCol, parents, indexRow + 1, true);
42217
+ }
42218
+ e.preventDefault();
42219
+ return e.code;
42220
+ }
42221
+ };
42222
+ const handleEnter = (e, params) => {
42223
+ const { idElement, row, fieldChildren, addDisable, dataSource, editDisable, moveIndexRowToNewPage, itemFocus, indexCol, indexRow, parents, totalCount, pagingClient, pagingSetting, setItemFocus, getNewParents, focusNewElement } = params;
42224
+ if (!editDisable && !addDisable) {
42225
+ const element = document.getElementById(idElement);
42226
+ if (!isSelectMenuOpen(element)) {
42227
+ if (row[fieldChildren ?? 'children']?.length > 0 && row.expanded) {
42228
+ setItemFocus(getNewParents(itemFocus, 0));
42229
+ focusNewElement(indexCol, itemFocus, 1, true);
42230
+ e.preventDefault();
42231
+ return e.code;
42232
+ }
42233
+ else {
42234
+ if (parents === '') {
42235
+ if (indexRow === totalCount) {
42236
+ moveIndexRowToNewPage();
42237
+ }
42238
+ else {
42239
+ if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42240
+ pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42241
+ }
42242
+ setItemFocus(getNewParents(parents, indexRow));
42243
+ focusNewElement(indexCol, parents, indexRow + 1, true);
42244
+ }
42245
+ e.preventDefault();
42246
+ return e.code;
42247
+ }
42248
+ else {
42249
+ const result = FindNodeByPath(dataSource, itemFocus);
42250
+ if (!result) {
42251
+ return;
42252
+ }
42253
+ const { parent, lastIndex } = result;
42254
+ if (!parent) {
42255
+ return;
42256
+ }
42257
+ if ((lastIndex ?? 0) < parent.length - 1) {
42258
+ setItemFocus(getNewParents(parents, indexRow));
42259
+ focusNewElement(indexCol, parents, indexRow + 1, true);
42260
+ e.preventDefault();
42261
+ return e.code;
42262
+ }
42263
+ else {
42264
+ const result = FindNodeByPath(dataSource, parents);
42265
+ if (!result) {
42266
+ return '';
42267
+ }
42268
+ const { lastIndex } = result;
42269
+ setItemFocus(getNewParents(parents.split('-').slice(0, -1).join('-'), (lastIndex ?? 0) + 1));
42270
+ focusNewElement(indexCol, parents.split('-').slice(0, -1).join('-'), (lastIndex ?? 0) + 2, true);
42271
+ e.preventDefault();
42272
+ return e.code;
42273
+ }
42274
+ }
42275
+ }
42276
+ }
42277
+ }
42278
+ };
42279
+ const handleCtrlD = (e, params) => {
42280
+ const { editDisable, addDisable, handleDuplicate } = params;
42281
+ if (!editDisable && !addDisable) {
42282
+ handleDuplicate();
42283
+ e.preventDefault();
42284
+ return e.code;
42285
+ }
42286
+ };
42287
+
42288
+ const ToolbarBottom = ({ handleAdd, handleDuplicate, handleInsertBefore, handleInsertAfter, handleDeleteAll, setOpenPopupSetupColumn, itemFocus, editDisable, addDisable, buttonSetting, toolbarSetting, headerColumns, t
42289
+ // isTree
42290
+ }) => {
42291
+ return (jsx("div", { id: "table_custom_bottom_toolbar", className: "r-toolbar r-toolbar-bottom", role: "toolbar", children: jsxs("div", { className: "r-toolbar-items", children: [jsxs("div", { className: "r-toolbar-left", children: [jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable }), children: jsx(Button$1, { color: 'success', outline: true, onClick: handleAdd, className: 'd-flex', children: t('Add item') }) }), itemFocus && jsxs(Fragment$1, { children: [jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.duplicateDisable }), children: jsx(Button$1, { color: 'success', outline: true, onClick: handleDuplicate, className: 'd-flex', children: t('Duplicate') }) }), jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.insertBeforeDisable }), children: jsx(Button$1, { color: 'success', outline: true, onClick: handleInsertBefore, className: 'd-flex', children: t('Insert item before') }) }), jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.insertAfterDisable }), children: jsx(Button$1, { color: 'success', outline: true, onClick: handleInsertAfter, className: 'd-flex', children: t('Insert item after') }) })] }), jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || buttonSetting?.deleteAllDisable }), children: 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' && (jsx("div", { className: "r-toolbar-item", children: item.template() }, `toolbar-bottom-left-${index}`))))] }), jsx("div", { className: "r-toolbar-center", children: toolbarSetting?.toolbarBottomOptions?.map((item, index) => (item.align === 'center' && (jsx("div", { className: "r-toolbar-item", children: item.template() }, `toolbar-bottom-center-${index}`)))) }), jsxs("div", { className: "r-toolbar-right", children: [toolbarSetting?.toolbarBottomOptions?.map((item, index) => (item.align === 'right' && (jsx("div", { className: "r-toolbar-item", children: item.template() }, `toolbar-bottom-right-${index}`)))), jsx("div", { className: classnames('r-toolbar-item me-25', { 'd-none': headerColumns.length > 1 }), children: jsx(SvgSettings, { className: "text-primary cursor-pointer", onClick: () => setOpenPopupSetupColumn(true) }) }), jsx("div", { className: classnames('r-toolbar-item me-25', { 'd-none': editDisable || addDisable }), children: jsxs(UncontrolledDropdown, { className: 'dropdown-user nav-item', children: [jsx(DropdownToggle$1, { tag: 'div', color: "primary", onClick: (e) => e.preventDefault(), children: jsx(SvgInfo, { className: "cursor-pointer text-primary" }) }), jsx(DropdownMenu$1, { className: 'formula-dropdown icon-dropdown', children: jsxs("ul", { className: "mb-0 pe-50", children: [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" }), jsx("li", { style: { fontSize: 13 }, children: "Ch\u1ECDn \u00F4 v\u00E0 Ctrl + V \u0111\u1EC3 d\u00E1n th\u00F4ng tin t\u1EEB excel" }), 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" }), 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" })] }) })] }) })] })] }) }));
42292
+ };
42293
+
42294
+ const RenderToolbarTop = ({ toolbarTopOption }) => {
42295
+ return (jsx("div", { id: "table_custom_top_toolbar", className: "r-toolbar r-toolbar-top", "aria-orientation": "horizontal", children: jsxs("div", { className: "r-toolbar-items", children: [jsx("div", { className: "r-toolbar-left", children: toolbarTopOption?.map((item, index) => {
42296
+ return ((item.align === 'left') ? jsx(Fragment$1, { children: jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-left-${index}`) }) : '');
42297
+ }) }), jsx("div", { className: "r-toolbar-center", children: toolbarTopOption?.map((item, index) => {
42298
+ return ((item.align === 'center') ? jsx(Fragment$1, { children: jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-center-${index}`) }) : '');
42299
+ }) }), jsx("div", { className: "r-toolbar-right", children: toolbarTopOption?.map((item, index) => {
42300
+ return ((item.align === 'right') ? jsx(Fragment$1, { children: jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-top-right-${index}`) }) : '');
42301
+ }) })] }) }));
42302
+ };
42303
+
42304
+ const FooterCol = ({ col, indexCol, dataSource, objWidthFix, formatSetting }) => {
42305
+ const sumValue = (col.haveSum === true && col.editType === "numeric") ? dataSource.reduce(function (accumulator, currentValue) { return (Number(accumulator ?? 0) + Number(currentValue[col.field] ?? 0)); }, 0) : 0;
42306
+ return (jsx(Fragment, { children: col.visible !== false && (jsx("td", { className: classnames(`p-0 px-50 r-footer fix-${col.fixedType}`, { "cell-fixed": col.fixedType }), style: {
42307
+ left: col.fixedType === "left" ? objWidthFix[indexCol] : undefined,
42308
+ right: col.fixedType === "right" ? objWidthFix[indexCol] : undefined,
42309
+ textAlign: col.textAlign ?? "left"
42310
+ }, children: jsx("div", { className: "r-footer-div", children: col.haveSum === true && col.editType === "numeric" && (jsx(Fragment$1, { children: Number(sumValue) >= 0 ? (jsx(Fragment$1, { children: formartNumberic(sumValue, formatSetting?.decimalSeparator ?? ",", formatSetting?.thousandSeparator ?? ".", col.numericSettings?.fraction, true, false) })) : (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}`));
42311
+ };
42312
+
42313
+ const handleAdd = (dataSource, tableElement, columnFistEdit,
42314
+ /*eslint-disable*/
42315
+ changeDataSource, pagingSetting, setItemFocus, focusNewElement
42316
+ /*eslint-enable*/
42317
+ ) => {
42318
+ const lengthData = dataSource.length;
42319
+ changeDataSource(dataSource, true);
42320
+ if (pagingSetting?.setCurrentPage) {
42321
+ pagingSetting.setCurrentPage(Math.floor(lengthData / (pagingSetting?.pageSize ?? 0)) + 1);
42322
+ }
42323
+ if (tableElement) {
42324
+ setItemFocus(`${lengthData}`);
42325
+ focusNewElement(columnFistEdit, '', lengthData + 1, true);
42326
+ }
42327
+ };
42328
+ const handleDuplicate = async (dataSource, itemFocus, fieldKey, defaultValue, fieldUniKey,
42329
+ /*eslint-disable*/
42330
+ changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate // sự kiện khi duplicate
42331
+ /*eslint-enable*/
42332
+ ) => {
42333
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.duplicateDisable && !editDisable && !addDisable) {
42334
+ const result = FindNodeByPath(dataSource, itemFocus);
42335
+ if (!result) {
42336
+ return;
42337
+ }
42338
+ const { parent, lastIndex, node } = result;
42339
+ if (!parent || !node) {
42340
+ return;
42341
+ }
42342
+ const newData = { ...node };
42343
+ if (fieldKey && defaultValue) {
42344
+ fieldUniKey.forEach((item) => {
42345
+ newData[item] = defaultValue[item];
42346
+ });
42347
+ newData[fieldKey] = defaultValue[fieldKey];
42348
+ }
42349
+ if (onDuplicate) {
42350
+ await onDuplicate(newData, (lastIndex ?? 0));
42351
+ }
42352
+ parent.splice((lastIndex ?? -1) + 1, 0, newData);
42353
+ changeDataSource([...dataSource]);
42354
+ if (tableElement && lastIndex === totalCount) {
42355
+ setTimeout(() => {
42356
+ tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
42357
+ }, 100);
42358
+ }
42359
+ }
42360
+ };
42361
+ const handleInsertAfter = (dataSource, itemFocus, defaultValue,
42362
+ /*eslint-disable*/
42363
+ changeDataSource,
42364
+ /*eslint-enable*/
42365
+ tableElement, totalCount, pagingClient, pagingSetting, toolbarSetting, buttonSetting, editDisable, addDisable) => {
42366
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertAfterDisable && !editDisable && !addDisable) {
42367
+ const result = FindNodeByPath(dataSource, itemFocus);
42368
+ if (!result) {
42369
+ return;
42370
+ }
42371
+ const { parent, lastIndex, firstIndex } = result;
42372
+ if (!parent) {
42373
+ return;
42374
+ }
42375
+ if (firstIndex >= 0) {
42376
+ if (pagingClient) {
42377
+ dataSource.splice(((((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0)) + (firstIndex ?? -1) + 1), 0, { ...defaultValue });
42378
+ }
42379
+ else {
42380
+ dataSource.splice((firstIndex ?? -1) + 1, 0, { ...defaultValue });
42381
+ }
42382
+ if (tableElement && firstIndex === totalCount) {
42383
+ setTimeout(() => {
42384
+ tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
42385
+ }, 100);
42386
+ }
42387
+ }
42388
+ else {
42389
+ // Chèn vào sau phần tử cuối cùng
42390
+ parent.splice((lastIndex ?? -1) + 1, 0, { ...defaultValue });
42391
+ }
42392
+ changeDataSource([...dataSource]);
42393
+ }
42394
+ };
42395
+ const handleInsertBefore = (dataSource, itemFocus, defaultValue,
42396
+ /*eslint-disable*/
42397
+ changeDataSource,
42398
+ /*eslint-enable*/
42399
+ pagingClient, pagingSetting, toolbarSetting, buttonSetting, editDisable, addDisable) => {
42400
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertAfterDisable && !editDisable && !addDisable) {
42401
+ const result = FindNodeByPath(dataSource, itemFocus);
42402
+ if (!result) {
42403
+ return;
42404
+ }
42405
+ const { parent, lastIndex, firstIndex } = result;
42406
+ if (!parent) {
42407
+ return;
42408
+ }
42409
+ if (firstIndex >= 0) {
42410
+ if (pagingClient) {
42411
+ dataSource.splice(((((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0)) + (firstIndex ?? -1)), 0, { ...defaultValue });
42412
+ }
42413
+ else {
42414
+ dataSource.splice((firstIndex ?? -1), 0, { ...defaultValue });
42415
+ }
42416
+ }
42417
+ else {
42418
+ // Chèn vào sau phần tử cuối cùng
42419
+ parent.splice((lastIndex ?? -1), 0, { ...defaultValue });
42420
+ }
42421
+ changeDataSource([...dataSource]);
42422
+ }
42423
+ };
42424
+ const handleDeleteAll = (t,
42425
+ /*eslint-disable*/
42426
+ messageBoxConfirmDelete, setItemFocus, changeDataSource,
42427
+ /*eslint-enable*/
42428
+ editDisable, addDisable, toolbarSetting, buttonSetting) => {
42429
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.deleteAllDisable && !editDisable && !addDisable) {
42430
+ messageBoxConfirmDelete(t, () => {
42431
+ if (!editDisable && !addDisable) {
42432
+ setItemFocus('');
42433
+ changeDataSource([], false);
42434
+ }
42435
+ }, '');
42436
+ }
42437
+ };
42438
+
42094
42439
  const TableEdit = forwardRef((props, ref) => {
42095
42440
  const { t } = useTranslation();
42096
- 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;
42441
+ 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;
42097
42442
  useImperativeHandle(ref, () => {
42098
42443
  return {
42099
42444
  refeshFocusRow: handleRefeshRow
42100
42445
  };
42101
42446
  });
42102
42447
  const [refreshRow, setRefreshRow] = useState(false);
42103
- const [indexFocus, setIndexFocus] = useState();
42448
+ const [itemFocus, setItemFocus] = useState('');
42104
42449
  const [selectedRows, setSelectedRows] = useState([]);
42105
42450
  const [headerColumns, setHeaderColumns] = useState([[]]);
42106
42451
  const [contentColumns, setContentColumns] = useState([]);
@@ -42117,6 +42462,7 @@ const TableEdit = forwardRef((props, ref) => {
42117
42462
  const searchClient = searchSetting?.searchEnable && (searchSetting?.searchClient || !(editDisable || addDisable));
42118
42463
  const fieldKey = columns.find((item) => item.isPrimarykey === true)?.field ?? 'id';
42119
42464
  const fieldUniKey = columns.filter((item) => item.isUnikey === true)?.map((item) => item.field);
42465
+ const getNewParents = (parents, index) => (parents ? `${parents}-${index}` : `${index}`);
42120
42466
  useEffect(() => {
42121
42467
  if (pagingClient && pagingSetting.setCurrentPage && Math.ceil(totalCount / (pagingSetting?.pageSize ?? 1)) < (pagingSetting.currentPage ?? 1)) {
42122
42468
  pagingSetting.setCurrentPage(1);
@@ -42267,30 +42613,251 @@ const TableEdit = forwardRef((props, ref) => {
42267
42613
  else {
42268
42614
  toolbarTopOption = [...defaultToolbarOption];
42269
42615
  }
42270
- const RenderEdit = (row, col, indexCol, indexRow) => {
42616
+ const onChangePage = (args) => {
42617
+ if (pagingSetting?.setCurrentPage) {
42618
+ if (args.currentPage === args.oldPage) {
42619
+ return;
42620
+ }
42621
+ pagingSetting.setCurrentPage(args.currentPage);
42622
+ }
42623
+ };
42624
+ const onChangePageSize = (args) => {
42625
+ if (pagingSetting?.allowPaging) {
42626
+ if (pagingSetting?.pageSize !== args.pageSize) {
42627
+ if (pagingSetting?.setPageSize) {
42628
+ pagingSetting.setPageSize(args.pageSize);
42629
+ }
42630
+ if (pagingSetting?.setCurrentPage) {
42631
+ pagingSetting.setCurrentPage(1);
42632
+ }
42633
+ }
42634
+ }
42635
+ };
42636
+ useOnClickOutside(gridRef, () => {
42637
+ setTimeout(() => {
42638
+ setItemFocus('');
42639
+ }, 50);
42640
+ });
42641
+ const getColumn = (col, index) => {
42642
+ const column = contentColumns.filter(e => e.visible !== false)[col + index];
42643
+ if (column) {
42644
+ return { ...column };
42645
+ }
42646
+ return undefined;
42647
+ };
42648
+ const pasteDataFromExcel = async (currenRowIndex, col, e) => {
42649
+ const clipboard = (e.clipboardData || window.Clipboard).getData('text');
42650
+ const rowsClipboard = clipboard.trimEnd().split('\n');
42651
+ setItemFocus('');
42652
+ if (rowsClipboard.length > 200) {
42653
+ messageBoxError(t, 'You can only paste up to 200 rows.');
42654
+ }
42655
+ if (rowsClipboard.length > 0) {
42656
+ const columnsDataChange = [];
42657
+ for (let index = 0; index < rowsClipboard[0].trimEnd().split('\t').length; index++) {
42658
+ const stringData = [];
42659
+ rowsClipboard.forEach((element) => {
42660
+ if (element.trimEnd().split('\t')[index] && !stringData.includes(element.trimEnd().split('\t')[index].toString().trim())) {
42661
+ stringData.push(element.trimEnd().split('\t')[index].toString().trim());
42662
+ }
42663
+ });
42664
+ const column = getColumn(col, index);
42665
+ if (column) {
42666
+ if ((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + 0])) && column.editEnable && column.onPasteValidate) {
42667
+ const rs = await column.onPasteValidate(stringData.join(','), currenRowIndex + 0, dataSource[currenRowIndex + 0]);
42668
+ if (rs) {
42669
+ column.resultValidate = rs;
42670
+ }
42671
+ }
42672
+ columnsDataChange.push(column);
42673
+ }
42674
+ }
42675
+ for (let indexRow = 0; indexRow < rowsClipboard.length; indexRow++) {
42676
+ const item = rowsClipboard[indexRow];
42677
+ const colsClipboard = item.trimEnd().split('\t');
42678
+ let dataRow = dataSource[currenRowIndex + indexRow];
42679
+ if (!dataRow) {
42680
+ dataRow = { ...defaultValue };
42681
+ dataSource.push(dataRow);
42682
+ }
42683
+ for (let index = 0; index < colsClipboard.length; index++) {
42684
+ const stringData = colsClipboard[index].toString().trim();
42685
+ const column = columnsDataChange[index];
42686
+ if (column) {
42687
+ if (((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + indexRow])) && column.editEnable) || column.onPaste) {
42688
+ if (column.onPasteValidate && column.resultValidate) {
42689
+ const rs = column.resultValidate.find((item) => item[column.selectSettings?.fieldValue ?? 'value'] === stringData);
42690
+ if (rs) {
42691
+ if (column.onPaste) {
42692
+ dataRow[column.field] = column.onPaste(dataRow, stringData);
42693
+ }
42694
+ else {
42695
+ dataRow[column.field] = stringData;
42696
+ }
42697
+ if (column.callback) {
42698
+ column.callback(rs, currenRowIndex + indexRow);
42699
+ }
42700
+ }
42701
+ else {
42702
+ notificationError(t('PasteExcelNotExist', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42703
+ }
42704
+ }
42705
+ else {
42706
+ if (column.editType === 'date') {
42707
+ const date = new Date(stringData);
42708
+ if (!isNaN(date.getTime())) {
42709
+ if (column.onPaste) {
42710
+ dataRow[column.field] = column.onPaste(dataRow, date);
42711
+ }
42712
+ else {
42713
+ dataRow[column.field] = date;
42714
+ }
42715
+ if (column.callback) {
42716
+ column.callback(date, currenRowIndex + indexRow);
42717
+ }
42718
+ }
42719
+ else {
42720
+ notificationError(t('PasteExcelIncorrectFormat', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42721
+ }
42722
+ }
42723
+ else if (column.editType === 'numeric') {
42724
+ const number = Number(stringData);
42725
+ if (!isNaN(number)) {
42726
+ if (column.onPaste) {
42727
+ dataRow[column.field] = column.onPaste(dataRow, number);
42728
+ }
42729
+ else {
42730
+ dataRow[column.field] = number;
42731
+ }
42732
+ if (column.callback) {
42733
+ column.callback(number, currenRowIndex + indexRow);
42734
+ }
42735
+ }
42736
+ else {
42737
+ notificationError(t('PasteExcelIncorrectFormat', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42738
+ }
42739
+ }
42740
+ else if (column.editType === 'select') {
42741
+ const rs = ((column.selectSettings?.optionsField ? item[column.selectSettings?.optionsField] : column.selectSettings?.options) ?? []).find((item) => item[column.selectSettings?.fieldValue ?? 'value'] === stringData);
42742
+ if (rs) {
42743
+ if (column.onPaste) {
42744
+ dataRow[column.field] = column.onPaste(dataRow, stringData);
42745
+ }
42746
+ else {
42747
+ dataRow[column.field] = stringData;
42748
+ }
42749
+ if (column.callback) {
42750
+ column.callback(rs, currenRowIndex + indexRow);
42751
+ }
42752
+ }
42753
+ else {
42754
+ notificationError(t('PasteExcelNotExist', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42755
+ }
42756
+ }
42757
+ else {
42758
+ if (column.onPaste) {
42759
+ column.onPaste(dataRow, stringData);
42760
+ }
42761
+ else {
42762
+ dataRow[column.field] = stringData;
42763
+ }
42764
+ if (column.callback) {
42765
+ column.callback(stringData, currenRowIndex + indexRow);
42766
+ }
42767
+ }
42768
+ }
42769
+ }
42770
+ }
42771
+ }
42772
+ if (rowChange) {
42773
+ rowChange(dataRow, currenRowIndex + indexRow, '');
42774
+ }
42775
+ }
42776
+ }
42777
+ changeDataSource(dataSource);
42778
+ };
42779
+ const changeDataSource = (data, haveNew = false) => {
42780
+ if (!editDisable && setDataSource) {
42781
+ if (haveNew && !addDisable) {
42782
+ data.push(defaultValue ? { ...defaultValue, [fieldKey]: disableAutoKey ? undefined : generateUUID() } : {});
42783
+ setDataSource([...data]);
42784
+ }
42785
+ else {
42786
+ setDataSource([...data]);
42787
+ }
42788
+ }
42789
+ };
42790
+ useEffect(() => {
42791
+ setItemFocus('');
42792
+ if (setSelectedItem) {
42793
+ if (isMulti) {
42794
+ if (dataSource && selectedRows && selectedRows?.length !== selectedItem?.length) {
42795
+ setSelectedItem([...selectedRows]);
42796
+ if (handleSelect) {
42797
+ handleSelect([...selectedRows]);
42798
+ }
42799
+ }
42800
+ }
42801
+ else {
42802
+ if (dataSource && selectedRows?.length > 0) {
42803
+ if ((!selectedItem || (selectedItem[fieldKey] !== selectedRows[0][fieldKey]))) {
42804
+ setSelectedItem({ ...selectedRows[0] });
42805
+ if (handleSelect) {
42806
+ handleSelect({ ...selectedRows[0] });
42807
+ }
42808
+ }
42809
+ }
42810
+ else {
42811
+ setSelectedItem(undefined);
42812
+ if (handleSelect) {
42813
+ handleSelect(undefined);
42814
+ }
42815
+ }
42816
+ }
42817
+ }
42818
+ }, [selectedRows]);
42819
+ useEffect(() => {
42820
+ if (!isMulti) {
42821
+ if (dataSource && selectedItem && selectedItem[fieldKey]) {
42822
+ if (selectedRows?.length === 0 || selectedItem[fieldKey] !== selectedRows[0][fieldKey]) {
42823
+ setSelectedRows([selectedItem]);
42824
+ }
42825
+ }
42826
+ else {
42827
+ setSelectedRows([]);
42828
+ }
42829
+ }
42830
+ else {
42831
+ if (dataSource && selectedItem && selectedRows?.length !== selectedItem.length) {
42832
+ setSelectedRows(selectedItem ? [...selectedItem] : []);
42833
+ }
42834
+ }
42835
+ }, [selectedItem]);
42836
+ const RenderEdit = (row, col, parents, indexCol, indexRow) => {
42837
+ const idElement = `${idTable}-col${indexCol + 1}-row${getNewParents(parents, indexRow + 1)}`;
42271
42838
  /*eslint-disable */
42272
42839
  switch (col?.editTypeCondition ? col?.editTypeCondition(row) : col.editType) {
42273
42840
  case 'date':
42274
- return (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) => {
42841
+ return (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) => {
42275
42842
  row[col.field] = date ? new Date(date.getTime() + 7 * 60 * 60 * 1000) : undefined;
42276
42843
  if (col.callback) {
42277
- col.callback(row[col.field], indexRow);
42844
+ col.callback(row[col.field], indexRow, row);
42278
42845
  }
42279
42846
  handleDataChange(row, col, indexRow);
42280
42847
  }, dateFormat: "dd/MM/yyyy", onKeyDown: (e) => {
42281
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) {
42848
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) {
42282
42849
  return true;
42283
42850
  }
42284
42851
  } }));
42285
42852
  case 'datetime':
42286
- return (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) => {
42853
+ return (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) => {
42287
42854
  row[col.field] = date;
42288
42855
  if (col.callback) {
42289
- col.callback(row[col.field], indexRow);
42856
+ col.callback(row[col.field], indexRow, row);
42290
42857
  }
42291
42858
  handleDataChange(row, col, indexRow);
42292
42859
  }, dateFormat: "dd/MM/yyyy HH:mm", onKeyDown: (e) => {
42293
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) {
42860
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) {
42294
42861
  return true;
42295
42862
  }
42296
42863
  } }));
@@ -42312,7 +42879,7 @@ const TableEdit = forwardRef((props, ref) => {
42312
42879
  valueSelect = col.selectSettings?.defaultValue(row);
42313
42880
  }
42314
42881
  }
42315
- return (jsx(SelectTable, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, value: valueSelect, options: optionsSelect, onChange: (val) => {
42882
+ return (jsx(SelectTable, { id: idElement, value: valueSelect, options: optionsSelect, onChange: (val) => {
42316
42883
  if (col.selectSettings?.isMulti) {
42317
42884
  row[col.field] = (val?.length ?? 0) > 0 ? val.map((item) => item[col.selectSettings?.fieldValue ?? 'value']) : [];
42318
42885
  }
@@ -42334,11 +42901,11 @@ const TableEdit = forwardRef((props, ref) => {
42334
42901
  }
42335
42902
  }
42336
42903
  if (col.callback) {
42337
- col.callback(val, indexRow);
42904
+ col.callback(val, indexRow, row);
42338
42905
  }
42339
42906
  handleDataChange(row, col, indexRow);
42340
- }, 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) => {
42341
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) ;
42907
+ }, 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) => {
42908
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) ;
42342
42909
  }, onOpenMenu: () => {
42343
42910
  if (col.selectSettings?.onOpenMenu) {
42344
42911
  col.selectSettings?.onOpenMenu(row, col, indexRow);
@@ -42379,8 +42946,8 @@ const TableEdit = forwardRef((props, ref) => {
42379
42946
  valueSelectTree = (!isNullOrUndefined$1(row[col.field]) && row[col.field] !== '') ? findItemInTree(optionsSelectTree, row[col.field]) : '';
42380
42947
  }
42381
42948
  return (jsx("div", { onKeyDown: (e) => {
42382
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) ;
42383
- }, children: jsx(SelectTableTree, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, value: valueSelectTree, options: optionsSelectTree, onChange: (val) => {
42949
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) ;
42950
+ }, children: jsx(SelectTableTree, { id: idElement, value: valueSelectTree, options: optionsSelectTree, onChange: (val) => {
42384
42951
  if (col.selectSettings?.isMulti) {
42385
42952
  row[col.field] = !isNullOrUndefined$1(val) ? val : [];
42386
42953
  }
@@ -42388,7 +42955,7 @@ const TableEdit = forwardRef((props, ref) => {
42388
42955
  row[col.field] = !isNullOrUndefined$1(val) ? val[col.selectSettings?.fieldValue ?? 'value'] : undefined;
42389
42956
  }
42390
42957
  if (col.callback) {
42391
- col.callback(val, indexRow);
42958
+ col.callback(val, indexRow, row);
42392
42959
  }
42393
42960
  handleDataChange(row, col, indexRow);
42394
42961
  }, 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: () => {
@@ -42396,7 +42963,7 @@ const TableEdit = forwardRef((props, ref) => {
42396
42963
  col.selectSettings?.onOpenMenu(row, col, indexRow);
42397
42964
  }
42398
42965
  }, 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) => {
42399
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) ;
42966
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) ;
42400
42967
  }, onPaste: (e) => {
42401
42968
  if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
42402
42969
  pasteDataFromExcel(indexRow, indexCol, e);
@@ -42404,14 +42971,14 @@ const TableEdit = forwardRef((props, ref) => {
42404
42971
  }
42405
42972
  } }) }));
42406
42973
  case 'checkbox':
42407
- return (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) => {
42974
+ return (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) => {
42408
42975
  row[col.field] = val.currentTarget.checked;
42409
42976
  if (col.callback) {
42410
- col.callback(val.target.value, indexRow);
42977
+ col.callback(val.target.value, indexRow, row);
42411
42978
  }
42412
42979
  handleDataChange(row, col, indexRow);
42413
42980
  }, onKeyDown: (e) => {
42414
- if (checkKeyDown(e, row, col, indexRow + 1, indexCol + 1)) ;
42981
+ if (checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1)) ;
42415
42982
  } }));
42416
42983
  case 'numeric':
42417
42984
  const numericFormatProps = {
@@ -42422,7 +42989,7 @@ const TableEdit = forwardRef((props, ref) => {
42422
42989
  decimalScale: col.numericSettings?.fraction ?? 0
42423
42990
  };
42424
42991
  let floatValue = parseFloat(row[col.field]);
42425
- return (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) => {
42992
+ return (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) => {
42426
42993
  floatValue = values?.floatValue;
42427
42994
  }, onFocus: (e) => {
42428
42995
  e.target.setSelectionRange(0, e.target.innerText.length - 1);
@@ -42430,7 +42997,7 @@ const TableEdit = forwardRef((props, ref) => {
42430
42997
  if (floatValue !== row[col.field]) {
42431
42998
  row[col.field] = !isNaN(floatValue) ? floatValue : 0;
42432
42999
  if (col.callback) {
42433
- col.callback(row[col.field], indexRow);
43000
+ col.callback(row[col.field], indexRow, row);
42434
43001
  }
42435
43002
  handleDataChange(row, col, indexRow);
42436
43003
  }
@@ -42439,12 +43006,12 @@ const TableEdit = forwardRef((props, ref) => {
42439
43006
  if (floatValue !== row[col.field]) {
42440
43007
  row[col.field] = !isNaN(floatValue) ? floatValue : 0;
42441
43008
  if (col.callback) {
42442
- col.callback(row[col.field], indexRow);
43009
+ col.callback(row[col.field], indexRow, row);
42443
43010
  }
42444
43011
  handleDataChange(row, col, indexRow);
42445
43012
  }
42446
43013
  }
42447
- checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
43014
+ checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1);
42448
43015
  }, onPaste: (e) => {
42449
43016
  if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
42450
43017
  pasteDataFromExcel(indexRow, indexCol, e);
@@ -42456,19 +43023,19 @@ const TableEdit = forwardRef((props, ref) => {
42456
43023
  if (row[col.field] != val.target?.value) {
42457
43024
  row[col.field] = val.target?.value;
42458
43025
  if (col.callback) {
42459
- col.callback(val.target.value, indexRow);
43026
+ col.callback(val.target.value, indexRow, row);
42460
43027
  }
42461
43028
  handleDataChange(row, col, indexRow);
42462
43029
  }
42463
43030
  }, onKeyDown: (val) => {
42464
- checkKeyDown(val, row, col, indexRow + 1, indexCol + 1);
43031
+ checkKeyDown(val, row, parents, indexRow + 1, indexCol + 1);
42465
43032
  } }, `col-${indexRow}-${indexCol}`) }));
42466
43033
  case 'form':
42467
- return (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) => {
43034
+ return (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) => {
42468
43035
  row = { ...row, ...val };
42469
43036
  handleDataChange(row, col, indexRow);
42470
43037
  }, invalid: col.validate && col.validate(row[col.field], row), textAlign: col.textAlign, onKeyDown: (e) => {
42471
- return checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
43038
+ return checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1);
42472
43039
  }, onPaste: (e) => {
42473
43040
  if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
42474
43041
  pasteDataFromExcel(indexRow, indexCol, e);
@@ -42476,16 +43043,16 @@ const TableEdit = forwardRef((props, ref) => {
42476
43043
  }
42477
43044
  } }));
42478
43045
  default:
42479
- return (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) => {
43046
+ return (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) => {
42480
43047
  if (row[col.field] != val.target?.value) {
42481
43048
  row[col.field] = val.target?.value;
42482
43049
  if (col.callback) {
42483
- col.callback(val.target.value, indexRow);
43050
+ col.callback(val.target.value, indexRow, row);
42484
43051
  }
42485
43052
  handleDataChange(row, col, indexRow);
42486
43053
  }
42487
43054
  }, onKeyDown: (e) => {
42488
- checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
43055
+ checkKeyDown(e, row, parents, indexRow + 1, indexCol + 1);
42489
43056
  }, onPaste: (e) => {
42490
43057
  if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
42491
43058
  pasteDataFromExcel(indexRow, indexCol, e);
@@ -42500,9 +43067,14 @@ const TableEdit = forwardRef((props, ref) => {
42500
43067
  }
42501
43068
  };
42502
43069
  // focus vào dòng mới
42503
- const focusNewElement = (col, row, onLoad = false) => {
43070
+ const focusNewElement = (col, parents, row, onLoad = false) => {
43071
+ let indexRow = row;
43072
+ if (indexRow === undefined) {
43073
+ indexRow = (parents.length > 0 ? parseInt(parents.split('-').pop() ?? '0') : 0) + 1;
43074
+ parents = parents.split('-').slice(0, -1).join('-');
43075
+ }
42504
43076
  setTimeout(() => {
42505
- const element = document.getElementById(`${idTable}-col${col}-row${row}`);
43077
+ const element = document.getElementById(`${idTable}-col${col}-row${getNewParents(parents, indexRow)}`);
42506
43078
  if (element) {
42507
43079
  if (element.className.includes('react-select') || element.className.includes('form-edit')) {
42508
43080
  element.getElementsByTagName('input')[0]?.focus();
@@ -42510,459 +43082,98 @@ const TableEdit = forwardRef((props, ref) => {
42510
43082
  else {
42511
43083
  element.focus();
42512
43084
  }
42513
- if (!onLoad) {
42514
- if (tableElement.current) {
42515
- const parentRect = tableElement.current.getBoundingClientRect();
42516
- const childRect = element.getBoundingClientRect();
42517
- const offset = childRect.left - parentRect.left + tableElement.current.scrollLeft - (parentRect.width / 2) + (childRect.width / 2);
42518
- tableElement.current.scrollTo({ left: offset, behavior: 'smooth' });
42519
- }
42520
- }
42521
- if ((tableElement.current?.scrollHeight ?? 0) > 0) {
42522
- if ((tableElement.current?.scrollTop ?? 0) > ((row - 1) % (pagingSetting?.pageSize ?? 1)) * 34) {
42523
- tableElement.current?.scrollTo({ behavior: 'smooth', top: ((row - 1) % (pagingSetting?.pageSize ?? 1)) * 34 });
43085
+ if (isTree) {
43086
+ if (!onLoad) {
43087
+ if (tableElement.current) {
43088
+ const parentRect = tableElement.current.getBoundingClientRect();
43089
+ const childRect = element.getBoundingClientRect();
43090
+ const offset = childRect.left - parentRect.left + tableElement.current.scrollLeft - (parentRect.width / 2) + (childRect.width / 2);
43091
+ tableElement.current.scrollTo({ left: offset, behavior: 'smooth' });
43092
+ }
42524
43093
  }
42525
- else if (((tableElement.current?.clientHeight ?? 0) - (haveSum ? 30 : 0) - (headerColumns.length * 42)) < (((row % (pagingSetting?.pageSize ?? 1)) * 34) - (tableElement.current?.scrollTop ?? 0))) {
42526
- tableElement.current?.scrollTo({ behavior: 'smooth', top: (tableElement.current?.scrollTop ?? 0) + 34 });
43094
+ if ((tableElement.current?.scrollHeight ?? 0) > 0) {
43095
+ if ((tableElement.current?.scrollTop ?? 0) > ((indexRow - 1) % (pagingSetting?.pageSize ?? 1)) * 34) {
43096
+ tableElement.current?.scrollTo({ behavior: 'smooth', top: ((indexRow - 1) % (pagingSetting?.pageSize ?? 1)) * 34 });
43097
+ }
43098
+ else if (((tableElement.current?.clientHeight ?? 0) - (haveSum ? 30 : 0) - (headerColumns.length * 42)) < (((indexRow % (pagingSetting?.pageSize ?? 1)) * 34) - (tableElement.current?.scrollTop ?? 0))) {
43099
+ tableElement.current?.scrollTo({ behavior: 'smooth', top: (tableElement.current?.scrollTop ?? 0) + 34 });
43100
+ }
42527
43101
  }
42528
43102
  }
42529
43103
  }
42530
43104
  }, onLoad ? 100 : 0);
42531
43105
  };
42532
- //Thêm dòng mới
43106
+ //cần sửa
42533
43107
  const moveIndexRowToNewPage = () => {
42534
43108
  changeDataSource(dataSource, true);
42535
43109
  if (pagingClient && pagingSetting?.setCurrentPage && (totalCount % (pagingSetting?.pageSize ?? 0)) === 0) {
42536
43110
  pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 0) + 1);
42537
43111
  }
42538
43112
  if (tableElement) {
42539
- setIndexFocus(totalCount);
42540
- focusNewElement(columnFistEdit, totalCount + 1, true);
43113
+ setItemFocus(`${totalCount}`);
43114
+ focusNewElement(columnFistEdit, '', totalCount + 1, true);
42541
43115
  }
42542
43116
  };
42543
- const checkKeyDown = (e, row, col, indexRow, indexCol) => {
42544
- if (e.code === 'ArrowRight') {
42545
- let newIndexCol = -1;
42546
- for (let i = indexCol; i < contentColumns.length; i++) {
42547
- if (contentColumns[i].editEnable && (contentColumns[i].visible !== false) && (!contentColumns[i].disabledCondition?.(row))) {
42548
- newIndexCol = i + 1;
42549
- break;
42550
- }
42551
- }
42552
- if (newIndexCol > -1) {
42553
- focusNewElement(newIndexCol, indexRow);
42554
- e.preventDefault();
42555
- return e.code;
42556
- }
42557
- }
42558
- else if (e.code === 'ArrowLeft') {
42559
- let newIndexCol = -1;
42560
- for (let i = indexCol - 2; i >= 0; i--) {
42561
- if (contentColumns[i].editEnable && (contentColumns[i].visible !== false) && (!contentColumns[i].disabledCondition?.(row))) {
42562
- newIndexCol = i + 1;
42563
- break;
42564
- }
42565
- }
42566
- if (newIndexCol > -1) {
42567
- focusNewElement(newIndexCol, indexRow);
42568
- e.preventDefault();
42569
- return e.code;
42570
- }
42571
- }
42572
- else if (e.code === 'ArrowUp') {
42573
- const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
42574
- if (element && !(element.getElementsByClassName('select__control--menu-is-open').length > 0 ||
42575
- element.getElementsByClassName('select-100__control--menu-is-open').length > 0 ||
42576
- element.getElementsByClassName('select-200__control--menu-is-open').length > 0 ||
42577
- element.getElementsByClassName('select-300__control--menu-is-open').length > 0 ||
42578
- element.getElementsByClassName('select-400__control--menu-is-open').length > 0 ||
42579
- element.getElementsByClassName('select-500__control--menu-is-open').length > 0)) {
42580
- if (indexRow > 1) {
42581
- if (pagingClient && (pagingSetting?.currentPage ?? 0) !== 1 && (indexRow % (pagingSetting?.pageSize ?? 0)) === 1 && pagingSetting?.setCurrentPage) {
42582
- pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) - 1);
42583
- }
42584
- setIndexFocus(indexRow - 2);
42585
- focusNewElement(indexCol, indexRow - 1, true);
42586
- e.preventDefault();
42587
- return e.code;
42588
- }
42589
- }
42590
- }
42591
- else if (e.code === 'ArrowDown') {
42592
- const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
42593
- if (element && !(element.getElementsByClassName('select__control--menu-is-open').length > 0 ||
42594
- element.getElementsByClassName('select-100__control--menu-is-open').length > 0 ||
42595
- element.getElementsByClassName('select-200__control--menu-is-open').length > 0 ||
42596
- element.getElementsByClassName('select-300__control--menu-is-open').length > 0 ||
42597
- element.getElementsByClassName('select-400__control--menu-is-open').length > 0 ||
42598
- element.getElementsByClassName('select-500__control--menu-is-open').length > 0)) {
42599
- if (indexRow < totalCount) {
42600
- if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42601
- pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42602
- }
42603
- setIndexFocus(indexRow);
42604
- focusNewElement(indexCol, indexRow + 1, true);
42605
- e.preventDefault();
42606
- return e.code;
42607
- }
42608
- }
42609
- }
42610
- else if (e.code === 'Tab' && indexCol === columnLastEdit) {
42611
- if (indexRow === totalCount) {
42612
- moveIndexRowToNewPage();
42613
- }
42614
- else {
42615
- if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42616
- pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42617
- }
42618
- setIndexFocus(indexRow);
42619
- focusNewElement(indexCol, indexRow + 1, true);
42620
- }
42621
- e.preventDefault();
42622
- return e.code;
42623
- }
42624
- else if ((e.code === 'Enter' || e.code === 'NumpadEnter') && (!editDisable && !addDisable)) {
42625
- const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
42626
- if (element && !(element.getElementsByClassName('select__control--menu-is-open').length > 0 ||
42627
- element.getElementsByClassName('select-100__control--menu-is-open').length > 0 ||
42628
- element.getElementsByClassName('select-200__control--menu-is-open').length > 0 ||
42629
- element.getElementsByClassName('select-300__control--menu-is-open').length > 0 ||
42630
- element.getElementsByClassName('select-400__control--menu-is-open').length > 0 ||
42631
- element.getElementsByClassName('select-500__control--menu-is-open').length > 0)) {
42632
- if (indexRow === totalCount) {
42633
- moveIndexRowToNewPage();
42634
- }
42635
- else {
42636
- if (pagingClient && (indexRow % (pagingSetting?.pageSize ?? 0)) === 0 && pagingSetting?.setCurrentPage) {
42637
- pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
42638
- }
42639
- setIndexFocus(indexRow);
42640
- focusNewElement(indexCol, indexRow + 1, true);
42641
- }
42642
- e.preventDefault();
42643
- return e.code;
42644
- }
42645
- }
42646
- else if (e.code === 'KeyD' && e.ctrlKey == true && (!editDisable && !addDisable)) {
42647
- handleDuplicate(dataSource[indexFocus ?? -1], indexRow);
42648
- e.preventDefault();
42649
- return e.code;
42650
- }
42651
- return '';
42652
- };
42653
- const onChangePage = (args) => {
42654
- if (pagingSetting?.setCurrentPage) {
42655
- if (args.currentPage === args.oldPage) {
42656
- return;
42657
- }
42658
- pagingSetting.setCurrentPage(args.currentPage);
42659
- }
42660
- };
42661
- const onChangePageSize = (args) => {
42662
- if (pagingSetting?.allowPaging) {
42663
- if (pagingSetting?.pageSize !== args.pageSize) {
42664
- if (pagingSetting?.setPageSize) {
42665
- pagingSetting.setPageSize(args.pageSize);
42666
- }
42667
- if (pagingSetting?.setCurrentPage) {
42668
- pagingSetting.setCurrentPage(1);
42669
- }
42670
- }
42671
- }
42672
- };
42673
- useOnClickOutside(gridRef, () => {
42674
- setTimeout(() => {
42675
- setIndexFocus(-1);
42676
- }, 50);
42677
- });
42678
- const handleAdd = () => {
42679
- const lengthData = dataSource.length;
42680
- changeDataSource(dataSource, true);
42681
- if (pagingSetting?.setCurrentPage) {
42682
- pagingSetting?.setCurrentPage(Math.floor(lengthData / (pagingSetting?.pageSize ?? 0)) + 1);
42683
- }
42684
- if (tableElement) {
42685
- setIndexFocus(lengthData);
42686
- focusNewElement(columnFistEdit, lengthData + 1, true);
42687
- }
42688
- };
42689
- const handleDuplicate = async (data, index) => {
42690
- const newData = { ...data };
42691
- if (toolbarSetting?.showBottomToolbar && !buttonSetting?.duplicateDisable && !editDisable && !addDisable) {
42692
- if (fieldKey && defaultValue) {
42693
- fieldUniKey.forEach((item) => {
42694
- newData[item] = defaultValue[item];
42695
- });
42696
- newData[fieldKey] = defaultValue[fieldKey];
42697
- }
42698
- if (onDuplicate) {
42699
- await onDuplicate(newData, index);
42700
- }
42701
- if (pagingClient) {
42702
- dataSource.splice((((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + index) + 1, 0, newData);
42703
- }
42704
- else {
42705
- dataSource.splice(index + 1, 0, newData);
42706
- }
42707
- changeDataSource(dataSource);
42708
- if (tableElement && index === totalCount) {
42709
- setTimeout(() => {
42710
- tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
42711
- }, 100);
42712
- }
42713
- }
42714
- };
42715
- const handleInsertAfter = () => {
42716
- if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertAfterDisable && !editDisable && !addDisable) {
42717
- if (pagingClient) {
42718
- dataSource.splice((((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + (indexFocus ?? -1) + 1), 0, { ...{ ...defaultValue } });
42719
- }
42720
- else {
42721
- dataSource.splice((indexFocus ?? -1) + 1, 0, { ...defaultValue });
42722
- }
42723
- changeDataSource(dataSource);
42724
- if (tableElement && indexFocus === totalCount) {
42725
- setTimeout(() => {
42726
- tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
42727
- }, 100);
42728
- }
42729
- }
42730
- };
42731
- const handleInsertBefore = () => {
42732
- if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertBeforeDisable && !editDisable && !addDisable) {
42733
- if (pagingClient) {
42734
- dataSource.splice((((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + (indexFocus ?? -1)), 0, { ...{ ...defaultValue } });
42735
- }
42736
- else {
42737
- dataSource.splice((indexFocus ?? -1), 0, { ...defaultValue });
42738
- }
42739
- changeDataSource(dataSource);
42740
- }
42741
- };
42742
- const handleDeleteAll = () => {
42743
- if (toolbarSetting?.showBottomToolbar && !buttonSetting?.deleteAllDisable && !editDisable && !addDisable) {
42744
- messageBoxConfirmDelete(t, deleteAll, '');
42745
- }
42746
- };
42747
- const deleteAll = () => {
42748
- if (!editDisable && !addDisable) {
42749
- setIndexFocus(-1);
42750
- changeDataSource([], false);
42751
- }
42752
- };
42753
- const getColumn = (col, index) => {
42754
- const column = contentColumns.filter(e => e.visible !== false)[col + index];
42755
- if (column) {
42756
- return { ...column };
42757
- }
42758
- return undefined;
43117
+ const checkKeyDown = (e, row, parents, indexRow, indexCol) => {
43118
+ const idElement = `${idTable}-col${indexCol}-row${getNewParents(parents, indexRow)}`;
43119
+ const params = {
43120
+ columnLastEdit,
43121
+ contentColumns,
43122
+ dataSource,
43123
+ addDisable,
43124
+ editDisable,
43125
+ focusNewElement,
43126
+ getNewParents,
43127
+ handleDuplicate: () => handleDuplicate(dataSource, itemFocus, fieldKey, defaultValue, fieldUniKey, changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate),
43128
+ idElement,
43129
+ indexCol,
43130
+ indexRow,
43131
+ itemFocus,
43132
+ moveIndexRowToNewPage,
43133
+ pagingClient,
43134
+ pagingSetting,
43135
+ parents,
43136
+ row,
43137
+ setItemFocus,
43138
+ totalCount,
43139
+ fieldChildren
43140
+ };
43141
+ const handlers = {
43142
+ ArrowRight: () => handleArrowRight(e, params),
43143
+ ArrowLeft: () => handleArrowLeft(e, params),
43144
+ ArrowUp: () => handleArrowUp(e, params),
43145
+ ArrowDown: () => handleArrowDown(e, params),
43146
+ Tab: () => handleTab(e, params),
43147
+ Enter: () => handleEnter(e, params),
43148
+ NumpadEnter: () => handleEnter(e, params),
43149
+ KeyD: () => (e.ctrlKey ? handleCtrlD(e, params) : undefined)
43150
+ };
43151
+ return handlers[e.code]?.() || "";
42759
43152
  };
42760
- const pasteDataFromExcel = async (currenRowIndex, col, e) => {
42761
- const clipboard = (e.clipboardData || window.Clipboard).getData('text');
42762
- const rowsClipboard = clipboard.trimEnd().split('\n');
42763
- setIndexFocus(undefined);
42764
- if (rowsClipboard.length > 200) {
42765
- messageBoxError(t, 'You can only paste up to 200 rows.');
42766
- }
42767
- if (rowsClipboard.length > 0) {
42768
- const columnsDataChange = [];
42769
- for (let index = 0; index < rowsClipboard[0].trimEnd().split('\t').length; index++) {
42770
- const stringData = [];
42771
- rowsClipboard.forEach((element) => {
42772
- if (element.trimEnd().split('\t')[index] && !stringData.includes(element.trimEnd().split('\t')[index].toString().trim())) {
42773
- stringData.push(element.trimEnd().split('\t')[index].toString().trim());
42774
- }
42775
- });
42776
- const column = getColumn(col, index);
42777
- if (column) {
42778
- if ((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + 0])) && column.editEnable && column.onPasteValidate) {
42779
- const rs = await column.onPasteValidate(stringData.join(','), currenRowIndex + 0, dataSource[currenRowIndex + 0]);
42780
- if (rs) {
42781
- column.resultValidate = rs;
42782
- }
42783
- }
42784
- columnsDataChange.push(column);
42785
- }
42786
- }
42787
- for (let indexRow = 0; indexRow < rowsClipboard.length; indexRow++) {
42788
- const item = rowsClipboard[indexRow];
42789
- const colsClipboard = item.trimEnd().split('\t');
42790
- let dataRow = dataSource[currenRowIndex + indexRow];
42791
- if (!dataRow) {
42792
- dataRow = { ...defaultValue };
42793
- dataSource.push(dataRow);
42794
- }
42795
- for (let index = 0; index < colsClipboard.length; index++) {
42796
- const stringData = colsClipboard[index].toString().trim();
42797
- const column = columnsDataChange[index];
42798
- if (column) {
42799
- if (((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + indexRow])) && column.editEnable) || column.onPaste) {
42800
- if (column.onPasteValidate && column.resultValidate) {
42801
- const rs = column.resultValidate.find((item) => item[column.selectSettings?.fieldValue ?? 'value'] === stringData);
42802
- if (rs) {
42803
- if (column.onPaste) {
42804
- dataRow[column.field] = column.onPaste(dataRow, stringData);
42805
- }
42806
- else {
42807
- dataRow[column.field] = stringData;
42808
- }
42809
- if (column.callback) {
42810
- column.callback(rs, currenRowIndex + indexRow);
42811
- }
42812
- }
42813
- else {
42814
- notificationError(t('PasteExcelNotExist', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42815
- }
42816
- }
42817
- else {
42818
- if (column.editType === 'date') {
42819
- const date = new Date(stringData);
42820
- if (!isNaN(date.getTime())) {
42821
- if (column.onPaste) {
42822
- dataRow[column.field] = column.onPaste(dataRow, date);
42823
- }
42824
- else {
42825
- dataRow[column.field] = date;
42826
- }
42827
- if (column.callback) {
42828
- column.callback(date, currenRowIndex + indexRow);
42829
- }
42830
- }
42831
- else {
42832
- notificationError(t('PasteExcelIncorrectFormat', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42833
- }
42834
- }
42835
- else if (column.editType === 'numeric') {
42836
- const number = Number(stringData);
42837
- if (!isNaN(number)) {
42838
- if (column.onPaste) {
42839
- dataRow[column.field] = column.onPaste(dataRow, number);
42840
- }
42841
- else {
42842
- dataRow[column.field] = number;
42843
- }
42844
- if (column.callback) {
42845
- column.callback(number, currenRowIndex + indexRow);
42846
- }
42847
- }
42848
- else {
42849
- notificationError(t('PasteExcelIncorrectFormat', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42850
- }
42851
- }
42852
- else if (column.editType === 'select') {
42853
- const rs = ((column.selectSettings?.optionsField ? item[column.selectSettings?.optionsField] : column.selectSettings?.options) ?? []).find((item) => item[column.selectSettings?.fieldValue ?? 'value'] === stringData);
42854
- if (rs) {
42855
- if (column.onPaste) {
42856
- dataRow[column.field] = column.onPaste(dataRow, stringData);
42857
- }
42858
- else {
42859
- dataRow[column.field] = stringData;
42860
- }
42861
- if (column.callback) {
42862
- column.callback(rs, currenRowIndex + indexRow);
42863
- }
42864
- }
42865
- else {
42866
- notificationError(t('PasteExcelNotExist', { index: (currenRowIndex + indexRow + 1), field: t(column.headerText ?? ''), value: stringData }));
42867
- }
42868
- }
42869
- else {
42870
- if (column.onPaste) {
42871
- column.onPaste(dataRow, stringData);
42872
- }
42873
- else {
42874
- dataRow[column.field] = stringData;
42875
- }
42876
- if (column.callback) {
42877
- column.callback(stringData, currenRowIndex + indexRow);
42878
- }
42879
- }
42880
- }
42881
- }
42882
- }
42883
- }
42884
- if (rowChange) {
42885
- rowChange(dataRow, currenRowIndex + indexRow, '');
42886
- }
42887
- }
43153
+ const checkSearch = (keyword, data, fieldKey) => {
43154
+ if (!keyword || fieldKey.length === 0) {
43155
+ return true;
42888
43156
  }
42889
- changeDataSource(dataSource);
42890
- };
42891
- const changeDataSource = (data, haveNew = false) => {
42892
- if (!editDisable && setDataSource) {
42893
- if ((searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm)) {
42894
- if (searchSetting?.setSearchTerm) {
42895
- searchSetting?.setSearchTerm('');
42896
- }
42897
- else {
42898
- setSearchTerm('');
42899
- }
42900
- }
42901
- if (haveNew && !addDisable) {
42902
- data.push(defaultValue ? { ...defaultValue, [fieldKey]: disableAutoKey ? undefined : generateUUID() } : {});
42903
- setDataSource([...data]);
42904
- }
42905
- else {
42906
- setDataSource([...data]);
43157
+ for (let index = 0; index < fieldKey.length; index++) {
43158
+ const key = fieldKey[index].trim();
43159
+ if (data[key] && data[key].toString().trim().toLowerCase().includes(keyword.trim().toLowerCase())) {
43160
+ return true;
42907
43161
  }
42908
43162
  }
43163
+ return false;
42909
43164
  };
42910
- useEffect(() => {
42911
- setIndexFocus(-1);
42912
- if (setSelectedItem) {
42913
- if (isMulti) {
42914
- if (dataSource && selectedRows && selectedRows?.length !== selectedItem?.length) {
42915
- setSelectedItem([...selectedRows]);
42916
- if (handleSelect) {
42917
- handleSelect([...selectedRows]);
42918
- }
42919
- }
42920
- }
42921
- else {
42922
- if (dataSource && selectedRows?.length > 0) {
42923
- if ((!selectedItem || (selectedItem[fieldKey] !== selectedRows[0][fieldKey]))) {
42924
- setSelectedItem({ ...selectedRows[0] });
42925
- if (handleSelect) {
42926
- handleSelect({ ...selectedRows[0] });
42927
- }
42928
- }
42929
- }
42930
- else {
42931
- setSelectedItem(undefined);
42932
- if (handleSelect) {
42933
- handleSelect(undefined);
42934
- }
42935
- }
42936
- }
42937
- }
42938
- }, [selectedRows]);
42939
- useEffect(() => {
42940
- if (!isMulti) {
42941
- if (dataSource && selectedItem && selectedItem[fieldKey]) {
42942
- if (selectedRows?.length === 0 || selectedItem[fieldKey] !== selectedRows[0][fieldKey]) {
42943
- setSelectedRows([selectedItem]);
42944
- }
42945
- }
42946
- else {
42947
- setSelectedRows([]);
42948
- }
42949
- }
42950
- else {
42951
- if (dataSource && selectedItem && selectedRows?.length !== selectedItem.length) {
42952
- setSelectedRows(selectedItem ? [...selectedItem] : []);
42953
- }
42954
- }
42955
- }, [selectedItem]);
42956
- const renderContentCol = (col, row, indexRow, indexCol, isSelected) => {
43165
+ const renderContentCol = (col, row, indexRow, indexCol, parents, isSelected) => {
43166
+ const currentItem = getNewParents(parents, indexRow);
43167
+ const level = parents ? parents.split('-').length : 0;
42957
43168
  if (col.field === 'command') {
42958
- return (col.visible !== false && jsx("td", { className: classnames(`r-rowcell p-0 fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || indexFocus === indexRow }), style: {
43169
+ return (col.visible !== false && jsx("td", { className: classnames(`r-rowcell p-0 fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || itemFocus === currentItem }), style: {
42959
43170
  left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
42960
43171
  right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
42961
43172
  textAlign: col.textAlign ? col.textAlign : 'left',
42962
- }, children: jsx("div", { className: "r-rowcell-div command", children: jsx(CommandElement, { commandItems: col.commandItems ?? [], handleCommandClick: handleCommandClick, indexRow: indexRow, rowData: row, setIndexFocus: setIndexFocus, indexFocus: indexFocus }) }) }, `col-${indexRow}-${indexCol}`));
43173
+ }, children: jsx("div", { className: "r-rowcell-div command", children: jsx(CommandElement, { commandItems: col.commandItems ?? [], handleCommandClick: handleCommandClick, indexRow: indexRow, rowData: row, currentItem: currentItem, setItemFocus: setItemFocus, itemFocus: itemFocus }) }) }, `col-${indexRow}-${indexCol}`));
42963
43174
  }
42964
43175
  else if (col.field === '#') {
42965
- return (col.visible !== false && 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: {
43176
+ return (col.visible !== false && 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: {
42966
43177
  left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
42967
43178
  right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
42968
43179
  textAlign: 'center',
@@ -42986,21 +43197,31 @@ const TableEdit = forwardRef((props, ref) => {
42986
43197
  }
42987
43198
  }, onClick: (e) => {
42988
43199
  if (e.target.nodeName === 'DIV' || e.target.nodeName === 'TD') {
42989
- if (!editDisable && indexRow != indexFocus) {
42990
- setIndexFocus(indexRow);
43200
+ if (!editDisable && itemFocus !== currentItem) {
43201
+ setItemFocus(currentItem);
42991
43202
  }
42992
43203
  e.stopPropagation();
42993
43204
  }
42994
43205
  }, onKeyDown: (e) => {
42995
43206
  if (e.code === 'KeyD' && e.ctrlKey == true && (!editDisable && !addDisable) && (e.target.nodeName === 'DIV' || e.target.nodeName === 'TD')) {
42996
- handleDuplicate(row, indexRow);
43207
+ handleDuplicate(dataSource, itemFocus, fieldKey, defaultValue, fieldUniKey, changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate);
42997
43208
  e.preventDefault();
42998
43209
  e.stopPropagation();
42999
43210
  }
43000
- }, children: jsx("div", { className: "r-rowcell-div", children: indexRow + 1 }) }, `col-${indexRow}-${indexCol}`));
43211
+ }, children: jsxs("div", { className: "r-rowcell-div", style: { paddingLeft: level * 10 }, children: [isTree && row[fieldChildren ?? 'children']?.length > 0 &&
43212
+ jsx(SvgChevronRight, { onClick: (e) => {
43213
+ if (row.expanded) {
43214
+ row.expanded = false;
43215
+ }
43216
+ else {
43217
+ row.expanded = true;
43218
+ }
43219
+ handleDataChange(row, col, indexRow);
43220
+ e.stopPropagation();
43221
+ }, fontSize: 18, className: classnames('r-icon-expand', { 'is-open': row.expanded }) }), indexRow + 1] }) }, `col-${indexRow}-${indexCol}`));
43001
43222
  }
43002
43223
  else if (col.field === 'checkbox') {
43003
- return (jsx("td", { className: classnames(`r-rowcell p-0 fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || indexFocus === indexRow }), style: {
43224
+ return (jsx("td", { className: classnames(`r-rowcell p-0 fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || itemFocus === currentItem }), style: {
43004
43225
  left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
43005
43226
  right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
43006
43227
  textAlign: col.textAlign ? col.textAlign : 'center',
@@ -43039,18 +43260,18 @@ const TableEdit = forwardRef((props, ref) => {
43039
43260
  else if (col.editType === 'datetime') {
43040
43261
  value = value ? formatDateTime(value, formatSetting?.dateFormat ?? 'DD/MM/yyyy HH:mm') : '';
43041
43262
  }
43042
- const typeDis = !editDisable && (indexFocus === indexRow || col.editType === 'checkbox') && (!col.disabledCondition || !col.disabledCondition(row)) ? (col.editEnable ? 1 : (col.template ? 2 : 3)) : (col.template ? 2 : 3);
43263
+ const typeDis = !editDisable && (itemFocus === currentItem || col.editType === 'checkbox') && (!col.disabledCondition || !col.disabledCondition(row)) ? (col.editEnable ? 1 : (col.template ? 2 : 3)) : (col.template ? 2 : 3);
43043
43264
  const errorMessage = typeDis === 1 || col.field === '' || !col.validate ? '' : col.validate(row[col.field], row);
43044
- return (jsx(Fragment, { children: col.visible !== false && jsx("td", { className: classnames(`r-rowcell fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || indexFocus === indexRow }), style: {
43265
+ return (jsx(Fragment, { children: col.visible !== false && jsx("td", { className: classnames(`r-rowcell fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || itemFocus === currentItem }), style: {
43045
43266
  left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
43046
43267
  right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
43047
43268
  padding: 0,
43048
43269
  textAlign: col.textAlign ? col.textAlign : 'left'
43049
43270
  }, onClick: (e) => {
43050
43271
  if (e.target.nodeName === 'DIV' || e.target.nodeName === 'TD') {
43051
- if (!editDisable && indexRow != indexFocus) {
43052
- setIndexFocus(indexRow);
43053
- focusNewElement(indexCol + 1, indexRow + 1, true);
43272
+ if (!editDisable && itemFocus !== currentItem) {
43273
+ setItemFocus(currentItem);
43274
+ focusNewElement(indexCol + 1, parents, indexRow + 1, true);
43054
43275
  }
43055
43276
  if (selectEnable && editDisable) {
43056
43277
  const index = selectedRows?.findIndex((x) => x[fieldKey] === row[fieldKey]);
@@ -43074,73 +43295,47 @@ const TableEdit = forwardRef((props, ref) => {
43074
43295
  }
43075
43296
  e.stopPropagation();
43076
43297
  }
43077
- }, children: jsx("div", { className: classnames('r-rowcell-div'), children: jsxs("div", { id: indexFocus === indexRow && typeDis !== 1 ? `${idTable}-col${indexCol + 1}-row${indexRow + 1}` : '', className: classnames('r-rowcell-content', { 'r-is-invalid': errorMessage }), style: {
43298
+ }, children: jsx("div", { className: classnames('r-rowcell-div'), children: jsxs("div", { id: itemFocus === currentItem && typeDis !== 1 ? `${idTable}-col${indexCol + 1}-row${indexRow + 1}` : '', className: classnames('r-rowcell-content', { 'r-is-invalid': errorMessage }), style: {
43078
43299
  margin: typeDis === 1 ? 2 : !errorMessage ? '7px 9px' : 2
43079
- }, children: [typeDis === 1 && !refreshRow ? RenderEdit(row, col, indexCol, indexRow) : 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 ? jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsx("span", { id: `error-${indexRow}-${indexCol}`, className: classnames('cursor-pointer text-primary icon-table', { 'd-none': !errorMessage }), children: jsx(SvgAlertCircle, { fontSize: 15.5 }) }), (!(typeDis === 1 && !refreshRow)) && 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 ? jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsx(UncontrolledTooltip, { target: `error-${indexRow}-${indexCol}`, className: "r-tooltip tooltip-error", children: errorMessage?.toString() ?? '' })] }) }) }, `col-${indexRow}-${indexCol}`) }, indexCol));
43080
- }
43081
- };
43082
- const renderFooterCol = (col, indexCol) => {
43083
- const sumValue = (col.haveSum === true && col.editType === "numeric") ? dataSource.reduce(function (accumulator, currentValue) { return (Number(accumulator ?? 0) + Number(currentValue[col.field] ?? 0)); }, 0) : 0;
43084
- return (jsx(Fragment, { children: (col.visible !== false) && jsx("td", { className: classnames(`p-0 px-50 r-footer fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }), style: {
43085
- left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
43086
- right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
43087
- textAlign: col.textAlign ? col.textAlign : 'left'
43088
- }, children: jsxs("div", { className: "r-footer-div", children: [col.haveSum === true && col.editType === "numeric" && (Number(sumValue) >= 0) && jsx(Fragment$1, { children: formartNumberic(sumValue, formatSetting?.decimalSeparator ?? ',', formatSetting?.thousandSeparator ?? '.', col.numericSettings?.fraction, true, false) }), col.haveSum === true && col.editType === "numeric" && (Number(sumValue) < 0) && jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${formartNumberic(sumValue, formatSetting?.decimalSeparator ?? ',', formatSetting?.thousandSeparator ?? '.', col.numericSettings?.fraction, true, false)}${formatSetting?.suffixNegative ?? ''}`] })] }) }) }, `summarycell-${indexCol}`));
43089
- };
43090
- const renderToolbarBottom = () => {
43091
- return (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: jsxs("div", { className: "r-toolbar-items", children: [jsxs("div", { className: "r-toolbar-left", children: [jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable }), "aria-disabled": "false", children: jsx(Button$1, { color: 'success', outline: true, onClick: handleAdd, className: 'd-flex', children: t('Add item') }) }), (indexFocus ?? -1) > -1 ? jsxs(Fragment$1, { children: [jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.duplicateDisable }), "aria-disabled": "false", children: jsx(Button$1, { color: 'success', outline: true, onClick: () => { handleDuplicate(dataSource[indexFocus ?? -1], indexFocus ?? -1); }, className: 'd-flex', children: t('Duplicate') }) }), jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.insertBeforeDisable }), "aria-disabled": "false", children: jsx(Button$1, { color: 'success', outline: true, onClick: handleInsertBefore, className: 'd-flex', children: t('Insert item before') }) }), jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || addDisable || buttonSetting?.insertAfterDisable }), "aria-disabled": "false", children: jsx(Button$1, { color: 'success', outline: true, onClick: handleInsertAfter, className: 'd-flex', children: t('Insert item after') }) })] }) : jsx(Fragment$1, { children: " " }), jsx("div", { className: classnames('r-toolbar-item', { 'd-none': editDisable || buttonSetting?.deleteAllDisable }), "aria-disabled": "false", children: jsx(Button$1, { color: 'primary', outline: true, onClick: handleDeleteAll, className: 'd-flex', children: t('Delete all item') }) }), toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
43092
- return ((item.align === 'left') ?
43093
- jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-left-${index}`) : '');
43094
- })] }), jsx("div", { className: "r-toolbar-center", children: toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
43095
- return ((item.align === 'center') ?
43096
- jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-center-${index}`) : '');
43097
- }) }), jsxs("div", { className: "r-toolbar-right", children: [toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
43098
- return ((item.align === 'right') ?
43099
- jsx("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-right-${index}`) : '');
43100
- }), jsx("div", { className: classnames('r-toolbar-item me-25', { 'd-none': headerColumns.length > 1 }), "aria-disabled": "false", children: jsx(SvgSettings, { className: "text-primary cursor-pointer", onClick: () => setOpenPopupSetupColumn(true) }) }), jsx("div", { className: classnames('r-toolbar-item me-25', { 'd-none': editDisable || addDisable }), "aria-disabled": "false", children: jsxs(UncontrolledDropdown, { className: 'dropdown-user nav-item', children: [jsx(DropdownToggle$1, { tag: 'div', color: "primary", onClick: (e) => e.preventDefault(), children: jsx(SvgInfo, { className: "cursor-pointer text-primary" }) }), jsx(DropdownMenu$1, { className: 'formula-dropdown icon-dropdown', children: jsxs("ul", { className: "mb-0 pe-50", children: [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" }), jsx("li", { style: { fontSize: 13 }, children: "Ch\u1ECDn \u00F4 v\u00E0 Ctrl + V \u0111\u1EC3 d\u00E1n th\u00F4ng tin t\u1EEB excel" }), 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" }), 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" })] }) })] }) })] })] }) }));
43101
- };
43102
- const checkSearch = (keyword, data, fieldKey) => {
43103
- if (!keyword || fieldKey.length === 0) {
43104
- return true;
43105
- }
43106
- for (let index = 0; index < fieldKey.length; index++) {
43107
- const key = fieldKey[index].trim();
43108
- if (data[key] && data[key].toString().trim().toLowerCase().includes(keyword.trim().toLowerCase())) {
43109
- return true;
43110
- }
43300
+ }, children: [typeDis === 1 && !refreshRow ? RenderEdit(row, col, parents, indexCol, indexRow) : 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 ? jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsx("span", { id: `error-${indexRow}-${indexCol}`, className: classnames('cursor-pointer text-primary icon-table', { 'd-none': !errorMessage }), children: jsx(SvgAlertCircle, { fontSize: 15.5 }) }), (!(typeDis === 1 && !refreshRow)) && 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 ? jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsx(UncontrolledTooltip, { target: `error-${indexRow}-${indexCol}`, className: "r-tooltip tooltip-error", children: errorMessage?.toString() ?? '' })] }) }) }, `col-${indexRow}-${indexCol}`) }, indexCol));
43111
43301
  }
43112
- return false;
43113
43302
  };
43114
43303
  const renderData = () => {
43115
43304
  totalCount = 0;
43116
- let countDisplay = -1;
43117
- return (dataSource.map((row, indexRow) => {
43305
+ const renderRow = (row, indexRow, parents = '') => {
43118
43306
  const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
43119
- const flagSearch = !searchClient || checkSearch(searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm, row, searchSetting?.keyField ?? []);
43120
- if (flagSearch) {
43307
+ const flagSearch = !searchClient || checkSearch(searchSetting?.searchTerm ?? searchTerm, row, searchSetting?.keyField ?? []);
43308
+ if (!flagSearch)
43309
+ return null;
43310
+ if (parents === '')
43121
43311
  totalCount += 1;
43122
- const flagDisplay = !pagingClient || (totalCount > ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0) - 1)) && totalCount <= ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0))));
43123
- if (flagDisplay) {
43124
- countDisplay++;
43125
- return (jsx("tr", { className: classnames('r-row', { 'fisrt-row': countDisplay === 0 }), children: contentColumns.map((col, indexCol) => {
43126
- return (renderContentCol(col, row, indexRow, indexCol, isSelected));
43127
- }) }, `row-${indexRow}`));
43128
- }
43129
- }
43130
- }));
43312
+ const flagDisplay = !pagingClient || (totalCount > ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0) - 1)) && totalCount <= ((pagingSetting.pageSize ?? 0) * ((pagingSetting.currentPage ?? 0))));
43313
+ return (flagDisplay && jsxs(Fragment$1, { children: [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)))] }));
43314
+ };
43315
+ return dataSource.map((row, indexRow) => renderRow(row, indexRow));
43131
43316
  };
43132
43317
  useEffect(() => {
43133
43318
  if (pagingClient && pagingSetting?.setCurrentPage && (searchSetting?.searchTerm !== undefined ? searchSetting?.searchTerm : searchTerm)) {
43134
43319
  pagingSetting?.setCurrentPage(1);
43135
43320
  }
43136
43321
  }, [searchTerm, searchSetting?.searchTerm]);
43137
- return (jsxs(Fragment, { children: [jsxs("div", { className: "react-table-edit", children: [jsxs("div", { className: 'r-grid', ref: gridRef, children: [toolbarSetting?.showTopToolbar ? jsx(Fragment$1, { children: renderToolbarTop(toolbarTopOption) }) : jsx(Fragment$1, {}), jsx("div", { ref: tableElement, className: "r-gridtable", style: { height: `${height ? `${height}px` : 'auto'}`, minHeight: `${minHeight ? `${minHeight}px` : ''}`, maxHeight: `${maxHeight ? `${maxHeight}px` : '400px'}` }, children: jsxs("table", { style: { width: '100%' }, children: [jsx("thead", { className: 'r-gridheader', children: headerColumns.map((element, indexParent) => {
43322
+ return (jsxs(Fragment, { children: [jsxs("div", { className: "react-table-edit", children: [jsxs("div", { className: 'r-grid', ref: gridRef, children: [toolbarSetting?.showTopToolbar && jsx(RenderToolbarTop, { toolbarTopOption: toolbarTopOption }), jsx("div", { ref: tableElement, className: "r-gridtable", style: { height: `${height ? `${height}px` : 'auto'}`, minHeight: `${minHeight ? `${minHeight}px` : ''}`, maxHeight: `${maxHeight ? `${maxHeight}px` : '400px'}` }, children: jsxs("table", { style: { width: '100%' }, children: [jsx("thead", { className: 'r-gridheader', children: headerColumns.map((element, indexParent) => {
43138
43323
  return (jsx("tr", { className: "r-row", role: "row", children: element?.map((col, index) => {
43139
43324
  return (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}`));
43140
43325
  }) }, `header-${-indexParent}`));
43141
43326
  }) }), jsx("tbody", { className: 'r-gridcontent', children: renderData() }), jsx("tfoot", { className: "r-gridfoot", children: haveSum == true ? jsx("tr", { className: 'r-row', children: contentColumns.map((col, index) => {
43142
- return (renderFooterCol(col, index));
43143
- }) }) : jsx(Fragment$1, {}) })] }) }), toolbarSetting?.showBottomToolbar ? jsx(Fragment$1, { children: renderToolbarBottom() }) : jsx(Fragment$1, {})] }), pagingSetting?.allowPaging ? 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 }) : jsx(Fragment$1, {})] }), jsx(SidebarSetColumn, { handleSidebar: () => { setOpenPopupSetupColumn(!openPopupSetupColumn); }, openSidebar: openPopupSetupColumn, column: [...contentColumns], setColumn: setContentColumns })] }));
43327
+ return jsx(FooterCol, { col: col, indexCol: index, dataSource: dataSource, objWidthFix: objWidthFix, formatSetting: formatSetting });
43328
+ }) }) : jsx(Fragment$1, {}) })] }) }), toolbarSetting?.showBottomToolbar && jsx(ToolbarBottom, { handleAdd: () => {
43329
+ handleAdd(dataSource, tableElement.current, columnFistEdit, changeDataSource, pagingSetting, setItemFocus, focusNewElement);
43330
+ }, handleDuplicate: () => {
43331
+ handleDuplicate(dataSource, itemFocus, fieldKey, defaultValue, fieldUniKey, changeDataSource, tableElement, totalCount, toolbarSetting, buttonSetting, editDisable, addDisable, onDuplicate);
43332
+ }, handleInsertAfter: () => {
43333
+ handleInsertAfter(dataSource, itemFocus, defaultValue, changeDataSource, tableElement, totalCount, pagingClient, pagingSetting, toolbarSetting, buttonSetting, editDisable, addDisable);
43334
+ }, handleInsertBefore: () => {
43335
+ handleInsertBefore(dataSource, itemFocus, defaultValue, changeDataSource, pagingClient, pagingSetting, toolbarSetting, buttonSetting, editDisable, addDisable);
43336
+ }, handleDeleteAll: () => {
43337
+ handleDeleteAll(t, messageBoxConfirmDelete, setItemFocus, changeDataSource, editDisable, addDisable, toolbarSetting, buttonSetting);
43338
+ }, setOpenPopupSetupColumn: setOpenPopupSetupColumn, itemFocus: itemFocus, editDisable: editDisable, addDisable: addDisable, buttonSetting: buttonSetting, toolbarSetting: toolbarSetting, headerColumns: headerColumns, t: t })] }), pagingSetting?.allowPaging ? 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 }) : jsx(Fragment$1, {})] }), jsx(SidebarSetColumn, { handleSidebar: () => { setOpenPopupSetupColumn(!openPopupSetupColumn); }, openSidebar: openPopupSetupColumn, column: [...contentColumns], setColumn: setContentColumns })] }));
43144
43339
  });
43145
43340
 
43146
43341
  const TabsMenuComponent = ({ buttonWidth, tabParent, tabChild, resourceCodeParent, resources, resourceCode, windowSize, renderModal }) => {
@@ -64900,7 +65095,7 @@ const TabMergeImportExcel = (props) => {
64900
65095
  return jsx(Fragment$1, { children: data.isRequired ? jsx(SvgCheckSquare, { color: 'green', fontSize: 18 }) : jsx(SvgXSquare, { color: 'red', fontSize: 18 }) });
64901
65096
  },
64902
65097
  disabledCondition: (row) => {
64903
- return row.disableEdit;
65098
+ return row.disableEdit ?? false;
64904
65099
  },
64905
65100
  width: 80,
64906
65101
  minWidth: 80,
@@ -65475,5 +65670,5 @@ const ImportExcelComponent = (props) => {
65475
65670
  } }) }));
65476
65671
  };
65477
65672
 
65478
- export { ExportExcelComponent, ImportExcelComponent, InputStyleComponent, SelectTable, SelectTableTree, TabsMenuComponent, checkDecimalSeparator, checkThousandSeparator, TableEdit as default, formartNumberic, formatDateTime, generateUUID, isNullOrUndefined$1 as isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, roundNumber, useOnClickOutside };
65673
+ export { ExportExcelComponent, FindNodeByPath, ImportExcelComponent, InputStyleComponent, SelectTable, TabsMenuComponent, checkDecimalSeparator, checkThousandSeparator, TableEdit as default, formartNumberic, formatDateTime, generateUUID, isNullOrUndefined$1 as isNullOrUndefined, messageBoxConfirm, messageBoxConfirm2, messageBoxConfirmDelete, messageBoxError, messageHtmlBoxConfirm, messageHtmlBoxError, notificationError, notificationSuccess, roundNumber, useOnClickOutside };
65479
65674
  //# sourceMappingURL=index.mjs.map