react-table-edit 0.3.6 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1488,22 +1488,14 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1488
1488
  commandClick,
1489
1489
  dataSourceChange,
1490
1490
  rowChange,
1491
- allowPaging,
1492
- pageSize,
1493
- totalItem,
1494
- currentPage,
1495
- setCurrentPage,
1496
- setPageSize,
1491
+ pagingSetting,
1497
1492
  setDataSource,
1498
1493
  height,
1499
1494
  maxHeight,
1500
1495
  minHeight,
1501
1496
  defaultValue,
1502
1497
  haveSum,
1503
- toolbarOptions,
1504
- toolbarBottomOptions,
1505
- showTopToolbar,
1506
- showBottomToolbar,
1498
+ toolbarSetting,
1507
1499
  searchTerm,
1508
1500
  setSearchTerm,
1509
1501
  searchEnable,
@@ -1512,10 +1504,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1512
1504
  selectEnable,
1513
1505
  editDisable,
1514
1506
  addDisable,
1515
- deleteAllDisable,
1516
- insertAfterDisable,
1517
- insertBeforeDisable,
1518
- duplicateDisable,
1507
+ buttonSetting,
1519
1508
  decimalSeparator = ",",
1520
1509
  thousandSeparator = ".",
1521
1510
  handleSelect,
@@ -1536,13 +1525,42 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1536
1525
  const [columnLastEdit, setColumnlastEdit] = (0, import_react12.useState)(0);
1537
1526
  const [objWidthFix, setObjWidthFix] = (0, import_react12.useState)({});
1538
1527
  const [openPopupTree, setOpenPopupTree] = (0, import_react12.useState)(false);
1528
+ const [dataDisplay, setDataDisplay] = (0, import_react12.useState)([]);
1539
1529
  const [openPopupSetupColumn, setOpenPopupSetupColumn] = (0, import_react12.useState)(false);
1530
+ const [totalCount, setTotalCount] = (0, import_react12.useState)(0);
1540
1531
  const tableElement = (0, import_react12.useRef)(null);
1541
1532
  const gridRef = (0, import_react12.useRef)();
1542
1533
  const lag = window.localStorage.getItem("i18nextLng");
1543
1534
  const lang = lag ? lag : "vi";
1535
+ const pagingClient = pagingSetting?.allowPaging && !(editDisable || addDisable);
1544
1536
  const fieldKey = columns.find((item) => item.isPrimarykey === true)?.field ?? "id";
1545
1537
  const fieldUniKey = columns.filter((item) => item.isUnikey === true)?.map((item) => item.field);
1538
+ (0, import_react12.useEffect)(() => {
1539
+ if (pagingClient) {
1540
+ const length = dataSource.length;
1541
+ if (length > 0) {
1542
+ const arr = [];
1543
+ for (let i = (pagingSetting?.pageSize ?? 0) * ((pagingSetting?.currentPage ?? 0) - 1); i < dataSource.length && i < (pagingSetting?.pageSize ?? 0) * (pagingSetting?.currentPage ?? 0); i++) {
1544
+ arr.push(dataSource[i]);
1545
+ }
1546
+ setDataDisplay(arr);
1547
+ }
1548
+ setTotalCount(length);
1549
+ }
1550
+ }, [pagingSetting?.currentPage, pagingSetting?.pageSize]);
1551
+ (0, import_react12.useEffect)(() => {
1552
+ if (pagingClient && dataDisplay.length > 0) {
1553
+ const length = dataSource?.length ?? 0;
1554
+ if (length > 0) {
1555
+ const arr = [];
1556
+ for (let i = (pagingSetting?.pageSize ?? 0) * ((pagingSetting?.currentPage ?? 0) - 1); i < dataSource.length && i < (pagingSetting?.pageSize ?? 0) * (pagingSetting?.currentPage ?? 0); i++) {
1557
+ arr.push(dataSource[i]);
1558
+ }
1559
+ setDataDisplay(arr);
1560
+ }
1561
+ setTotalCount(length);
1562
+ }
1563
+ }, [dataSource]);
1546
1564
  (0, import_react12.useEffect)(() => {
1547
1565
  let indexFirst = -1;
1548
1566
  let indexlast = -1;
@@ -1648,7 +1666,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1648
1666
  }
1649
1667
  }
1650
1668
  }
