react-table-edit 0.4.7 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -73,6 +73,11 @@ var ReactInput = (props) => {
73
73
  setValue("");
74
74
  setSearchTerm("");
75
75
  };
76
+ (0, import_react.useEffect)(() => {
77
+ if (!props.value) {
78
+ setValue("");
79
+ }
80
+ }, [props.value]);
76
81
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
77
82
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
78
83
  import_reactstrap.Input,
@@ -1530,13 +1535,13 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1530
1535
  const gridRef = (0, import_react12.useRef)();
1531
1536
  const lag = window.localStorage.getItem("i18nextLng");
1532
1537
  const lang = lag ? lag : "vi";
1538
+ let totalCount = dataSource.length;
1533
1539
  const pagingClient = pagingSetting?.allowPaging && (pagingSetting?.pagingClient || !(editDisable || addDisable));
1534
1540
  const searchClient = searchSetting?.searchEnable && (searchSetting?.searchClient || !(editDisable || addDisable));
1535
- let totalCount = dataSource.length;
1536
1541
  const fieldKey = columns.find((item) => item.isPrimarykey === true)?.field ?? "id";
1537
1542
  const fieldUniKey = columns.filter((item) => item.isUnikey === true)?.map((item) => item.field);
1538
1543
  (0, import_react12.useEffect)(() => {
1539
- if (pagingClient && pagingSetting.setCurrentPage && dataSource?.length / (pagingSetting?.pageSize ?? 1) > (pagingSetting.currentPage ?? 1)) {
1544
+ if (pagingClient && pagingSetting.setCurrentPage && Math.ceil(totalCount / (pagingSetting?.pageSize ?? 1)) < (pagingSetting.currentPage ?? 1)) {
1540
1545
  pagingSetting.setCurrentPage(1);
1541
1546
  }
1542
1547
  }, [dataSource]);
@@ -2143,6 +2148,25 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2143
2148
  );
2144
2149
  }) }) });
2145
2150
  };
