react-table-edit 0.3.5 → 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.d.mts +27 -18
- package/dist/index.d.ts +27 -18
- package/dist/index.js +246 -127
- package/dist/index.mjs +246 -127
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1447,22 +1447,14 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
1447
1447
|
commandClick,
|
|
1448
1448
|
dataSourceChange,
|
|
1449
1449
|
rowChange,
|
|
1450
|
-
|
|
1451
|
-
pageSize,
|
|
1452
|
-
totalItem,
|
|
1453
|
-
currentPage,
|
|
1454
|
-
setCurrentPage,
|
|
1455
|
-
setPageSize,
|
|
1450
|
+
pagingSetting,
|
|
1456
1451
|
setDataSource,
|
|
1457
1452
|
height,
|
|
1458
1453
|
maxHeight,
|
|
1459
1454
|
minHeight,
|
|
1460
1455
|
defaultValue,
|
|
1461
1456
|
haveSum,
|
|
1462
|
-
|
|
1463
|
-
toolbarBottomOptions,
|
|
1464
|
-
showTopToolbar,
|
|
1465
|
-
showBottomToolbar,
|
|
1457
|
+
toolbarSetting,
|
|
1466
1458
|
searchTerm,
|
|
1467
1459
|
setSearchTerm,
|
|
1468
1460
|
searchEnable,
|
|
@@ -1471,10 +1463,7 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
1471
1463
|
selectEnable,
|
|
1472
1464
|
editDisable,
|
|
1473
1465
|
addDisable,
|
|
1474
|
-
|
|
1475
|
-
insertAfterDisable,
|
|
1476
|
-
insertBeforeDisable,
|
|
1477
|
-
duplicateDisable,
|
|
1466
|
+
buttonSetting,
|
|
1478
1467
|
decimalSeparator = ",",
|
|
1479
1468
|
thousandSeparator = ".",
|
|
1480
1469
|
handleSelect,
|
|
@@ -1495,13 +1484,42 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
1495
1484
|
const [columnLastEdit, setColumnlastEdit] = useState5(0);
|
|
1496
1485
|
const [objWidthFix, setObjWidthFix] = useState5({});
|
|
1497
1486
|
const [openPopupTree, setOpenPopupTree] = useState5(false);
|
|
1487
|
+
const [dataDisplay, setDataDisplay] = useState5([]);
|
|
1498
1488
|
const [openPopupSetupColumn, setOpenPopupSetupColumn] = useState5(false);
|
|
1489
|
+
const [totalCount, setTotalCount] = useState5(0);
|
|
1499
1490
|
const tableElement = useRef2(null);
|
|
1500
1491
|
const gridRef = useRef2();
|
|
1501
1492
|
const lag = window.localStorage.getItem("i18nextLng");
|
|
1502
1493
|
const lang = lag ? lag : "vi";
|
|
1494
|
+
const pagingClient = pagingSetting?.allowPaging && !(editDisable || addDisable);
|
|
1503
1495
|
const fieldKey = columns.find((item) => item.isPrimarykey === true)?.field ?? "id";
|
|
1504
1496
|
const fieldUniKey = columns.filter((item) => item.isUnikey === true)?.map((item) => item.field);
|
|
1497
|
+
useEffect5(() => {
|
|
1498
|
+
if (pagingClient) {
|
|
1499
|
+
const length = dataSource.length;
|
|
1500
|
+
if (length > 0) {
|
|
1501
|
+
const arr = [];
|
|
1502
|
+
for (let i = (pagingSetting?.pageSize ?? 0) * ((pagingSetting?.currentPage ?? 0) - 1); i < dataSource.length && i < (pagingSetting?.pageSize ?? 0) * (pagingSetting?.currentPage ?? 0); i++) {
|
|
1503
|
+
arr.push(dataSource[i]);
|
|
1504
|
+
}
|
|
1505
|
+
setDataDisplay(arr);
|
|
1506
|
+
}
|
|
1507
|
+
setTotalCount(length);
|
|
1508
|
+
}
|
|
1509
|
+
}, [pagingSetting?.currentPage, pagingSetting?.pageSize]);
|
|
1510
|
+
useEffect5(() => {
|
|
1511
|
+
if (pagingClient && dataDisplay.length > 0) {
|
|
1512
|
+
const length = dataSource?.length ?? 0;
|
|
1513
|
+
if (length > 0) {
|
|
1514
|
+
const arr = [];
|
|
1515
|
+
for (let i = (pagingSetting?.pageSize ?? 0) * ((pagingSetting?.currentPage ?? 0) - 1); i < dataSource.length && i < (pagingSetting?.pageSize ?? 0) * (pagingSetting?.currentPage ?? 0); i++) {
|
|
1516
|
+
arr.push(dataSource[i]);
|
|
1517
|
+
}
|
|
1518
|
+
setDataDisplay(arr);
|
|
1519
|
+
}
|
|
1520
|
+
setTotalCount(length);
|
|
1521
|
+
}
|
|
1522
|
+
}, [dataSource]);
|
|
1505
1523
|
useEffect5(() => {
|
|
1506
1524
|
let indexFirst = -1;
|
|
1507
1525
|
let indexlast = -1;
|
|
@@ -1607,7 +1625,7 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
1607
1625
|
}
|
|
1608
1626
|
}
|
|
1609
1627
|
}
|
|
1610
|
-
changeDataSource(dataSource);
|
|
1628
|
+
changeDataSource(pagingClient ? dataDisplay : dataSource);
|
|
1611
1629
|
if (dataSourceChange) {
|
|
1612
1630
|
dataSourceChange(dataSource);
|
|
1613
1631
|
}
|
|
@@ -1627,7 +1645,7 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
1627
1645
|
}
|
|
1628
1646
|
}
|
|
1629
1647
|
}
|
|
1630
|
-
changeDataSource(dataSource);
|
|
1648
|
+
changeDataSource(pagingClient ? dataDisplay : dataSource);
|
|
1631
1649
|
if (dataSourceChange) {
|
|
1632
1650
|
dataSourceChange(dataSource);
|
|
1633
1651
|
}
|
|
@@ -1654,8 +1672,8 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
1654
1672
|
};
|
|
1655
1673
|
const defaultToolbarOption = searchEnable === true ? [{ template: searchTemplate, align: "left" }] : [];
|
|
1656
1674
|
let toolbarTopOption = [];
|
|
1657
|
-
if (toolbarOptions) {
|
|
1658
|
-
toolbarTopOption = [...defaultToolbarOption, ...toolbarOptions];
|
|
1675
|
+
if (toolbarSetting?.toolbarOptions) {
|
|
1676
|
+
toolbarTopOption = [...defaultToolbarOption, ...toolbarSetting?.toolbarOptions];
|
|
1659
1677
|
} else {
|
|
1660
1678
|
toolbarTopOption = [...defaultToolbarOption];
|
|
1661
1679
|
}
|
|
@@ -1963,7 +1981,7 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
1963
1981
|
checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
|
|
1964
1982
|
},
|
|
1965
1983
|
onPaste: (e) => {
|
|
1966
|
-
if (showBottomToolbar && !editDisable && !addDisable) {
|
|
1984
|
+
if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable) {
|
|
1967
1985
|
pasteDataFromExcel(indexRow, indexCol);
|
|
1968
1986
|
e.preventDefault();
|
|
1969
1987
|
}
|
|
@@ -2045,7 +2063,7 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2045
2063
|
checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
|
|
2046
2064
|
},
|
|
2047
2065
|
onPaste: (e) => {
|
|
2048
|
-
if (showBottomToolbar && !editDisable && !addDisable) {
|
|
2066
|
+
if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable) {
|
|
2049
2067
|
pasteDataFromExcel(indexRow, indexCol);
|
|
2050
2068
|
e.preventDefault();
|
|
2051
2069
|
}
|
|
@@ -2083,6 +2101,37 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2083
2101
|
);
|
|
2084
2102
|
}) }) });
|
|
2085
2103
|
};
|
|
2104
|
+
const moveIndexRowToNewPage = (isUp, addIfLast = false) => {
|
|
2105
|
+
if (!isUp) {
|
|
2106
|
+
let index = 0;
|
|
2107
|
+
if (addIfLast) {
|
|
2108
|
+
if (!pagingSetting?.allowPaging || (pagingSetting?.pageSize ?? 0) * ((pagingSetting?.currentPage ?? 1) - 1) + dataDisplay.length >= dataSource.length) {
|
|
2109
|
+
changeDataSource(pagingClient ? dataDisplay : dataSource, true);
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
if (pagingClient && dataDisplay.length > (pagingSetting?.pageSize ?? 0) && pagingSetting?.setCurrentPage) {
|
|
2113
|
+
pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 0) + 1);
|
|
2114
|
+
} else {
|
|
2115
|
+
index = dataDisplay.length - 1;
|
|
2116
|
+
}
|
|
2117
|
+
if (tableElement) {
|
|
2118
|
+
setIndexFocus(index);
|
|
2119
|
+
setTimeout(() => {
|
|
2120
|
+
tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
|
|
2121
|
+
const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${index + 1}`);
|
|
2122
|
+
if (element) {
|
|
2123
|
+
if (element.className.includes("react-select") || element.className.includes("form-edit")) {
|
|
2124
|
+
element.getElementsByTagName("input")[0]?.focus();
|
|
2125
|
+
} else {
|
|
2126
|
+
element.focus();
|
|
2127
|
+
element.scrollIntoView();
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
}, 100);
|
|
2131
|
+
}
|
|
2132
|
+
} else {
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2086
2135
|
const checkKeyDown = (e, row, col, indexRow, indexCol) => {
|
|
2087
2136
|
if (e.code === "ArrowRight") {
|
|
2088
2137
|
let newIndexCol = -1;
|
|
@@ -2104,8 +2153,7 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2104
2153
|
e.preventDefault();
|
|
2105
2154
|
return e.code;
|
|
2106
2155
|
}
|
|
2107
|
-
}
|
|
2108
|
-
if (e.code === "ArrowLeft") {
|
|
2156
|
+
} else if (e.code === "ArrowLeft") {
|
|
2109
2157
|
let newIndexCol = -1;
|
|
2110
2158
|
for (let i = indexCol - 2; i >= 0; i--) {
|
|
2111
2159
|
if (contentColumns[i].editEnable && contentColumns[i].visible !== false && (!contentColumns[i].disabledCondition || !contentColumns[i].disabledCondition(row))) {
|
|
@@ -2125,14 +2173,20 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2125
2173
|
e.preventDefault();
|
|
2126
2174
|
return e.code;
|
|
2127
2175
|
}
|
|
2128
|
-
}
|
|
2129
|
-
if (e.code === "ArrowUp") {
|
|
2176
|
+
} else if (e.code === "ArrowUp") {
|
|
2130
2177
|
const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
|
|
2131
2178
|
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)) {
|
|
2179
|
+
let index = -1;
|
|
2132
2180
|
if (indexRow > 1) {
|
|
2133
|
-
|
|
2181
|
+
index = indexRow - 2;
|
|
2182
|
+
} else if (pagingClient && (pagingSetting?.currentPage ?? 0) !== 1) {
|
|
2183
|
+
index = (pagingSetting?.pageSize ?? 0) - 1;
|
|
2184
|
+
pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) - 1);
|
|
2185
|
+
}
|
|
2186
|
+
if (index !== -1) {
|
|
2187
|
+
setIndexFocus(index);
|
|
2134
2188
|
setTimeout(() => {
|
|
2135
|
-
const element2 = document.getElementById(`${idTable}-col${indexCol}-row${
|
|
2189
|
+
const element2 = document.getElementById(`${idTable}-col${indexCol}-row${index + 1}`);
|
|
2136
2190
|
if (element2) {
|
|
2137
2191
|
if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
|
|
2138
2192
|
element2.getElementsByTagName("input")[0]?.focus();
|
|
@@ -2145,14 +2199,20 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2145
2199
|
return e.code;
|
|
2146
2200
|
}
|
|
2147
2201
|
}
|
|
2148
|
-
}
|
|
2149
|
-
if (e.code === "ArrowDown") {
|
|
2202
|
+
} else if (e.code === "ArrowDown") {
|
|
2150
2203
|
const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
|
|
2151
2204
|
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)) {
|
|
2152
|
-
|
|
2153
|
-
|
|
2205
|
+
let index = -1;
|
|
2206
|
+
if (indexRow < dataDisplay.length) {
|
|
2207
|
+
index = indexRow;
|
|
2208
|
+
} else if (pagingClient && (pagingSetting?.currentPage ?? 1) * (pagingSetting?.pageSize ?? 0) < totalCount) {
|
|
2209
|
+
index = 0;
|
|
2210
|
+
pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 1) + 1);
|
|
2211
|
+
}
|
|
2212
|
+
if (index !== -1) {
|
|
2213
|
+
setIndexFocus(index);
|
|
2154
2214
|
setTimeout(() => {
|
|
2155
|
-
const element2 = document.getElementById(`${idTable}-col${indexCol}-row${
|
|
2215
|
+
const element2 = document.getElementById(`${idTable}-col${indexCol}-row${index + 1}`);
|
|
2156
2216
|
if (element2) {
|
|
2157
2217
|
if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
|
|
2158
2218
|
element2.getElementsByTagName("input")[0]?.focus();
|
|
@@ -2165,40 +2225,32 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2165
2225
|
return e.code;
|
|
2166
2226
|
}
|
|
2167
2227
|
}
|
|
2168
|
-
}
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
setIndexFocus(indexRow);
|
|
2182
|
-
setTimeout(() => {
|
|
2183
|
-
const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${indexRow + 1}`);
|
|
2184
|
-
if (element) {
|
|
2185
|
-
if (element.className.includes("react-select") || element.className.includes("form-edit")) {
|
|
2186
|
-
element.getElementsByTagName("input")[0]?.focus();
|
|
2187
|
-
} else {
|
|
2188
|
-
element.focus();
|
|
2189
|
-
element.scrollIntoView();
|
|
2228
|
+
} else if (e.code === "Tab" && indexCol === columnLastEdit) {
|
|
2229
|
+
if (indexRow === dataDisplay.length) {
|
|
2230
|
+
moveIndexRowToNewPage(false, true);
|
|
2231
|
+
} else {
|
|
2232
|
+
setIndexFocus(indexRow);
|
|
2233
|
+
setTimeout(() => {
|
|
2234
|
+
const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${indexRow + 1}`);
|
|
2235
|
+
if (element) {
|
|
2236
|
+
if (element.className.includes("react-select") || element.className.includes("form-edit")) {
|
|
2237
|
+
element.getElementsByTagName("input")[0]?.focus();
|
|
2238
|
+
} else {
|
|
2239
|
+
element.focus();
|
|
2240
|
+
}
|
|
2190
2241
|
}
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2242
|
+
}, 100);
|
|
2243
|
+
}
|
|
2193
2244
|
e.preventDefault();
|
|
2194
|
-
}
|
|
2195
|
-
if ((e.code === "Enter" || e.code === "NumpadEnter") && (!editDisable && !addDisable)) {
|
|
2245
|
+
} else if ((e.code === "Enter" || e.code === "NumpadEnter") && (!editDisable && !addDisable)) {
|
|
2196
2246
|
const element = document.getElementById(`${idTable}-col${indexCol}-row${indexRow}`);
|
|
2197
2247
|
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)) {
|
|
2198
|
-
if (indexRow
|
|
2248
|
+
if (indexRow === dataDisplay.length) {
|
|
2249
|
+
moveIndexRowToNewPage(false, true);
|
|
2250
|
+
} else {
|
|
2199
2251
|
setIndexFocus(indexRow);
|
|
2200
2252
|
setTimeout(() => {
|
|
2201
|
-
const element2 = document.getElementById(`${idTable}-col${
|
|
2253
|
+
const element2 = document.getElementById(`${idTable}-col${columnFistEdit}-row${indexRow + 1}`);
|
|
2202
2254
|
if (element2) {
|
|
2203
2255
|
if (element2.className.includes("react-select") || element2.className.includes("form-edit")) {
|
|
2204
2256
|
element2.getElementsByTagName("input")[0]?.focus();
|
|
@@ -2207,14 +2259,11 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2207
2259
|
}
|
|
2208
2260
|
}
|
|
2209
2261
|
}, 100);
|
|
2210
|
-
} else {
|
|
2211
|
-
handleAdd();
|
|
2212
2262
|
}
|
|
2213
2263
|
e.preventDefault();
|
|
2214
2264
|
return e.code;
|
|
2215
2265
|
}
|
|
2216
|
-
}
|
|
2217
|
-
if (e.code === "KeyD" && e.ctrlKey == true && (!editDisable && !addDisable)) {
|
|
2266
|
+
} else if (e.code === "KeyD" && e.ctrlKey == true && (!editDisable && !addDisable)) {
|
|
2218
2267
|
handleDuplicate(dataSource[indexFocus ?? -1], indexRow);
|
|
2219
2268
|
e.preventDefault();
|
|
2220
2269
|
return e.code;
|
|
@@ -2222,16 +2271,22 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2222
2271
|
return "";
|
|
2223
2272
|
};
|
|
2224
2273
|
const onChangePage = (args) => {
|
|
2225
|
-
if (
|
|
2226
|
-
|
|
2274
|
+
if (pagingSetting?.setCurrentPage) {
|
|
2275
|
+
if (args.newProp.currentPage === args.oldProp.currentPage) {
|
|
2276
|
+
return;
|
|
2277
|
+
}
|
|
2278
|
+
pagingSetting.setCurrentPage(args.currentPage);
|
|
2227
2279
|
}
|
|
2228
|
-
setCurrentPage(args.currentPage);
|
|
2229
2280
|
};
|
|
2230
2281
|
const onChangePageSize = (args) => {
|
|
2231
|
-
if (allowPaging) {
|
|
2232
|
-
if (pageSize !== args.pageSize) {
|
|
2233
|
-
setPageSize
|
|
2234
|
-
|
|
2282
|
+
if (pagingSetting?.allowPaging) {
|
|
2283
|
+
if (pagingSetting?.pageSize !== args.pageSize) {
|
|
2284
|
+
if (pagingSetting?.setPageSize) {
|
|
2285
|
+
pagingSetting.setPageSize(args.pageSize);
|
|
2286
|
+
}
|
|
2287
|
+
if (pagingSetting?.setCurrentPage) {
|
|
2288
|
+
pagingSetting.setCurrentPage(1);
|
|
2289
|
+
}
|
|
2235
2290
|
}
|
|
2236
2291
|
}
|
|
2237
2292
|
};
|
|
@@ -2243,12 +2298,18 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2243
2298
|
}
|
|
2244
2299
|
});
|
|
2245
2300
|
const handleAdd = () => {
|
|
2246
|
-
changeDataSource(dataSource, true);
|
|
2301
|
+
changeDataSource(pagingClient ? dataDisplay : dataSource, true);
|
|
2302
|
+
let index = 0;
|
|
2303
|
+
if (pagingClient && dataDisplay.length > (pagingSetting?.pageSize ?? 0) && pagingSetting?.setCurrentPage) {
|
|
2304
|
+
pagingSetting?.setCurrentPage((pagingSetting?.currentPage ?? 0) + 1);
|
|
2305
|
+
} else {
|
|
2306
|
+
index = dataDisplay.length - 1;
|
|
2307
|
+
}
|
|
2247
2308
|
if (tableElement) {
|
|
2248
|
-
setIndexFocus(
|
|
2309
|
+
setIndexFocus(index);
|
|
2249
2310
|
setTimeout(() => {
|
|
2250
2311
|
tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
|
|
2251
|
-
const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${
|
|
2312
|
+
const element = document.getElementById(`${idTable}-col${columnFistEdit}-row${index + 1}`);
|
|
2252
2313
|
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)) {
|
|
2253
2314
|
if (element.className.includes("react-select") || element.className.includes("form-edit")) {
|
|
2254
2315
|
element.getElementsByTagName("input")[0]?.focus();
|
|
@@ -2259,26 +2320,24 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2259
2320
|
}, 100);
|
|
2260
2321
|
}
|
|
2261
2322
|
};
|
|
2262
|
-
const deleteAll = () => {
|
|
2263
|
-
if (!editDisable && !addDisable) {
|
|
2264
|
-
setIndexFocus(-1);
|
|
2265
|
-
changeDataSource([], false);
|
|
2266
|
-
}
|
|
2267
|
-
};
|
|
2268
2323
|
const handleDuplicate = (data, index) => {
|
|
2269
|
-
if (showBottomToolbar && !editDisable && !addDisable) {
|
|
2324
|
+
if (toolbarSetting?.showBottomToolbar && !buttonSetting?.duplicateDisable && !editDisable && !addDisable) {
|
|
2270
2325
|
if (fieldKey) {
|
|
2271
|
-
const newdata = { ...data };
|
|
2272
2326
|
fieldUniKey.forEach((item) => {
|
|
2273
|
-
|
|
2327
|
+
data[item] = defaultValue[item];
|
|
2274
2328
|
});
|
|
2275
|
-
|
|
2276
|
-
|
|
2329
|
+
data[fieldKey] = defaultValue[fieldKey];
|
|
2330
|
+
}
|
|
2331
|
+
if (pagingClient) {
|
|
2332
|
+
if (dataDisplay.length < (pagingSetting?.pageSize ?? 0)) {
|
|
2333
|
+
dataDisplay.splice(index, 0, data);
|
|
2334
|
+
}
|
|
2335
|
+
dataSource.splice(((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + index, 0, { ...data });
|
|
2277
2336
|
} else {
|
|
2278
|
-
dataSource
|
|
2337
|
+
dataSource.splice(index, 0, data);
|
|
2279
2338
|
}
|
|
2280
|
-
changeDataSource(dataSource);
|
|
2281
|
-
if (tableElement && index === dataSource
|
|
2339
|
+
changeDataSource(pagingClient ? dataDisplay : dataSource);
|
|
2340
|
+
if (tableElement && index === (pagingClient ? dataDisplay.length : dataSource.length)) {
|
|
2282
2341
|
setTimeout(() => {
|
|
2283
2342
|
tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
|
|
2284
2343
|
}, 100);
|
|
@@ -2286,10 +2345,17 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2286
2345
|
}
|
|
2287
2346
|
};
|
|
2288
2347
|
const handleInsertAfter = () => {
|
|
2289
|
-
if (showBottomToolbar && !editDisable && !addDisable) {
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2348
|
+
if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertAfterDisable && !editDisable && !addDisable) {
|
|
2349
|
+
if (pagingClient) {
|
|
2350
|
+
if (dataDisplay.length < (pagingSetting?.pageSize ?? 0)) {
|
|
2351
|
+
dataDisplay.splice((indexFocus ?? -1) + 1, 0, { ...defaultValue });
|
|
2352
|
+
}
|
|
2353
|
+
dataSource.splice(((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + (indexFocus ?? -1) + 1, 0, { ...{ ...defaultValue } });
|
|
2354
|
+
} else {
|
|
2355
|
+
dataSource.splice((indexFocus ?? -1) + 1, 0, { ...defaultValue });
|
|
2356
|
+
}
|
|
2357
|
+
changeDataSource(pagingClient ? dataDisplay : dataSource);
|
|
2358
|
+
if (tableElement && indexFocus === dataSource.length) {
|
|
2293
2359
|
setTimeout(() => {
|
|
2294
2360
|
tableElement.current?.scrollTo(0, tableElement.current.scrollHeight);
|
|
2295
2361
|
}, 100);
|
|
@@ -2297,16 +2363,29 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2297
2363
|
}
|
|
2298
2364
|
};
|
|
2299
2365
|
const handleInsertBefore = () => {
|
|
2300
|
-
if (showBottomToolbar && !editDisable && !addDisable) {
|
|
2301
|
-
|
|
2302
|
-
|
|
2366
|
+
if (toolbarSetting?.showBottomToolbar && !buttonSetting?.insertBeforeDisable && !editDisable && !addDisable) {
|
|
2367
|
+
if (pagingClient) {
|
|
2368
|
+
if (dataDisplay.length < (pagingSetting?.pageSize ?? 0)) {
|
|
2369
|
+
dataDisplay.splice(indexFocus ?? -1, 0, { ...defaultValue });
|
|
2370
|
+
}
|
|
2371
|
+
dataSource.splice(((pagingSetting?.currentPage ?? 1) - 1) * (pagingSetting?.pageSize ?? 0) + (indexFocus ?? -1), 0, { ...{ ...defaultValue } });
|
|
2372
|
+
} else {
|
|
2373
|
+
dataSource.splice(indexFocus ?? -1, 0, { ...defaultValue });
|
|
2374
|
+
}
|
|
2375
|
+
changeDataSource(pagingClient ? dataDisplay : dataSource);
|
|
2303
2376
|
}
|
|
2304
2377
|
};
|
|
2305
2378
|
const handleDeleteAll = () => {
|
|
2306
|
-
if (showBottomToolbar && !editDisable && !addDisable) {
|
|
2379
|
+
if (toolbarSetting?.showBottomToolbar && !buttonSetting?.deleteAllDisable && !editDisable && !addDisable) {
|
|
2307
2380
|
messageBoxConfirmDelete(t, deleteAll, "");
|
|
2308
2381
|
}
|
|
2309
2382
|
};
|
|
2383
|
+
const deleteAll = () => {
|
|
2384
|
+
if (!editDisable && !addDisable) {
|
|
2385
|
+
setIndexFocus(-1);
|
|
2386
|
+
changeDataSource([], false);
|
|
2387
|
+
}
|
|
2388
|
+
};
|
|
2310
2389
|
const pasteDataFromExcel = async (row, col) => {
|
|
2311
2390
|
const clipboard = await navigator.clipboard.readText();
|
|
2312
2391
|
const arrayRow = clipboard.trimEnd().split("\n");
|
|
@@ -2315,7 +2394,7 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2315
2394
|
let dataRow = dataSource[row + indexRow];
|
|
2316
2395
|
if (!dataRow) {
|
|
2317
2396
|
dataRow = { ...defaultValue };
|
|
2318
|
-
dataSource
|
|
2397
|
+
dataSource.push(dataRow);
|
|
2319
2398
|
}
|
|
2320
2399
|
arrayCol.forEach((element, index) => {
|
|
2321
2400
|
const column = contentColumns[col + index];
|
|
@@ -2326,15 +2405,31 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2326
2405
|
rowChange(dataRow, row + indexRow, "");
|
|
2327
2406
|
});
|
|
2328
2407
|
handleRefeshRow();
|
|
2329
|
-
changeDataSource(dataSource);
|
|
2408
|
+
changeDataSource(pagingClient ? dataDisplay : dataSource);
|
|
2330
2409
|
};
|
|
2331
2410
|
const changeDataSource = (data, haveNew = false) => {
|
|
2332
|
-
if (
|
|
2333
|
-
|
|
2334
|
-
|
|
2411
|
+
if (data.length === 0 && !haveNew) {
|
|
2412
|
+
setDataDisplay([]);
|
|
2413
|
+
setDataSource([]);
|
|
2414
|
+
} else if (!editDisable && !addDisable && setDataSource) {
|
|
2415
|
+
if (pagingClient) {
|
|
2416
|
+
if (haveNew) {
|
|
2417
|
+
data.push(defaultValue ? { ...defaultValue, [fieldKey]: generateUUID() } : {});
|
|
2418
|
+
setDataDisplay(data);
|
|
2419
|
+
dataSource.push(defaultValue ? { ...defaultValue, [fieldKey]: generateUUID() } : {});
|
|
2420
|
+
} else {
|
|
2421
|
+
setDataDisplay([...data]);
|
|
2422
|
+
}
|
|
2423
|
+
setTotalCount(dataSource?.length ?? 0);
|
|
2424
|
+
} else {
|
|
2425
|
+
if (haveNew) {
|
|
2426
|
+
data.push(defaultValue ? { ...defaultValue, [fieldKey]: generateUUID() } : {});
|
|
2427
|
+
setDataSource([...data]);
|
|
2428
|
+
} else {
|
|
2429
|
+
setDataSource([...data]);
|
|
2430
|
+
}
|
|
2335
2431
|
}
|
|
2336
2432
|
}
|
|
2337
|
-
setDataSource([...data]);
|
|
2338
2433
|
};
|
|
2339
2434
|
useEffect5(() => {
|
|
2340
2435
|
setIndexFocus(-1);
|
|
@@ -2418,11 +2513,18 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2418
2513
|
onPaste: (e) => {
|
|
2419
2514
|
if (!editDisable && (e.target.nodeName === "DIV" || e.target.nodeName === "TD")) {
|
|
2420
2515
|
navigator.clipboard.readText().then((rs) => {
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2516
|
+
if (pagingClient) {
|
|
2517
|
+
dataDisplay[indexRow] = JSON.parse(rs);
|
|
2518
|
+
if (fieldKey) {
|
|
2519
|
+
dataDisplay[indexRow][fieldKey] = defaultValue[fieldKey];
|
|
2520
|
+
}
|
|
2521
|
+
} else {
|
|
2522
|
+
dataSource[indexRow] = JSON.parse(rs);
|
|
2523
|
+
if (fieldKey) {
|
|
2524
|
+
dataSource[indexRow][fieldKey] = defaultValue[fieldKey];
|
|
2525
|
+
}
|
|
2424
2526
|
}
|
|
2425
|
-
changeDataSource(dataSource);
|
|
2527
|
+
changeDataSource(pagingClient ? dataDisplay : dataSource);
|
|
2426
2528
|
notificationSuccess(t("PasteSuccessful"));
|
|
2427
2529
|
}).catch((ex) => {
|
|
2428
2530
|
alert(ex);
|
|
@@ -2629,17 +2731,22 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2629
2731
|
children: /* @__PURE__ */ jsx12(
|
|
2630
2732
|
Input6,
|
|
2631
2733
|
{
|
|
2632
|
-
checked:
|
|
2734
|
+
checked: (pagingClient ? dataDisplay.length > 0 : dataSource.length > 0) && selectedRows?.length >= (pagingClient ? dataDisplay.length : dataSource.length),
|
|
2633
2735
|
type: "checkbox",
|
|
2634
2736
|
className: classnames6("cursor-pointer", { "d-none": !isMulti }),
|
|
2635
2737
|
style: { textAlign: col.textAlign ?? "left", marginTop: 6 },
|
|
2636
2738
|
onChange: (e) => {
|
|
2637
2739
|
if (selectEnable) {
|
|
2638
2740
|
if (e.target.checked) {
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2741
|
+
if (pagingClient) {
|
|
2742
|
+
setSelectedRows(dataDisplay.map((item) => {
|
|
2743
|
+
return item;
|
|
2744
|
+
}));
|
|
2745
|
+
} else {
|
|
2746
|
+
setSelectedRows(dataSource.map((item) => {
|
|
2747
|
+
return item;
|
|
2748
|
+
}));
|
|
2749
|
+
}
|
|
2643
2750
|
} else {
|
|
2644
2751
|
setSelectedRows([]);
|
|
2645
2752
|
}
|
|
@@ -2746,7 +2853,7 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2746
2853
|
maxWidth: col.maxWidth,
|
|
2747
2854
|
textAlign: col.textAlign ? col.textAlign : "left"
|
|
2748
2855
|
},
|
|
2749
|
-
children: /* @__PURE__ */ jsx12("div", { className: "r-footer-div", children: col.haveSum === true && col.editType === "numeric" ? formartNumberic(dataSource
|
|
2856
|
+
children: /* @__PURE__ */ jsx12("div", { className: "r-footer-div", children: col.haveSum === true && col.editType === "numeric" ? formartNumberic(dataSource.reduce(function(accumulator, currentValue) {
|
|
2750
2857
|
return Number(accumulator ?? 0) + Number(currentValue[col.field] ?? 0);
|
|
2751
2858
|
}, 0), decimalSeparator, thousandSeparator, col.numericSettings?.fraction, true) : "" })
|
|
2752
2859
|
}
|
|
@@ -2770,22 +2877,22 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2770
2877
|
/* @__PURE__ */ jsxs11("div", { className: "r-toolbar-left", children: [
|
|
2771
2878
|
/* @__PURE__ */ jsx12("div", { className: classnames6("r-toolbar-item", { "d-none": editDisable || addDisable }), "aria-disabled": "false", children: /* @__PURE__ */ jsx12(Button3, { color: "success", outline: true, onClick: handleAdd, className: "d-flex", children: t("Add item") }) }),
|
|
2772
2879
|
(indexFocus ?? -1) > -1 ? /* @__PURE__ */ jsxs11(Fragment13, { children: [
|
|
2773
|
-
/* @__PURE__ */ jsx12("div", { className: classnames6("r-toolbar-item", { "d-none": editDisable || addDisable || duplicateDisable }), "aria-disabled": "false", children: /* @__PURE__ */ jsx12(Button3, { color: "success", outline: true, onClick: () => {
|
|
2774
|
-
handleDuplicate(dataSource[indexFocus ?? -1], indexFocus ?? -1);
|
|
2880
|
+
/* @__PURE__ */ jsx12("div", { className: classnames6("r-toolbar-item", { "d-none": editDisable || addDisable || buttonSetting?.duplicateDisable }), "aria-disabled": "false", children: /* @__PURE__ */ jsx12(Button3, { color: "success", outline: true, onClick: () => {
|
|
2881
|
+
handleDuplicate(pagingClient ? dataDisplay[indexFocus ?? -1] : dataSource[indexFocus ?? -1], indexFocus ?? -1);
|
|
2775
2882
|
}, className: "d-flex", children: t("Duplicate") }) }),
|
|
2776
|
-
/* @__PURE__ */ jsx12("div", { className: classnames6("r-toolbar-item", { "d-none": editDisable || addDisable || insertBeforeDisable }), "aria-disabled": "false", children: /* @__PURE__ */ jsx12(Button3, { color: "success", outline: true, onClick: handleInsertBefore, className: "d-flex", children: t("Insert item before") }) }),
|
|
2777
|
-
/* @__PURE__ */ jsx12("div", { className: classnames6("r-toolbar-item", { "d-none": editDisable || addDisable || insertAfterDisable }), "aria-disabled": "false", children: /* @__PURE__ */ jsx12(Button3, { color: "success", outline: true, onClick: handleInsertAfter, className: "d-flex", children: t("Insert item after") }) })
|
|
2883
|
+
/* @__PURE__ */ jsx12("div", { className: classnames6("r-toolbar-item", { "d-none": editDisable || addDisable || buttonSetting?.insertBeforeDisable }), "aria-disabled": "false", children: /* @__PURE__ */ jsx12(Button3, { color: "success", outline: true, onClick: handleInsertBefore, className: "d-flex", children: t("Insert item before") }) }),
|
|
2884
|
+
/* @__PURE__ */ jsx12("div", { className: classnames6("r-toolbar-item", { "d-none": editDisable || addDisable || buttonSetting?.insertAfterDisable }), "aria-disabled": "false", children: /* @__PURE__ */ jsx12(Button3, { color: "success", outline: true, onClick: handleInsertAfter, className: "d-flex", children: t("Insert item after") }) })
|
|
2778
2885
|
] }) : /* @__PURE__ */ jsx12(Fragment13, { children: " " }),
|
|
2779
|
-
/* @__PURE__ */ jsx12("div", { className: classnames6("r-toolbar-item", { "d-none": editDisable ||
|
|
2780
|
-
toolbarBottomOptions?.map((item, index) => {
|
|
2886
|
+
/* @__PURE__ */ jsx12("div", { className: classnames6("r-toolbar-item", { "d-none": editDisable || buttonSetting?.deleteAllDisable }), "aria-disabled": "false", children: /* @__PURE__ */ jsx12(Button3, { color: "primary", outline: true, onClick: handleDeleteAll, className: "d-flex", children: t("Delete all item") }) }),
|
|
2887
|
+
toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
|
|
2781
2888
|
return item.align === "left" ? /* @__PURE__ */ jsx12("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-left-${index}`) : "";
|
|
2782
2889
|
})
|
|
2783
2890
|
] }),
|
|
2784
|
-
/* @__PURE__ */ jsx12("div", { className: "r-toolbar-center", children: toolbarBottomOptions?.map((item, index) => {
|
|
2891
|
+
/* @__PURE__ */ jsx12("div", { className: "r-toolbar-center", children: toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
|
|
2785
2892
|
return item.align === "center" ? /* @__PURE__ */ jsx12("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-center-${index}`) : "";
|
|
2786
2893
|
}) }),
|
|
2787
2894
|
/* @__PURE__ */ jsxs11("div", { className: "r-toolbar-right", children: [
|
|
2788
|
-
toolbarBottomOptions?.map((item, index) => {
|
|
2895
|
+
toolbarSetting?.toolbarBottomOptions?.map((item, index) => {
|
|
2789
2896
|
return item.align === "right" ? /* @__PURE__ */ jsx12("div", { className: "r-toolbar-item", "aria-disabled": "false", children: item.template() }, `toolbar-bottom-right-${index}`) : "";
|
|
2790
2897
|
}),
|
|
2791
2898
|
/* @__PURE__ */ jsx12("div", { className: classnames6("r-toolbar-item me-25", { "d-none": headerColumns.length > 1 }), "aria-disabled": "false", children: /* @__PURE__ */ jsx12(Settings, { className: "text-primary cursor-pointer", onClick: () => setOpenPopupSetupColumn(true) }) }),
|
|
@@ -2804,19 +2911,31 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2804
2911
|
return /* @__PURE__ */ jsxs11(Fragment12, { children: [
|
|
2805
2912
|
/* @__PURE__ */ jsxs11("div", { className: "react-table-edit", children: [
|
|
2806
2913
|
/* @__PURE__ */ jsxs11("div", { className: "r-grid", ref: gridRef, children: [
|
|
2807
|
-
showTopToolbar ? /* @__PURE__ */ jsx12(Fragment13, { children: renderToolbarTop() }) : /* @__PURE__ */ jsx12(Fragment13, {}),
|
|
2914
|
+
toolbarSetting?.showTopToolbar ? /* @__PURE__ */ jsx12(Fragment13, { children: renderToolbarTop() }) : /* @__PURE__ */ jsx12(Fragment13, {}),
|
|
2808
2915
|
/* @__PURE__ */ jsx12("div", { ref: tableElement, className: "r-gridtable", style: { height: `${height ? `${height}px` : "auto"}`, minHeight: `${minHeight ? `${minHeight}px` : ""}`, maxHeight: `${maxHeight ? `${maxHeight}px` : "400px"}` }, children: /* @__PURE__ */ jsxs11("table", { style: { width: "100%" }, children: [
|
|
2809
2916
|
/* @__PURE__ */ jsx12("thead", { className: "r-gridheader", children: headerColumns.map((element, indexParent) => {
|
|
2810
2917
|
return /* @__PURE__ */ jsx12("tr", { className: "r-row", role: "row", children: element?.map((col, index) => {
|
|
2811
2918
|
return renderHeaderCol(col, index, indexParent);
|
|
2812
2919
|
}) }, indexParent);
|
|
2813
2920
|
}) }),
|
|
2814
|
-
/* @__PURE__ */ jsx12("tbody", { className: "r-gridcontent", children:
|
|
2921
|
+
/* @__PURE__ */ jsx12("tbody", { className: "r-gridcontent", children: pagingClient ? dataDisplay.map((row, indexRow) => {
|
|
2922
|
+
const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
|
|
2923
|
+
return /* @__PURE__ */ jsx12(
|
|
2924
|
+
"tr",
|
|
2925
|
+
{
|
|
2926
|
+
className: classnames6("r-row", { "last-row": indexRow === dataDisplay.length - 1 }, { "fisrt-row": indexRow === 0 }),
|
|
2927
|
+
children: contentColumns.map((col, indexCol) => {
|
|
2928
|
+
return renderContentCol(col, row, indexRow, indexCol, isSelected);
|
|
2929
|
+
})
|
|
2930
|
+
},
|
|
2931
|
+
`row-${indexRow}`
|
|
2932
|
+
);
|
|
2933
|
+
}) : dataSource.map((row, indexRow) => {
|
|
2815
2934
|
const isSelected = selectedRows?.some((x) => x[fieldKey] === row[fieldKey]);
|
|
2816
2935
|
return /* @__PURE__ */ jsx12(
|
|
2817
2936
|
"tr",
|
|
2818
2937
|
{
|
|
2819
|
-
className: classnames6("r-row", { "last-row": indexRow ===
|
|
2938
|
+
className: classnames6("r-row", { "last-row": indexRow === dataDisplay.length - 1 }, { "fisrt-row": indexRow === 0 }),
|
|
2820
2939
|
children: contentColumns.map((col, indexCol) => {
|
|
2821
2940
|
return renderContentCol(col, row, indexRow, indexCol, isSelected);
|
|
2822
2941
|
})
|
|
@@ -2828,17 +2947,17 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2828
2947
|
return renderFooterCol(col, index);
|
|
2829
2948
|
}) }) : /* @__PURE__ */ jsx12(Fragment13, {}) })
|
|
2830
2949
|
] }) }),
|
|
2831
|
-
showBottomToolbar ? /* @__PURE__ */ jsx12(Fragment13, { children: renderToolbarBottom() }) : /* @__PURE__ */ jsx12(Fragment13, {})
|
|
2950
|
+
toolbarSetting?.showBottomToolbar ? /* @__PURE__ */ jsx12(Fragment13, { children: renderToolbarBottom() }) : /* @__PURE__ */ jsx12(Fragment13, {})
|
|
2832
2951
|
] }),
|
|
2833
|
-
allowPaging ? /* @__PURE__ */ jsx12(
|
|
2952
|
+
pagingSetting?.allowPaging ? /* @__PURE__ */ jsx12(
|
|
2834
2953
|
PagerComponent,
|
|
2835
2954
|
{
|
|
2836
2955
|
locale: lang,
|
|
2837
2956
|
click: onChangePage,
|
|
2838
|
-
pageSize,
|
|
2839
|
-
currentPage,
|
|
2957
|
+
pageSize: pagingSetting?.pageSize,
|
|
2958
|
+
currentPage: pagingSetting?.currentPage,
|
|
2840
2959
|
pageSizes: [20, 30, 50, 100],
|
|
2841
|
-
totalRecordsCount:
|
|
2960
|
+
totalRecordsCount: pagingClient ? totalCount : pagingSetting?.totalItem ?? 0,
|
|
2842
2961
|
pageCount: 5,
|
|
2843
2962
|
dropDownChanged: onChangePageSize
|
|
2844
2963
|
}
|