1651
- changeDataSource(dataSource);
1669
+ changeDataSource(pagingClient ? dataDisplay : dataSource);
1652
1670
  if (dataSourceChange) {
1653
1671
  dataSourceChange(dataSource);
1654
1672
  }
@@ -1668,7 +1686,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1668
1686
  }
1669
1687
  }
1670
1688
  }
1671
- changeDataSource(dataSource);
1689
+ changeDataSource(pagingClient ? dataDisplay : dataSource);
1672
1690
  if (dataSourceChange) {
1673
1691
  dataSourceChange(dataSource);
1674
1692
  }
@@ -1695,8 +1713,8 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
1695
1713
  };
1696
1714
  const defaultToolbarOption = searchEnable === true ? [{ template: searchTemplate, align: "left" }] : [];
1697
1715
  let toolbarTopOption = [];
1698
- if (toolbarOptions) {
1699
- toolbarTopOption = [...defaultToolbarOption, ...toolbarOptions];
1716
+ if (toolbarSetting?.toolbarOptions) {
1717
+ toolbarTopOption = [...defaultToolbarOption, ...toolbarSetting?.toolbarOptions];
1700
1718
  } else {
1701
1719
  toolbarTopOption = [...defaultToolbarOption];
1702
1720
  }
@@ -2004,7 +2022,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2004
2022
  checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
2005
2023
  },
2006
2024
  onPaste: (e) => {
2007
- if (showBottomToolbar && !editDisable && !addDisable) {
2025
+ if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable) {
2008
2026
  pasteDataFromExcel(indexRow, indexCol);
2009
2027
  e.preventDefault();
2010
2028
  }
@@ -2086,7 +2104,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2086
2104
  checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
2087
2105
  },
2088
2106
  onPaste: (e) => {
2089
- if (showBottomToolbar && !editDisable && !addDisable) {
2107
+ if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable) {
2090
2108
  pasteDataFromExcel(indexRow, indexCol);
2091
2109
  e.preventDefault();
2092
2110
  }
@@ -2124,6 +2142,37 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2124
2142
  );
2125
2143
  }) }) });
2126
2144
  };