2151
+ const focusNewElement = (col, row, onLoad = false) => {
2152
+ setTimeout(() => {
2153
+ const element = document.getElementById(`${idTable}-col${col}-row${row}`);
2154
+ if (element) {
2155
+ if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2156
+ element.getElementsByTagName("input")[0]?.focus();
2157
+ } else {
2158
+ element.focus();
2159
+ }
2160
+ if ((tableElement.current?.scrollHeight ?? 0) > 0) {
2161
+ if ((tableElement.current?.scrollTop ?? 0) > (row - 1) * 34) {
2162
+ tableElement.current?.scrollTo({ behavior: "smooth", top: (row - 1) * 34 });
2163
+ } else if ((tableElement.current?.clientHeight ?? 0) - (haveSum ? 30 : 0) - headerColumns.length * 42 < row * 34 - (tableElement.current?.scrollTop ?? 0)) {
2164
+ tableElement.current?.scrollTo({ behavior: "smooth", top: (tableElement.current?.scrollTop ?? 0) + 34 });
2165
+ }
2166
+ }
2167
+ }
2168
+ }, onLoad ? 100 : 0);
2169
+ };
2146
2170
  const moveIndexRowToNewPage = () => {
2147
2171
  changeDataSource(dataSource, true);
2148
2172
  if (pagingClient && pagingSetting?.setCurrentPage && totalCount % (pagingSetting?.pageSize ?? 0) === 0) {
@@ -2150,18 +2174,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2150
2174
  }
2151
2175
  if (tableElement) {
2152
2176
  setIndexFocus(totalCount);
2153
- setTimeout(() => {
2154
- tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
2155
- const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${totalCount + 1}`);
2156
- if (element) {
2157
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2158
- element.getElementsByTagName("input")[0]?.focus();
2159
- } else {
2160
- element.focus();
2161
- element.scrollIntoView();
2162
- }
2163
- }
2164
- }, 100);
2177
+ focusNewElement(columnFistEdit, totalCount + 1, true);
2165
2178
  }
2166
2179
  };
2167
2180
  const checkKeyDown = (e, row, col, indexRow, indexCol) => {
@@ -2174,14 +2187,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2174
2187
  }
2175
2188
  }
2176
2189
  if (newIndexCol > -1) {
2177
- const element = document.getElementById(`${idTable}-col${newIndexCol}-row${indexRow}`);
2178
- if (element) {
2179
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2180
- element.getElementsByTagName("input")[0]?.focus();
2181
- } else {
2182
- element.focus();
2183
- }
2184
- }
2190
+ focusNewElement(newIndexCol, indexRow);
2185
2191
  e.preventDefault();
2186
2192
  return e.code;
2187
2193
  }
@@ -2194,14 +2200,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2194
2200
  }
2195
2201
  }
2196
2202
  if (newIndexCol > -1) {
2197
- const element = document.getElementById(`${idTable}-col${newIndexCol}-row${indexRow}`);
2198
- if (element) {
2199
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2200
- element.getElementsByTagName("input")[0]?.focus();
2201
- } else {
2202
- element.focus();
2203
- }
2204
- }
2203
+ focusNewElement(newIndexCol, indexRow);
2205
2204
  e.preventDefault();
2206
2205
  return e.code;
2207
2206
  }
@@ -2213,16 +2212,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2213
2212
  pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) - 1);
2214
2213
  }
2215
2214
  setIndexFocus(indexRow - 2);
2216
- setTimeout(() => {
2217
- const element2 = document.getElementById(`${idTable}-col${indexCol}-row${indexRow - 1}`);
2218
- if (element2) {
2219
- if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
2220
- element2.getElementsByTagName("input")[0]?.focus();
2221
- } else {
2222
- element2.focus();
2223
- }
2224
- }
2225
- }, 100);
2215
+ focusNewElement(indexCol, indexRow - 1, true);
2226
2216
  e.preventDefault();
2227
2217
  return e.code;
2228
2218
  }
@@ -2235,16 +2225,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2235
2225
  pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
2236
2226
  }
2237
2227
  setIndexFocus(indexRow);
2238
- setTimeout(() => {
2239
- const element2 = document.getElementById(`${idTable}-col${indexCol}-row${indexRow + 1}`);
2240
- if (element2) {
2241
- if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
2242
- element2.getElementsByTagName("input")[0]?.focus();
2243
- } else {
2244
- element2.focus();
2245
- }
2246
- }
2247
- }, 100);
2228
+ focusNewElement(indexCol, indexRow + 1, true);
2248
2229
  e.preventDefault();
2249
2230
  return e.code;
2250
2231
  }
@@ -2257,16 +2238,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2257
2238
  pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
2258
2239
  }
2259
2240
  setIndexFocus(indexRow);
2260
- setTimeout(() => {
2261
- const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow + 1}`);
2262
- if (element) {
2263
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2264
- element.getElementsByTagName("input")[0]?.focus();
2265
- } else {
2266
- element.focus();
2267
- }
2268
- }
2269
- }, 100);
2241
+ focusNewElement(indexCol, indexRow + 1, true);
2270
2242
  }
2271
2243
  e.preventDefault();
2272
2244
  return e.code;
@@ -2280,16 +2252,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2280
2252
  pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
2281
2253
  }
2282
2254
  setIndexFocus(indexRow);
2283
- setTimeout(() => {
2284
- const element2 = document.getElementById(`${idTable}-col${indexCol}-row${indexRow + 1}`);
2285
- if (element2) {
2286
- if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
2287
- element2.getElementsByTagName("input")[0]?.focus();
2288
- } else {
2289
- element2.focus();
2290
- }
2291
- }
2292
- }, 100);
2255
+ focusNewElement(indexCol, indexRow + 1, true);
2293
2256
  }
2294
2257
  e.preventDefault();
2295
2258
  return e.code;
@@ -2329,23 +2292,14 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2329
2292
  }
2330
2293
  });
