trotl-table 1.0.63 → 1.0.64
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/Table.cjs.js +43 -11
- package/dist/Table.cjs.js.map +1 -1
- package/dist/Table.esm.js +43 -11
- package/dist/Table.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/Table.cjs.js
CHANGED
|
@@ -9851,6 +9851,35 @@ function TableInner({
|
|
|
9851
9851
|
return null;
|
|
9852
9852
|
});
|
|
9853
9853
|
};
|
|
9854
|
+
const getAccessorValue = React.useCallback((row, accessor) => {
|
|
9855
|
+
if (!row || accessor == null) return undefined;
|
|
9856
|
+
|
|
9857
|
+
// Support fallback accessors: ["preverjen", "Preverjen", ...]
|
|
9858
|
+
if (Array.isArray(accessor)) {
|
|
9859
|
+
for (const key of accessor) {
|
|
9860
|
+
if (row?.[key] !== undefined) return row[key];
|
|
9861
|
+
}
|
|
9862
|
+
return undefined;
|
|
9863
|
+
}
|
|
9864
|
+
return row?.[accessor];
|
|
9865
|
+
}, []);
|
|
9866
|
+
const getAccessorKey = React.useCallback((row, accessor) => {
|
|
9867
|
+
if (accessor == null) return accessor;
|
|
9868
|
+
if (Array.isArray(accessor)) {
|
|
9869
|
+
for (const key of accessor) {
|
|
9870
|
+
if (row?.[key] !== undefined) return key;
|
|
9871
|
+
}
|
|
9872
|
+
return accessor[0];
|
|
9873
|
+
}
|
|
9874
|
+
return accessor;
|
|
9875
|
+
}, []);
|
|
9876
|
+
const isSameAccessor = React.useCallback((a, b) => {
|
|
9877
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
9878
|
+
if (a.length !== b.length) return false;
|
|
9879
|
+
return a.every((item, idx) => item === b[idx]);
|
|
9880
|
+
}
|
|
9881
|
+
return a === b;
|
|
9882
|
+
}, []);
|
|
9854
9883
|
|
|
9855
9884
|
// console.log(extraSearchTerm)
|
|
9856
9885
|
|
|
@@ -9936,11 +9965,11 @@ function TableInner({
|
|
|
9936
9965
|
if (!searchTerm) return dateFiltered;
|
|
9937
9966
|
const query = searchTerm.toLowerCase();
|
|
9938
9967
|
return dateFiltered.filter(row => columns.some(col => {
|
|
9939
|
-
const val = row
|
|
9968
|
+
const val = getAccessorValue(row, col.accessor);
|
|
9940
9969
|
if (val == null) return false;
|
|
9941
9970
|
return String(val).toLowerCase().includes(query);
|
|
9942
9971
|
}));
|
|
9943
|
-
}, [searchTerm, columns, urlSearchString]);
|
|
9972
|
+
}, [searchTerm, columns, urlSearchString, getAccessorValue]);
|
|
9944
9973
|
|
|
9945
9974
|
// Natural-ish comparator: handles nulls, numbers, strings, ISO dates
|
|
9946
9975
|
const compare = (x, y, dir = "asc") => {
|
|
@@ -10005,14 +10034,14 @@ function TableInner({
|
|
|
10005
10034
|
const sortRows = rows => {
|
|
10006
10035
|
const arr = [...rows];
|
|
10007
10036
|
if (!sortKey) return filterRows(arr); // fallback to drag order
|
|
10008
|
-
arr.sort((a, b) => compare(a
|
|
10037
|
+
arr.sort((a, b) => compare(getAccessorValue(a, sortKey), getAccessorValue(b, sortKey), direction));
|
|
10009
10038
|
return filterRows(arr);
|
|
10010
10039
|
};
|
|
10011
10040
|
return normalizedGroups.map(g => ({
|
|
10012
10041
|
...g,
|
|
10013
10042
|
rows: sortRows(g.rows || [])
|
|
10014
10043
|
}));
|
|
10015
|
-
}, [normalizedGroups, sorting, filterRows]);
|
|
10044
|
+
}, [normalizedGroups, sorting, filterRows, getAccessorValue]);
|
|
10016
10045
|
const [expandedGroups, setExpandedGroups] = React.useState({});
|
|
10017
10046
|
const toggleGroup = gid => {
|
|
10018
10047
|
setExpandedGroups(prev => ({
|
|
@@ -10185,18 +10214,19 @@ function TableInner({
|
|
|
10185
10214
|
}, [searchTerm]);
|
|
10186
10215
|
const triggerCellCallback = React.useCallback((row, col, explicitValue) => {
|
|
10187
10216
|
const accessor = col?.accessor ?? null;
|
|
10188
|
-
const
|
|
10217
|
+
const resolvedAccessor = getAccessorKey(row, accessor);
|
|
10218
|
+
const value = explicitValue !== undefined ? explicitValue : getAccessorValue(row, accessor);
|
|
10189
10219
|
const type = col?.type ?? (col?.isCustom ? "custom" : "text");
|
|
10190
10220
|
try {
|
|
10191
10221
|
const callback = cellCallbackRef.current;
|
|
10192
10222
|
if (typeof callback !== "function") return;
|
|
10193
10223
|
if (callback.length >= 2) {
|
|
10194
|
-
callback(row,
|
|
10224
|
+
callback(row, resolvedAccessor, value, col);
|
|
10195
10225
|
return;
|
|
10196
10226
|
}
|
|
10197
10227
|
callback({
|
|
10198
10228
|
type,
|
|
10199
|
-
accessor,
|
|
10229
|
+
accessor: resolvedAccessor,
|
|
10200
10230
|
value,
|
|
10201
10231
|
row,
|
|
10202
10232
|
column: col
|
|
@@ -10204,7 +10234,7 @@ function TableInner({
|
|
|
10204
10234
|
} catch (err) {
|
|
10205
10235
|
console.error("cellCallback error", err);
|
|
10206
10236
|
}
|
|
10207
|
-
}, []);
|
|
10237
|
+
}, [getAccessorKey, getAccessorValue]);
|
|
10208
10238
|
const renderCell = React.useCallback((v, accessor, row, col) => {
|
|
10209
10239
|
// Checkbox column type (editable in-table)
|
|
10210
10240
|
if (col && col.type === 'checkbox') {
|
|
@@ -10703,6 +10733,8 @@ function TableInner({
|
|
|
10703
10733
|
maxWidth: keyWidth
|
|
10704
10734
|
} : undefined
|
|
10705
10735
|
}, visualIndex), allColumns.map((col, i) => {
|
|
10736
|
+
const resolvedAccessor = getAccessorKey(row, col.accessor);
|
|
10737
|
+
const cellValue = getAccessorValue(row, col.accessor);
|
|
10706
10738
|
let cellStyle = col.style ? {
|
|
10707
10739
|
...col.style
|
|
10708
10740
|
} : undefined;
|
|
@@ -10717,7 +10749,7 @@ function TableInner({
|
|
|
10717
10749
|
className: "table-cell",
|
|
10718
10750
|
style: cellStyle,
|
|
10719
10751
|
onClick: () => triggerCellCallback(row, col)
|
|
10720
|
-
}, col.isCustom ? typeof col.render === 'function' ? col.render(row, i) : col.render : renderCell(
|
|
10752
|
+
}, col.isCustom ? typeof col.render === 'function' ? col.render(row, i) : col.render : renderCell(cellValue, resolvedAccessor, row, col));
|
|
10721
10753
|
})), showActions && /*#__PURE__*/React.createElement("div", {
|
|
10722
10754
|
className: "table-cell action-cell",
|
|
10723
10755
|
style: actionColumnStyle
|
|
@@ -10791,7 +10823,7 @@ function TableInner({
|
|
|
10791
10823
|
}, content);
|
|
10792
10824
|
}
|
|
10793
10825
|
return content;
|
|
10794
|
-
}, [tableDataFlat, columns, selectedRows, toggleRowSelection, groupRowsById, renderCell, showActions, showDelete, showEdit, showKey, showView, translate, enableDragRow, moveRow, enableMultiSelect, rowHeight, tableId, customColumns, doubleClickEnable, keyWidth, actionColumnStyle, showDuplicate, showDownload, showIcons, showShare, triggerCellCallback]);
|
|
10826
|
+
}, [tableDataFlat, columns, selectedRows, toggleRowSelection, groupRowsById, renderCell, showActions, showDelete, showEdit, showKey, showView, translate, enableDragRow, moveRow, enableMultiSelect, rowHeight, tableId, customColumns, doubleClickEnable, keyWidth, actionColumnStyle, showDuplicate, showDownload, showIcons, showShare, triggerCellCallback, getAccessorKey, getAccessorValue]);
|
|
10795
10827
|
const rowHeightGetter = ({
|
|
10796
10828
|
index
|
|
10797
10829
|
}) => tableDataFlat[index]?.type === "group" ? groupHeaderHeight : rowHeight;
|
|
@@ -10890,7 +10922,7 @@ function TableInner({
|
|
|
10890
10922
|
style: cellStyle,
|
|
10891
10923
|
title: headerTitle,
|
|
10892
10924
|
onClick: col.isCustom ? undefined : () => setSort(col.accessor)
|
|
10893
|
-
}, col.isCustom ? translatedHeader ?? "" : translatedHeader, !col.isCustom && sorting?.column
|
|
10925
|
+
}, col.isCustom ? translatedHeader ?? "" : translatedHeader, !col.isCustom && isSameAccessor(sorting?.column, col.accessor) && (sorting.direction === "asc" ? " ↑" : " ↓"));
|
|
10894
10926
|
}), showActions && /*#__PURE__*/React.createElement("div", {
|
|
10895
10927
|
className: "table-cell action-cell",
|
|
10896
10928
|
style: actionColumnStyle,
|