2145
+ const moveIndexRowToNewPage = (isUp, addIfLast = false) => {
2146
+ if (!isUp) {
2147
+ let index = 0;
2148
+ if (addIfLast) {
2149
+ if (!pagingSetting?.allowPaging || (pagingSetting?.pageSize ?? 0) * ((pagingSetting?.currentPage ?? 1) - 1) + dataDisplay.length >= dataSource.length) {
2150
+ changeDataSource(pagingClient ? dataDisplay : dataSource, true);
2151
+ }
2152
+ }
2153
+ if (pagingClient && dataDisplay.length > (pagingSetting?.pageSize ?? 0) && pagingSetting?.setCurrentPage) {
2154
+ pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 0) + 1);
2155
+ } else {
2156
+ index = dataDisplay.length - 1;
2157
+ }
2158
+ if (tableElement) {
2159
+ setIndexFocus(index);
2160
+ setTimeout(() => {
2161
+ tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
2162
+ const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${index + 1}`);
2163
+ if (element) {
2164
+ if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2165
+ element.getElementsByTagName("input")[0]?.focus();
2166
+ } else {
2167
+ element.focus();
2168
+ element.scrollIntoView();
2169
+ }
2170
+ }
2171
+ }, 100);
2172
+ }
2173
+ } else {
2174
+ }
2175
+ };
2127
2176
  const checkKeyDown = (e, row, col, indexRow, indexCol) => {
2128
2177
  if (e.code === "ArrowRight") {
2129
2178
  let newIndexCol = -1;
@@ -2145,8 +2194,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2145
2194
  e.preventDefault();
2146
2195
  return e.code;
2147
2196
  }
2148
- }
2149
- if (e.code === "ArrowLeft") {
2197
+ } else if (e.code === "ArrowLeft") {
2150
2198
  let newIndexCol = -1;
2151
2199
  for (let i = indexCol - 2; i >= 0; i--) {
2152
2200
  if (contentColumns[i].editEnable && contentColumns[i].visible !== false && (!contentColumns[i].disabledCondition || !contentColumns[i].disabledCondition(row))) {
@@ -2166,14 +2214,20 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2166
2214
  e.preventDefault();
2167
2215
  return e.code;
2168
2216
  }
2169
- }
2170
- if (e.code === "ArrowUp") {
2217
+ } else if (e.code === "ArrowUp") {
2171
2218
  const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
2172
2219
  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)) {
2220
+ let index = -1;
2173
2221
  if (indexRow > 1) {
2174
- setIndexFocus(indexRow - 2);
2222
+ index = indexRow - 2;
2223
+ } else if (pagingClient && (pagingSetting?.currentPage ?? 0) !== 1) {
2224
+ index = (pagingSetting?.pageSize ?? 0) - 1;
2225
+ pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) - 1);
2226
+ }
2227
+ if (index !== -1) {
2228
+ setIndexFocus(index);
2175
2229
  setTimeout(() => {
2176
- const element2 = document.getElementById(`${idTable}-col${indexCol}-row${indexRow - 1}`);
2230
+ const element2 = document.getElementById(`${idTable}-col${indexCol}-row${index + 1}`);
2177
2231
  if (element2) {
2178
2232
  if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
2179
2233
  element2.getElementsByTagName("input")[0]?.focus();
@@ -2186,14 +2240,20 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2186
2240
  return e.code;
2187
2241
  }
2188
2242
  }
2189
- }
2190
- if (e.code === "ArrowDown") {
2243
+ } else if (e.code === "ArrowDown") {
2191
2244
  const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
2192
2245
  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)) {
2193
- if (indexRow < dataSource?.length) {
2194
- setIndexFocus(indexRow);
2246
+ let index = -1;
2247
+ if (indexRow < dataDisplay.length) {
2248
+ index = indexRow;
2249
+ } else if (pagingClient && (pagingSetting?.currentPage ?? 1) * (pagingSetting?.pageSize ?? 0) < totalCount) {
2250
+ index = 0;
2251
+ pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
2252
+ }
2253
+ if (index !== -1) {
2254
+ setIndexFocus(index);
2195
2255
  setTimeout(() => {
2196
- const element2 = document.getElementById(`${idTable}-col${indexCol}-row${indexRow + 1}`);
2256
+ const element2 = document.getElementById(`${idTable}-col${indexCol}-row${index + 1}`);
2197
2257
  if (element2) {
2198
2258
  if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
2199
2259
  element2.getElementsByTagName("input")[0]?.focus();
@@ -2206,40 +2266,32 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2206
2266
  return e.code;
2207
2267
  }
2208
2268
  }
2209
- }
2210
- if (e.code === "Tab" && indexCol === columnLastEdit) {
2211
- if (indexRow === dataSource?.length) {
2212
- changeDataSource(dataSource, true);
2213
- if (tableElement) {
2214
- setTimeout(() => {
2215
- tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
2216
- }, 100);
2217
- }
2218
- if (!(!editDisable && !addDisable)) {
2219
- return false;
2220
- }
2221
- }
2222
- setIndexFocus(indexRow);
2223
- setTimeout(() => {
2224
- const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${indexRow + 1}`);
2225
- if (element) {
2226
- if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2227
- element.getElementsByTagName("input")[0]?.focus();
2228
- } else {
2229
- element.focus();
2230
- element.scrollIntoView();
2269
+ } else if (e.code === "Tab" && indexCol === columnLastEdit) {
2270
+ if (indexRow === dataDisplay.length) {
2271
+ moveIndexRowToNewPage(false, true);
2272
+ } else {
2273
+ setIndexFocus(indexRow);
2274
+ setTimeout(() => {
2275
+ const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${indexRow + 1}`);
2276
+ if (element) {
2277
+ if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2278
+ element.getElementsByTagName("input")[0]?.focus();
2279
+ } else {
2280
+ element.focus();
2281
+ }
2231
2282
  }
2232
- }
2233
- }, 100);
2283
+ }, 100);
2284
+ }
2234
2285
  e.preventDefault();
2235
- }
2236
- if ((e.code === "Enter" || e.code === "NumpadEnter") && (!editDisable && !addDisable)) {
2286
+ } else if ((e.code === "Enter" || e.code === "NumpadEnter") && (!editDisable && !addDisable)) {
2237
2287
  const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
2238
2288
  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)) {
2239
- if (indexRow < dataSource?.length) {
2289
+ if (indexRow === dataDisplay.length) {
2290
+ moveIndexRowToNewPage(false, true);
2291
+ } else {
2240
2292
  setIndexFocus(indexRow);
2241
2293
  setTimeout(() => {
2242
- const element2 = document.getElementById(`${idTable}-col${indexCol}-row${indexRow + 1}`);
2294
+ const element2 = document.getElementById(`${idTable}-col${columnFistEdit}-row${indexRow + 1}`);
2243
2295
  if (element2) {
2244
2296
  if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
2245
2297
  element2.getElementsByTagName("input")[0]?.focus();
@@ -2248,14 +2300,11 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2248
2300
  }
2249
2301
  }
2250
2302
  }, 100);
2251
- } else {
2252
- handleAdd();
2253
2303
  }
2254
2304
  e.preventDefault();
2255
2305
  return e.code;
2256
2306
  }
2257
- }
2258
- if (e.code === "KeyD" && e.ctrlKey == true && (!editDisable && !addDisable)) {
2307
+ } else if (e.code === "KeyD" && e.ctrlKey == true && (!editDisable && !addDisable)) {
2259
2308
  handleDuplicate(dataSource[indexFocus ?? -1], indexRow);
2260
2309
  e.preventDefault();
2261
2310
  return e.code;
@@ -2263,16 +2312,22 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2263
2312
  return "";
2264
2313
  };
2265
2314
  const onChangePage = (args) => {
2266
- if (args.newProp.currentPage === args.oldProp.currentPage) {
2267
- return;
2315
+ if (pagingSetting?.setCurrentPage) {
2316
+ if (args.newProp.currentPage === args.oldProp.currentPage) {
2317
+ return;
2318
+ }
2319
+ pagingSetting.setCurrentPage(args.currentPage);
2268
2320
  }
2269
- setCurrentPage(args.currentPage);
2270
2321
  };
2271
2322
  const onChangePageSize = (args) => {
2272
- if (allowPaging) {
2273
- if (pageSize !== args.pageSize) {
2274
- setPageSize(args.pageSize);
2275
- setCurrentPage(1);
2323
+ if (pagingSetting?.allowPaging) {
2324
+ if (pagingSetting?.pageSize !== args.pageSize) {
2325
+ if (pagingSetting?.setPageSize) {
2326
+ pagingSetting.setPageSize(args.pageSize);
2327
+ }
2328
+ if (pagingSetting?.setCurrentPage) {
2329
+ pagingSetting.setCurrentPage(1);
2330
+ }
2276
2331
  }
2277
2332
  }
2278
2333
  };
@@ -2284,12 +2339,18 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2284
2339
  }
2285
2340
  });
2286
2341
  const handleAdd = () => {
2287
- changeDataSource(dataSource, true);
2342
+ changeDataSource(pagingClient ? dataDisplay : dataSource, true);
2343
+ let index = 0;
2344
+ if (pagingClient && dataDisplay.length > (pagingSetting?.pageSize ?? 0) && pagingSetting?.setCurrentPage) {
2345
+ pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 0) + 1);
2346
+ } else {
2347
+ index = dataDisplay.length - 1;
2348
+ }
2288
2349
  if (tableElement) {
2289
- setIndexFocus(dataSource?.length);
2350
+ setIndexFocus(index);
2290
2351
  setTimeout(() => {
2291
2352
  tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
2292
- const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${dataSource?.length + 1}`);
2353
+ const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${index + 1}`);
2293
2354
  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)) {
2294
2355
  if (element.className.includes("react-select") || element.className.includes("form-edit")) {
2295
2356
  element.getElementsByTagName("input")[0]?.focus();
@@ -2300,26 +2361,24 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2300
2361
  }, 100);
2301
2362
  }
2302
2363
  };
2303
- const deleteAll = () => {
2304
- if (!editDisable && !addDisable) {
2305
- setIndexFocus(-1);
2306
- changeDataSource([], false);
2307
- }
2308
- };
2309
2364
  const handleDuplicate = (data, index) => {
2310
- if (showBottomToolbar && !editDisable && !addDisable) {
2365
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.duplicateDisable && !editDisable && !addDisable) {
2311
2366
  if (fieldKey) {
2312
- const newdata = { ...data };
2313
2367
  fieldUniKey.forEach((item) => {
2314
- newdata[item] = defaultValue[item];
2368
+ data[item] = defaultValue[item];
2315
2369
  });
2316
- newdata[fieldKey] = defaultValue[fieldKey];
2317
- dataSource?.splice(index, 0, newdata);
2370
+ data[fieldKey] = defaultValue[fieldKey];
2371
+ }
2372
+ if (pagingClient) {
2373
+ if (dataDisplay.length < (pagingSetting?.pageSize ?? 0)) {
2374
+ dataDisplay.splice(index, 0, data);
2375
+ }
2376
+ dataSource.splice(((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + index, 0, { ...data });
2318
2377
  } else {
2319
- dataSource?.splice(index, 0, { ...data });
2378
+ dataSource.splice(index, 0, data);
2320
2379
  }
2321
- changeDataSource(dataSource);
2322
- if (tableElement && index === dataSource?.length) {
2380
+ changeDataSource(pagingClient ? dataDisplay : dataSource);
2381
+ if (tableElement && index === (pagingClient ? dataDisplay.length : dataSource.length)) {
2323
2382
  setTimeout(() => {
2324
2383
  tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
2325
2384
  }, 100);
@@ -2327,10 +2386,17 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2327
2386
  }
2328
2387
  };
2329
2388
  const handleInsertAfter = () => {
2330
- if (showBottomToolbar && !editDisable && !addDisable) {
2331
- dataSource?.splice((indexFocus ?? -1) + 1, 0, { ...defaultValue });
2332
- changeDataSource(dataSource);
2333
- if (tableElement && indexFocus === dataSource?.length) {
2389
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertAfterDisable && !editDisable && !addDisable) {
2390
+ if (pagingClient) {
2391
+ if (dataDisplay.length < (pagingSetting?.pageSize ?? 0)) {
2392
+ dataDisplay.splice((indexFocus ?? -1) + 1, 0, { ...defaultValue });
2393
+ }
2394
+ dataSource.splice(((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + (indexFocus ?? -1) + 1, 0, { ...{ ...defaultValue } });
2395
+ } else {
2396
+ dataSource.splice((indexFocus ?? -1) + 1, 0, { ...defaultValue });
2397
+ }
2398
+ changeDataSource(pagingClient ? dataDisplay : dataSource);
2399
+ if (tableElement && indexFocus === dataSource.length) {
2334
2400
  setTimeout(() => {
2335
2401
  tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
2336
2402
  }, 100);
@@ -2338,16 +2404,29 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2338
2404
  }
2339
2405
  };
2340
2406
  const handleInsertBefore = () => {
2341
- if (showBottomToolbar && !editDisable && !addDisable) {
2342
- dataSource?.splice(indexFocus ?? -1, 0, { ...defaultValue });
2343
- changeDataSource(dataSource);
2407
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertBeforeDisable && !editDisable && !addDisable) {
2408
+ if (pagingClient) {
2409
+ if (dataDisplay.length < (pagingSetting?.pageSize ?? 0)) {
2410
+ dataDisplay.splice(indexFocus ?? -1, 0, { ...defaultValue });
2411
+ }
2412
+ dataSource.splice(((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + (indexFocus ?? -1), 0, { ...{ ...defaultValue } });
2413
+ } else {
2414
+ dataSource.splice(indexFocus ?? -1, 0, { ...defaultValue });
2415
+ }
2416
+ changeDataSource(pagingClient ? dataDisplay : dataSource);
2344
2417
  }
2345
2418
  };
2346
2419
  const handleDeleteAll = () => {
2347
- if (showBottomToolbar && !editDisable && !addDisable) {
2420
+ if (toolbarSetting?.showBottomToolbar && !buttonSetting?.deleteAllDisable && !editDisable && !addDisable) {
2348
2421
  messageBoxConfirmDelete(t, deleteAll, "");
2349
2422
  }
2350
2423
  };
2424
+ const deleteAll = () => {
2425
+ if (!editDisable && !addDisable) {
2426
+ setIndexFocus(-1);
2427
+ changeDataSource([], false);
2428
+ }
2429
+ };
2351
2430
  const pasteDataFromExcel = async (row, col) => {
2352
2431
  const clipboard = await navigator.clipboard.readText();
2353
2432
  const arrayRow = clipboard.trimEnd().split("\n");
@@ -2356,7 +2435,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2356
2435
  let dataRow = dataSource[row + indexRow];
2357
2436
  if (!dataRow) {
2358
2437
  dataRow = { ...defaultValue };
2359
- dataSource?.push(dataRow);
2438
+ dataSource.push(dataRow);
2360
2439
  }
2361
2440
  arrayCol.forEach((element, index) => {
2362
2441
  const column = contentColumns[col + index];
@@ -2367,15 +2446,31 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2367
2446
  rowChange(dataRow, row + indexRow, "");
2368
2447
  });
2369
2448
  handleRefeshRow();
2370
- changeDataSource(dataSource);
2449
+ changeDataSource(pagingClient ? dataDisplay : dataSource);
2371
2450
  };
2372
2451
  const changeDataSource = (data, haveNew = false) => {
2373
- if (!editDisable && !addDisable && setDataSource) {
2374
- if (haveNew) {
2375
- data.push(defaultValue ? { ...defaultValue, [fieldKey]: generateUUID() } : {});
2452
+ if (data.length === 0 && !haveNew) {
2453
+ setDataDisplay([]);
2454
+ setDataSource([]);
2455
+ } else if (!editDisable && !addDisable && setDataSource) {
2456
+ if (pagingClient) {
2457
+ if (haveNew) {
2458
+ data.push(defaultValue ? { ...defaultValue, [fieldKey]: generateUUID() } : {});
2459
+ setDataDisplay(data);
2460
+ dataSource.push(defaultValue ? { ...defaultValue, [fieldKey]: generateUUID() } : {});
2461
+ } else {
2462
+ setDataDisplay([...data]);
2463
+ }
2464
+ setTotalCount(dataSource?.length ?? 0);
2465
+ } else {
2466
+ if (haveNew) {
2467
+ data.push(defaultValue ? { ...defaultValue, [fieldKey]: generateUUID() } : {});
2468
+ setDataSource([...data]);
2469
+ } else {
2470
+ setDataSource([...data]);
2471
+ }
2376
2472
  }
2377
2473
  }
2378
- setDataSource([...data]);
2379
2474
  };
2380
2475
  (0, import_react12.useEffect)(() => {
2381
2476
  setIndexFocus(-1);
@@ -2459,11 +2554,18 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2459
2554
  onPaste: (e) => {
2460
2555
  if (!editDisable && (e.target.nodeName === "DIV" || e.target.nodeName === "TD")) {
2461
2556
  navigator.clipboard.readText().then((rs) => {
2462
- dataSource[indexRow] = JSON.parse(rs);
2463
- if (fieldKey) {
2464
- dataSource[indexRow][fieldKey] = defaultValue[fieldKey];
2557
+ if (pagingClient) {
2558
+ dataDisplay[indexRow] = JSON.parse(rs);
2559
+ if (fieldKey) {
2560
+ dataDisplay[indexRow][fieldKey] = defaultValue[fieldKey];
2561
+ }
2562
+ } else {
2563
+ dataSource[indexRow] = JSON.parse(rs);
2564
+ if (fieldKey) {
2565
+ dataSource[indexRow][fieldKey] = defaultValue[fieldKey];
2566
+ }
2465
2567
  }
2466
- changeDataSource(dataSource);
2568
+ changeDataSource(pagingClient ? dataDisplay : dataSource);
2467
2569
  notificationSuccess(t("PasteSuccessful"));
2468
2570
  }).catch((ex) => {
2469
2571
  alert(ex);
@@ -2670,17 +2772,22 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2670
2772
  children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2671
2773
  import_reactstrap8.Input,
2672
2774
  {
2673
- checked: selectedRows?.length >= dataSource?.length && dataSource?.length > 0,
2775
+ checked: (pagingClient ? dataDisplay.length > 0 : dataSource.length > 0) && selectedRows?.length >= (pagingClient ? dataDisplay.length : dataSource.length),
2674
2776
  type: "checkbox",
2675
2777
  className: (0, import_classnames10.default)("cursor-pointer", { "d-none": !isMulti }),
2676
2778
  style: { textAlign: col.textAlign ?? "left", marginTop: 6 },
2677
2779
  onChange: (e) => {
2678
2780
  if (selectEnable) {
2679
2781
  if (e.target.checked) {
2680
- const arr = dataSource?.map((item) => {
2681
- return item;
2682
- });
2683
- setSelectedRows(arr);
2782
+ if (pagingClient) {
2783
+ setSelectedRows(dataDisplay.map((item) => {
2784
+ return item;
2785
+ }));
2786
+ } else {
2787
+ setSelectedRows(dataSource.map((item) => {
2788
+ return item;
2789
+ }));
2790
+ }
2684
2791
  } else {
2685
2792
  setSelectedRows([]);
2686
2793
  }
@@ -2787,7 +2894,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2787
2894
  maxWidth: col.maxWidth,
2788
2895
  textAlign: col.textAlign ? col.textAlign : "left"
2789
2896
  },
2790
- children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "r-footer-div", children: col.haveSum === true && col.editType === "numeric" ? formartNumberic(dataSource?.reduce(function(accumulator, currentValue) {
2897
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "r-footer-div", children: col.haveSum === true && col.editType === "numeric" ? formartNumberic(dataSource.reduce(function(accumulator, currentValue) {
2791
2898
  return Number(accumulator ?? 0) + Number(currentValue[col.field] ?? 0);
2792
2899
  }, 0), decimalSeparator, thousandSeparator, col.numericSettings?.fraction, true) : "" })
2793
2900
  }
@@ -2811,22 +2918,22 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2811
2918
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "r-toolbar-left", children: [
2812
2919
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames10.default)("r-toolbar-item", { "d-none": editDisable || addDisable }), "aria-disabled": "false", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_reactstrap8.Button, { color: "success", outline: true, onClick: handleAdd, className: "d-flex", children: t("Add item") }) }),
2813
2920
  (indexFocus ?? -1) > -1 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
2814
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames10.default)("r-toolbar-item", { "d-none": editDisable || addDisable || duplicateDisable }), "aria-disabled": "false", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_reactstrap8.Button, { color: "success", outline: true, onClick: () => {
2815
- handleDuplicate(dataSource[indexFocus ?? -1], indexFocus ?? -1);
2921
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames10.default)("r-toolbar-item", { "d-none": editDisable || addDisable || buttonSetting?.duplicateDisable }), "aria-disabled": "false", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_reactstrap8.Button, { color: "success", outline: true, onClick: () => {
2922
+ handleDuplicate(pagingClient ? dataDisplay[indexFocus ?? -1] : dataSource[indexFocus ?? -1], indexFocus ?? -1);
2816
2923
  }, className: "d-flex", children: t("Duplicate") }) }),
2817
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames10.default)("r-toolbar-item", { "d-none": editDisable || addDisable || insertBeforeDisable }), "aria-disabled": "false", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_reactstrap8.Button, { color: "success", outline: true, onClick: handleInsertBefore, className: "d-flex", children: t("Insert item before") }) }),
2818
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames10.default)("r-toolbar-item", { "d-none": editDisable || addDisable || insertAfterDisable }), "aria-disabled": "false", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_reactstrap8.Button, { color: "success", outline: true, onClick: handleInsertAfter, className: "d-flex", children: t("Insert item after") }) })
2924
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames10.default)("r-toolbar-item", { "d-none": editDisable || addDisable || buttonSetting?.insertBeforeDisable }), "aria-disabled": "false", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_reactstrap8.Button, { color: "success", outline: true, onClick: handleInsertBefore, className: "d-flex", children: t("Insert item before") }) }),
2925
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames10.default)("r-toolbar-item", { "d-none": editDisable || addDisable || buttonSetting?.insertAfterDisable }), "aria-disabled": "false", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_reactstrap8.Button, { color: "success", outline: true, onClick: handleInsertAfter, className: "d-flex", children: t("Insert item after") }) })
2819
2926
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: " " }),
2820
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames10.default)("r-toolbar-item", { "d-none": editDisable || deleteAllDisable }), "aria-disabled": "false", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_reactstrap8.Button, { color: "primary", outline: true, onClick: handleDeleteAll, className: "d-flex", children: t("Delete all item") }) }),
2821
- toolbarBottomOptions?.map((item, index) => {
2927
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames10.default)("r-toolbar-item", { "d-none": editDisable || buttonSetting?.deleteAllDisable }), "aria-disabled": "false", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_reactstrap8.Button, { color: "primary", outline: true, onClick: handleDeleteAll, className: "d-flex", children: t("Delete all item") }) }),
2928
+ toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
2822
2929
  return item.align === "left" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-left-${index}`) : "";
2823
2930
  })
2824
2931
  ] }),