2331
2294
  const handleAdd = () => {
2295
+ const lengthData = dataSource.length;
2332
2296
  changeDataSource(dataSource, true);
2333
2297
  if (pagingSetting?.setCurrentPage) {
2334
- pagingSetting?.setCurrentPage(Math.floor(totalCount / (pagingSetting?.pageSize ?? 0)) + 1);
2298
+ pagingSetting?.setCurrentPage(Math.floor(lengthData / (pagingSetting?.pageSize ?? 0)) + 1);
2335
2299
  }
2336
2300
  if (tableElement) {
2337
- setIndexFocus(totalCount);
2338
- setTimeout(() => {
2339
- tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
2340
- const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${totalCount + 1}`);
2341
- if (element && !(element.getElementsByClassName("select__control--menu-is-open").length > 0 || element.getElementsByClassName("select-100__control--menu-is-open").length > 0 || element.getElementsByClassName("select-200__control--menu-is-open").length > 0 || element.getElementsByClassName("select-300__control--menu-is-open").length > 0 || element.getElementsByClassName("select-400__control--menu-is-open").length > 0 || element.getElementsByClassName("select-500__control--menu-is-open").length > 0)) {
2342
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2343
- element.getElementsByTagName("input")[0]?.focus();
2344
- } else {
2345
- element.focus();
2346
- }
2347
- }
2348
- }, 100);
2301
+ setIndexFocus(lengthData);
2302
+ focusNewElement(columnFistEdit, lengthData + 1, true);
2349
2303
  }
2350
2304
  };
2351
2305
  const handleDuplicate = (data, index) => {
@@ -2428,6 +2382,13 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2428
2382
  };
2429
2383
  const changeDataSource = (data, haveNew = false) => {
2430
2384
  if (!editDisable && !addDisable && setDataSource) {
2385
+ if (searchSetting?.searchTerm !== void 0 ? searchSetting?.searchTerm : searchTerm) {
2386
+ if (searchSetting?.setSearchTerm) {
2387
+ searchSetting?.setSearchTerm("");
2388
+ } else {
2389
+ setSearchTerm("");
2390
+ }
2391
+ }
2431
2392
  if (haveNew) {
2432
2393
  data.push(defaultValue ? { ...defaultValue, [fieldKey]: generateUUID() } : {});
2433
2394
  setDataSource([...data]);
@@ -2937,6 +2898,11 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2937
2898
  }
2938
2899
  });
2939
2900
  };
2901
+ (0, import_react12.useEffect)(() => {
2902
+ if (pagingClient && pagingSetting?.setCurrentPage && (searchSetting?.searchTerm !== void 0 ? searchSetting?.searchTerm : searchTerm)) {
2903
+ pagingSetting?.setCurrentPage(1);
2904
+ }
2905
+ }, [searchTerm, searchSetting?.searchTerm]);
2940
2906
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_react12.Fragment, { children: [
2941
2907
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "react-table-edit", children: [
2942
2908
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "r-grid", ref: gridRef, children: [
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // test-app/src/component/table/index.tsx
2
- import { Fragment as Fragment12, forwardRef as forwardRef2, useEffect as useEffect5, useImperativeHandle, useRef as useRef2, useState as useState5 } from "react";
2
+ import { Fragment as Fragment12, forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle, useRef as useRef2, useState as useState5 } from "react";
3
3
  import { Button as Button3, DropdownMenu as DropdownMenu2, DropdownToggle as DropdownToggle2, Input as Input6, UncontrolledDropdown } from "reactstrap";
4
4
  import classnames6 from "classnames";
5
5
  import { useTranslation as useTranslation8 } from "react-i18next";
@@ -11,7 +11,7 @@ import { AlertCircle, Info as Info2, Settings } from "becoxy-icons";
11
11
  // test-app/src/component/react-input/index.tsx
12
12
  import { X } from "becoxy-icons";
13
13
  import classNames from "classnames";
14
- import { Fragment, useState } from "react";
14
+ import { Fragment, useEffect, useState } from "react";
15
15
  import { Input } from "reactstrap";
16
16
  import { jsx, jsxs } from "react/jsx-runtime";
17
17
  var ReactInput = (props) => {
@@ -21,6 +21,11 @@ var ReactInput = (props) => {
21
21
  setValue("");
22
22
  setSearchTerm("");
23
23
  };
24
+ useEffect(() => {
25
+ if (!props.value) {
26
+ setValue("");
27
+ }
28
+ }, [props.value]);
24
29
  return /* @__PURE__ */ jsxs(Fragment, { children: [
25
30
  /* @__PURE__ */ jsx(
26
31
  Input,
@@ -178,9 +183,9 @@ var messageBoxConfirm2 = async (t, data, data2, message) => {
178
183
  };
179
184
 
180
185
  // test-app/src/component/utils.ts
181
- import { useEffect } from "react";
186
+ import { useEffect as useEffect2 } from "react";
182
187
  var useOnClickOutside = (ref, handler) => {
183
- useEffect(
188
+ useEffect2(
184
189
  () => {
185
190
  const listener = (event) => {
186
191
  if (!ref.current || ref.current.contains(event.target)) {
@@ -293,7 +298,7 @@ import moment from "moment";
293
298
  import { DropDownTreeComponent } from "@syncfusion/ej2-react-dropdowns";
294
299
 
295
300
  // test-app/src/component/edit-form/index.tsx
296
- import { forwardRef, useEffect as useEffect2, useRef, useState as useState2 } from "react";
301
+ import { forwardRef, useEffect as useEffect3, useRef, useState as useState2 } from "react";
297
302
  import {
298
303
  DropdownItem,
299
304
  DropdownMenu,
@@ -748,14 +753,14 @@ var EditForm = forwardRef((props, ref) => {
748
753
  defaultValues,
749
754
  resolver: yupResolver(schema)
750
755
  });
751
- useEffect2(() => {
756
+ useEffect3(() => {
752
757
  if (dropdownOpen) {
753
758
  if (onFormOpen && itemsField.length === 0) {
754
759
  onFormOpen(rowData, itemsField, setItemsField);
755
760
  }
756
761
  }
757
762
  }, [dropdownOpen]);
758
- useEffect2(() => {
763
+ useEffect3(() => {
759
764
  if (dropdownOpen && itemsField.length > 0) {
760
765
  itemsField.forEach((ele) => {
761
766
  setValue(ele.name, rowData[ele.name] ?? "");
@@ -1031,7 +1036,7 @@ var EditForm = forwardRef((props, ref) => {
1031
1036
  var edit_form_default = EditForm;
1032
1037
 
1033
1038
  // test-app/src/component/sidebar-setting-column/index.tsx
1034
- import { Fragment as Fragment10, useEffect as useEffect4, useState as useState4 } from "react";
1039
+ import { Fragment as Fragment10, useEffect as useEffect5, useState as useState4 } from "react";
1035
1040
  import { Button as Button2, Input as Input5 } from "reactstrap";
1036
1041
  import { useTranslation as useTranslation7 } from "react-i18next";
1037
1042
 
@@ -1082,7 +1087,7 @@ var modal_header_default = ModalHeader;
1082
1087
  // test-app/src/component/sidebar/index.tsx
1083
1088
  import { ChevronLeft, ChevronRight } from "becoxy-icons";
1084
1089
  import classNames4 from "classnames";
1085
- import { useEffect as useEffect3, useState as useState3 } from "react";
1090
+ import { useEffect as useEffect4, useState as useState3 } from "react";
1086
1091
  import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
1087
1092
  var Sidebar = (props) => {
1088
1093
  const {
@@ -1096,7 +1101,7 @@ var Sidebar = (props) => {
1096
1101
  } = props;
1097
1102
  const [isFullScreen, setIsFullScreen] = useState3(false);
1098
1103
  const [flag, setFlag] = useState3(open);
1099
- useEffect3(() => {
1104
+ useEffect4(() => {
1100
1105
  if (open !== flag) {
1101
1106
  if (open) {
1102
1107
  setFlag(open);
@@ -1191,7 +1196,7 @@ var SidebarSetColumn = (props) => {
1191
1196
  const { t } = useTranslation7();
1192
1197
  const [dataSource, setDataSource] = useState4([]);
1193
1198
  const [indexFocus, setIndexFocus] = useState4();
1194
- useEffect4(() => {
1199
+ useEffect5(() => {
1195
1200
  if (openSidebar) {
1196
1201
  setDataSource(column.map((e) => ({ ...e })));
1197
1202
  }
@@ -1209,7 +1214,7 @@ var SidebarSetColumn = (props) => {
1209
1214
  return { innerWidth, innerHeight };
1210
1215
  };
1211
1216
  const [windowSize, setWindowSize] = useState4(getWindowSize());
1212
- useEffect4(() => {
1217
+ useEffect5(() => {
1213
1218
  const handleWindowResize = () => {
1214
1219
  setWindowSize(getWindowSize());
1215
1220
  };
@@ -1488,17 +1493,17 @@ var TableEdit = forwardRef2((props, ref) => {
1488
1493
  const gridRef = useRef2();
1489
1494
  const lag = window.localStorage.getItem("i18nextLng");
1490
1495
  const lang = lag ? lag : "vi";
1496
+ let totalCount = dataSource.length;
1491
1497
  const pagingClient = pagingSetting?.allowPaging && (pagingSetting?.pagingClient || !(editDisable || addDisable));
1492
1498
  const searchClient = searchSetting?.searchEnable && (searchSetting?.searchClient || !(editDisable || addDisable));
1493
- let totalCount = dataSource.length;
1494
1499
  const fieldKey = columns.find((item) => item.isPrimarykey === true)?.field ?? "id";
1495
1500
  const fieldUniKey = columns.filter((item) => item.isUnikey === true)?.map((item) => item.field);
1496
- useEffect5(() => {
1497
- if (pagingClient && pagingSetting.setCurrentPage && dataSource?.length / (pagingSetting?.pageSize ?? 1) > (pagingSetting.currentPage ?? 1)) {
1501
+ useEffect6(() => {
1502
+ if (pagingClient && pagingSetting.setCurrentPage && Math.ceil(totalCount / (pagingSetting?.pageSize ?? 1)) < (pagingSetting.currentPage ?? 1)) {
1498
1503
  pagingSetting.setCurrentPage(1);
1499
1504
  }
1500
1505
  }, [dataSource]);
1501
- useEffect5(() => {
1506
+ useEffect6(() => {
1502
1507
  let indexFirst = -1;
1503
1508
  let indexlast = -1;
1504
1509
  let letfWidthFix = 0;
@@ -1531,7 +1536,7 @@ var TableEdit = forwardRef2((props, ref) => {
1531
1536
  setColumnFistEdit(indexFirst + 1);
1532
1537
  setColumnlastEdit(indexlast + 1);
1533
1538
  }, [contentColumns]);
1534
- useEffect5(() => {
1539
+ useEffect6(() => {
1535
1540
  const arrHeaderColumns = [];
1536
1541
  const arrContentColumns = [];
1537
1542
  let headerLevelRow = 0;
@@ -1548,7 +1553,7 @@ var TableEdit = forwardRef2((props, ref) => {
1548
1553
  setHeaderColumns(arrHeaderColumns);
1549
1554
  setContentColumns(arrContentColumns);
1550
1555
  }, [columns]);
1551
- useEffect5(() => {
1556
+ useEffect6(() => {
1552
1557
  const arrHeaderColumns = [];
1553
1558
  const arrContentColumns = [];
1554
1559
  let headerLevelRow = 0;
@@ -2101,6 +2106,25 @@ var TableEdit = forwardRef2((props, ref) => {
2101
2106
  );
2102
2107
  }) }) });
2103
2108
  };
2109
+ const focusNewElement = (col, row, onLoad = false) => {
2110
+ setTimeout(() => {
2111
+ const element = document.getElementById(`${idTable}-col${col}-row${row}`);
2112
+ if (element) {
2113
+ if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2114
+ element.getElementsByTagName("input")[0]?.focus();
2115
+ } else {
2116
+ element.focus();
2117
+ }
2118
+ if ((tableElement.current?.scrollHeight ?? 0) > 0) {
2119
+ if ((tableElement.current?.scrollTop ?? 0) > (row - 1) * 34) {
2120
+ tableElement.current?.scrollTo({ behavior: "smooth", top: (row - 1) * 34 });
2121
+ } else if ((tableElement.current?.clientHeight ?? 0) - (haveSum ? 30 : 0) - headerColumns.length * 42 < row * 34 - (tableElement.current?.scrollTop ?? 0)) {
2122
+ tableElement.current?.scrollTo({ behavior: "smooth", top: (tableElement.current?.scrollTop ?? 0) + 34 });
2123
+ }
2124
+ }
2125
+ }
2126
+ }, onLoad ? 100 : 0);
2127
+ };
2104
2128
  const moveIndexRowToNewPage = () => {
2105
2129
  changeDataSource(dataSource, true);
2106
2130
  if (pagingClient && pagingSetting?.setCurrentPage && totalCount % (pagingSetting?.pageSize ?? 0) === 0) {
@@ -2108,18 +2132,7 @@ var TableEdit = forwardRef2((props, ref) => {
2108
2132
  }
2109
2133
  if (tableElement) {
2110
2134
  setIndexFocus(totalCount);
2111
- setTimeout(() => {
2112
- tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
2113
- const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${totalCount + 1}`);
2114
- if (element) {
2115
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2116
- element.getElementsByTagName("input")[0]?.focus();
2117
- } else {
2118
- element.focus();
2119
- element.scrollIntoView();
2120
- }
2121
- }
2122
- }, 100);
2135
+ focusNewElement(columnFistEdit, totalCount + 1, true);
2123
2136
  }