2825
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "r-toolbar-center", children: toolbarBottomOptions?.map((item, index) => {
2932
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "r-toolbar-center", children: toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
2826
2933
  return item.align === "center" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-center-${index}`) : "";
2827
2934
  }) }),
2828
2935
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "r-toolbar-right", children: [
2829
- toolbarBottomOptions?.map((item, index) => {
2936
+ toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
2830
2937
  return item.align === "right" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-right-${index}`) : "";
2831
2938
  }),
2832
2939
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: (0, import_classnames10.default)("r-toolbar-item me-25", { "d-none": headerColumns.length > 1 }), "aria-disabled": "false", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_becoxy_icons4.Settings, { className: "text-primary cursor-pointer", onClick: () => setOpenPopupSetupColumn(true) }) }),
@@ -2845,19 +2952,31 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2845
2952
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_react12.Fragment, { children: [
2846
2953
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "react-table-edit", children: [
2847
2954
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "r-grid", ref: gridRef, children: [
2848
- showTopToolbar ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: renderToolbarTop() }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, {}),
2955
+ toolbarSetting?.showTopToolbar ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: renderToolbarTop() }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, {}),
2849
2956
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { ref: tableElement, className: "r-gridtable", style: { height: `${height ? `${height}px` : "auto"}`, minHeight: `${minHeight ? `${minHeight}px` : ""}`, maxHeight: `${maxHeight ? `${maxHeight}px` : "400px"}` }, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("table", { style: { width: "100%" }, children: [
2850
2957
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("thead", { className: "r-gridheader", children: headerColumns.map((element, indexParent) => {
2851
2958
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tr", { className: "r-row", role: "row", children: element?.map((col, index) => {
2852
2959
  return renderHeaderCol(col, index, indexParent);
2853
2960
  }) }, indexParent);
2854
2961
  }) }),