2124
2137
  };
2125
2138
  const checkKeyDown = (e, row, col, indexRow, indexCol) => {
@@ -2132,14 +2145,7 @@ var TableEdit = forwardRef2((props, ref) => {
2132
2145
  }
2133
2146
  }
2134
2147
  if (newIndexCol > -1) {
2135
- const element = document.getElementById(`${idTable}-col${newIndexCol}-row${indexRow}`);
2136
- if (element) {
2137
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2138
- element.getElementsByTagName("input")[0]?.focus();
2139
- } else {
2140
- element.focus();
2141
- }
2142
- }
2148
+ focusNewElement(newIndexCol, indexRow);
2143
2149
  e.preventDefault();
2144
2150
  return e.code;
2145
2151
  }
@@ -2152,14 +2158,7 @@ var TableEdit = forwardRef2((props, ref) => {
2152
2158
  }
2153
2159
  }
2154
2160
  if (newIndexCol > -1) {
2155
- const element = document.getElementById(`${idTable}-col${newIndexCol}-row${indexRow}`);
2156
- if (element) {
2157
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2158
- element.getElementsByTagName("input")[0]?.focus();
2159
- } else {
2160
- element.focus();
2161
- }
2162
- }
2161
+ focusNewElement(newIndexCol, indexRow);
2163
2162
  e.preventDefault();
2164
2163
  return e.code;
2165
2164
  }
@@ -2171,16 +2170,7 @@ var TableEdit = forwardRef2((props, ref) => {
2171
2170
  pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) - 1);
2172
2171
  }
2173
2172
  setIndexFocus(indexRow - 2);
2174
- setTimeout(() => {
2175
- const element2 = document.getElementById(`${idTable}-col${indexCol}-row${indexRow - 1}`);
2176
- if (element2) {
2177
- if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
2178
- element2.getElementsByTagName("input")[0]?.focus();
2179
- } else {
2180
- element2.focus();
2181
- }
2182
- }
2183
- }, 100);
2173
+ focusNewElement(indexCol, indexRow - 1, true);
2184
2174
  e.preventDefault();
2185
2175
  return e.code;
2186
2176
  }
@@ -2193,16 +2183,7 @@ var TableEdit = forwardRef2((props, ref) => {
2193
2183
  pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
2194
2184
  }
2195
2185
  setIndexFocus(indexRow);
2196
- setTimeout(() => {
2197
- const element2 = document.getElementById(`${idTable}-col${indexCol}-row${indexRow + 1}`);
2198
- if (element2) {
2199
- if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
2200
- element2.getElementsByTagName("input")[0]?.focus();
2201
- } else {
2202
- element2.focus();
2203
- }
2204
- }
2205
- }, 100);
2186
+ focusNewElement(indexCol, indexRow + 1, true);
2206
2187
  e.preventDefault();