2855
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tbody", { className: "r-gridcontent", children: dataSource?.map((row, indexRow) => {
2962
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tbody", { className: "r-gridcontent", children: pagingClient ? dataDisplay.map((row, indexRow) => {
2963
+ const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
2964
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2965
+ "tr",
2966
+ {
2967
+ className: (0, import_classnames10.default)("r-row", { "last-row": indexRow === dataDisplay.length - 1 }, { "fisrt-row": indexRow === 0 }),
2968
+ children: contentColumns.map((col, indexCol) => {
2969
+ return renderContentCol(col, row, indexRow, indexCol, isSelected);
2970
+ })
2971
+ },
2972
+ `row-${indexRow}`
2973
+ );
2974
+ }) : dataSource.map((row, indexRow) => {
2856
2975
  const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
2857
2976
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2858
2977
  "tr",
2859
2978
  {
2860
- className: (0, import_classnames10.default)("r-row", { "last-row": indexRow === dataSource.length - 1 }, { "fisrt-row": indexRow === 0 }),
2979
+ className: (0, import_classnames10.default)("r-row", { "last-row": indexRow === dataDisplay.length - 1 }, { "fisrt-row": indexRow === 0 }),
2861
2980
  children: contentColumns.map((col, indexCol) => {
2862
2981
  return renderContentCol(col, row, indexRow, indexCol, isSelected);
2863
2982
  })
@@ -2869,17 +2988,17 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
2869
2988
  return renderFooterCol(col, index);
2870
2989
  }) }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, {}) })
2871
2990
  ] }) }),
2872
- showBottomToolbar ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: renderToolbarBottom() }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, {})
2991
+ toolbarSetting?.showBottomToolbar ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: renderToolbarBottom() }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, {})
2873
2992
  ] }),
2874
- allowPaging ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2993
+ pagingSetting?.allowPaging ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2875
2994
  import_ej2_react_grids.PagerComponent,
2876
2995
  {
2877
2996
  locale: lang,
2878
2997
  click: onChangePage,
2879
- pageSize,
2880
- currentPage,
2998
+ pageSize: pagingSetting?.pageSize,
2999
+ currentPage: pagingSetting?.currentPage,
2881
3000
  pageSizes: [20, 30, 50, 100],
2882
- totalRecordsCount: totalItem ? totalItem : void 0,
3001
+ totalRecordsCount: pagingClient ? totalCount : pagingSetting?.totalItem ?? 0,
2883
3002
  pageCount: 5,
2884
3003
  dropDownChanged: onChangePageSize
2885
3004
  }