2207
2188
  return e.code;
2208
2189
  }
@@ -2215,16 +2196,7 @@ var TableEdit = forwardRef2((props, ref) => {
2215
2196
  pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
2216
2197
  }
2217
2198
  setIndexFocus(indexRow);
2218
- setTimeout(() => {
2219
- const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow + 1}`);
2220
- if (element) {
2221
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2222
- element.getElementsByTagName("input")[0]?.focus();
2223
- } else {
2224
- element.focus();
2225
- }
2226
- }
2227
- }, 100);
2199
+ focusNewElement(indexCol, indexRow + 1, true);
2228
2200
  }
2229
2201
  e.preventDefault();
2230
2202
  return e.code;
@@ -2238,16 +2210,7 @@ var TableEdit = forwardRef2((props, ref) => {
2238
2210
  pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
2239
2211
  }
2240
2212
  setIndexFocus(indexRow);
2241
- setTimeout(() => {
2242
- const element2 = document.getElementById(`${idTable}-col${indexCol}-row${indexRow + 1}`);
2243
- if (element2) {
2244
- if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
2245
- element2.getElementsByTagName("input")[0]?.focus();
2246
- } else {
2247
- element2.focus();
2248
- }
2249
- }
2250
- }, 100);
2213
+ focusNewElement(indexCol, indexRow + 1, true);
2251
2214
  }
2252
2215
  e.preventDefault();
2253
2216
  return e.code;
@@ -2287,23 +2250,14 @@ var TableEdit = forwardRef2((props, ref) => {
2287
2250
  }
2288
2251
  });
2289
2252
  const handleAdd = () => {
2253
+ const lengthData = dataSource.length;
2290
2254
  changeDataSource(dataSource, true);
2291
2255
  if (pagingSetting?.setCurrentPage) {
2292
- pagingSetting?.setCurrentPage(Math.floor(totalCount / (pagingSetting?.pageSize ?? 0)) + 1);
2256
+ pagingSetting?.setCurrentPage(Math.floor(lengthData / (pagingSetting?.pageSize ?? 0)) + 1);
2293
2257
  }
2294
2258
  if (tableElement) {
2295
- setIndexFocus(totalCount);
2296
- setTimeout(() => {
2297
- tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
2298
- const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${totalCount + 1}`);
2299
- if (element && !(element.getElementsByClassName("select__control--menu-is-open").length > 0 || element.getElementsByClassName("select-100__control--menu-is-open").length > 0 || element.getElementsByClassName("select-200__control--menu-is-open").length > 0 || element.getElementsByClassName("select-300__control--menu-is-open").length > 0 || element.getElementsByClassName("select-400__control--menu-is-open").length > 0 || element.getElementsByClassName("select-500__control--menu-is-open").length > 0)) {
2300
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2301
- element.getElementsByTagName("input")[0]?.focus();
2302
- } else {
2303
- element.focus();
2304
- }
2305
- }
2306
- }, 100);
2259
+ setIndexFocus(lengthData);
2260
+ focusNewElement(columnFistEdit, lengthData + 1, true);
2307
2261
  }
2308
2262
  };
2309
2263
  const handleDuplicate = (data, index) => {
@@ -2386,6 +2340,13 @@ var TableEdit = forwardRef2((props, ref) => {
2386
2340
  };
2387
2341
  const changeDataSource = (data, haveNew = false) => {
2388
2342
  if (!editDisable && !addDisable && setDataSource) {
2343
+ if (searchSetting?.searchTerm !== void 0 ? searchSetting?.searchTerm : searchTerm) {
2344
+ if (searchSetting?.setSearchTerm) {
2345
+ searchSetting?.setSearchTerm("");
2346
+ } else {
2347
+ setSearchTerm("");
2348
+ }
2349
+ }
2389
2350
  if (haveNew) {
2390
2351
  data.push(defaultValue ? { ...defaultValue, [fieldKey]: generateUUID() } : {});
2391
2352
  setDataSource([...data]);
@@ -2394,7 +2355,7 @@ var TableEdit = forwardRef2((props, ref) => {
2394
2355
  }
2395
2356
  }
2396
2357
  };
2397
- useEffect5(() => {
2358
+ useEffect6(() => {
2398
2359
  setIndexFocus(-1);
2399
2360
  if (setSelectedItem) {
2400
2361
  if (isMulti) {
@@ -2421,7 +2382,7 @@ var TableEdit = forwardRef2((props, ref) => {
2421
2382
  }
2422
2383
  }
2423
2384
  }, [selectedRows]);
2424
- useEffect5(() => {
2385
+ useEffect6(() => {
2425
2386
  if (!isMulti) {
2426
2387
  if (dataSource && selectedItem && selectedItem[fieldKey]) {
2427
2388
  if (selectedRows?.length === 0 || selectedItem[fieldKey] !== selectedRows[0][fieldKey]) {
@@ -2895,6 +2856,11 @@ var TableEdit = forwardRef2((props, ref) => {
2895
2856
  }
2896
2857
  });
2897
2858
  };
2859
+ useEffect6(() => {
2860
+ if (pagingClient && pagingSetting?.setCurrentPage && (searchSetting?.searchTerm !== void 0 ? searchSetting?.searchTerm : searchTerm)) {
2861
+ pagingSetting?.setCurrentPage(1);
2862
+ }
2863
+ }, [searchTerm, searchSetting?.searchTerm]);
2898
2864
  return /* @__PURE__ */ jsxs11(Fragment12, { children: [
2899
2865
  /* @__PURE__ */ jsxs11("div", { className: "react-table-edit", children: [
2900
2866
  /* @__PURE__ */ jsxs11("div", { className: "r-grid", ref: gridRef, children: [
@@ -2944,7 +2910,7 @@ var table_default = TableEdit;
2944
2910
  // test-app/src/component/tab-menu/index.tsx
2945
2911
  import { ChevronLeft as ChevronLeft2, ChevronRight as ChevronRight2 } from "becoxy-icons";
2946
2912
  import classNames5 from "classnames";
2947
- import { Fragment as Fragment14, useEffect as useEffect6, useState as useState6 } from "react";
2913
+ import { Fragment as Fragment14, useEffect as useEffect7, useState as useState6 } from "react";
2948
2914
  import { Link } from "react-router-dom";
2949
2915
  import { DropdownItem as DropdownItem2, DropdownMenu as DropdownMenu3, DropdownToggle as DropdownToggle3, UncontrolledDropdown as UncontrolledDropdown2 } from "reactstrap";
2950
2916
  import { jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
@@ -2970,7 +2936,7 @@ var TabsMenuComponent = ({
2970
2936
  setContentWidth(tabContent?.offsetWidth ?? 0);
2971
2937
  }
2972
2938
  };
2973
- useEffect6(() => {
2939
+ useEffect7(() => {
2974
2940
  setUrl(window.location.pathname);
2975
2941
  window.addEventListener("resize", handleWindowResize);
2976
2942
  setTimeout(() => {
@@ -2985,7 +2951,7 @@ var TabsMenuComponent = ({
2985
2951
  window.removeEventListener("resize", handleWindowResize);
2986
2952
  };
2987
2953
  }, []);
2988
- useEffect6(() => {
2954
+ useEffect7(() => {
2989
2955
  const item = resources?.find((x) => x.code === (resourceCodeParent ? resourceCodeParent : resourceCode));
2990
2956
  if (item) {
2991
2957
  if (resourceCodeParent) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-table-edit",
3
3
  "license": "MIT",
4
- "version": "0.4.7",
4
+ "version": "0.4.9",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",