trotl-table 1.0.63 → 1.0.65

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 CHANGED
@@ -9701,6 +9701,7 @@ function TableInner({
9701
9701
  yesDelete: "Yes, Delete",
9702
9702
  areYouSureYouWantToDelete: "Are you sure you want to delete",
9703
9703
  action: "Action",
9704
+ noData: "No Data",
9704
9705
  DropHereToMoveIntoThisGroup: "Drop here to move into this group"
9705
9706
  };
9706
9707
  return translations[key] || key;
@@ -9851,6 +9852,35 @@ function TableInner({
9851
9852
  return null;
9852
9853
  });
9853
9854
  };
9855
+ const getAccessorValue = React.useCallback((row, accessor) => {
9856
+ if (!row || accessor == null) return undefined;
9857
+
9858
+ // Support fallback accessors: ["preverjen", "Preverjen", ...]
9859
+ if (Array.isArray(accessor)) {
9860
+ for (const key of accessor) {
9861
+ if (row?.[key] !== undefined) return row[key];
9862
+ }
9863
+ return undefined;
9864
+ }
9865
+ return row?.[accessor];
9866
+ }, []);
9867
+ const getAccessorKey = React.useCallback((row, accessor) => {
9868
+ if (accessor == null) return accessor;
9869
+ if (Array.isArray(accessor)) {
9870
+ for (const key of accessor) {
9871
+ if (row?.[key] !== undefined) return key;
9872
+ }
9873
+ return accessor[0];
9874
+ }
9875
+ return accessor;
9876
+ }, []);
9877
+ const isSameAccessor = React.useCallback((a, b) => {
9878
+ if (Array.isArray(a) && Array.isArray(b)) {
9879
+ if (a.length !== b.length) return false;
9880
+ return a.every((item, idx) => item === b[idx]);
9881
+ }
9882
+ return a === b;
9883
+ }, []);
9854
9884
 
9855
9885
  // console.log(extraSearchTerm)
9856
9886
 
@@ -9936,11 +9966,11 @@ function TableInner({
9936
9966
  if (!searchTerm) return dateFiltered;
9937
9967
  const query = searchTerm.toLowerCase();
9938
9968
  return dateFiltered.filter(row => columns.some(col => {
9939
- const val = row[col.accessor];
9969
+ const val = getAccessorValue(row, col.accessor);
9940
9970
  if (val == null) return false;
9941
9971
  return String(val).toLowerCase().includes(query);
9942
9972
  }));
9943
- }, [searchTerm, columns, urlSearchString]);
9973
+ }, [searchTerm, columns, urlSearchString, getAccessorValue]);
9944
9974
 
9945
9975
  // Natural-ish comparator: handles nulls, numbers, strings, ISO dates
9946
9976
  const compare = (x, y, dir = "asc") => {
@@ -10005,14 +10035,14 @@ function TableInner({
10005
10035
  const sortRows = rows => {
10006
10036
  const arr = [...rows];
10007
10037
  if (!sortKey) return filterRows(arr); // fallback to drag order
10008
- arr.sort((a, b) => compare(a?.[sortKey], b?.[sortKey], direction));
10038
+ arr.sort((a, b) => compare(getAccessorValue(a, sortKey), getAccessorValue(b, sortKey), direction));
10009
10039
  return filterRows(arr);
10010
10040
  };
10011
10041
  return normalizedGroups.map(g => ({
10012
10042
  ...g,
10013
10043
  rows: sortRows(g.rows || [])
10014
10044
  }));
10015
- }, [normalizedGroups, sorting, filterRows]);
10045
+ }, [normalizedGroups, sorting, filterRows, getAccessorValue]);
10016
10046
  const [expandedGroups, setExpandedGroups] = React.useState({});
10017
10047
  const toggleGroup = gid => {
10018
10048
  setExpandedGroups(prev => ({
@@ -10185,18 +10215,19 @@ function TableInner({
10185
10215
  }, [searchTerm]);
10186
10216
  const triggerCellCallback = React.useCallback((row, col, explicitValue) => {
10187
10217
  const accessor = col?.accessor ?? null;
10188
- const value = explicitValue !== undefined ? explicitValue : accessor != null ? row?.[accessor] : undefined;
10218
+ const resolvedAccessor = getAccessorKey(row, accessor);
10219
+ const value = explicitValue !== undefined ? explicitValue : getAccessorValue(row, accessor);
10189
10220
  const type = col?.type ?? (col?.isCustom ? "custom" : "text");
10190
10221
  try {
10191
10222
  const callback = cellCallbackRef.current;
10192
10223
  if (typeof callback !== "function") return;
10193
10224
  if (callback.length >= 2) {
10194
- callback(row, accessor, value, col);
10225
+ callback(row, resolvedAccessor, value, col);
10195
10226
  return;
10196
10227
  }
10197
10228
  callback({
10198
10229
  type,
10199
- accessor,
10230
+ accessor: resolvedAccessor,
10200
10231
  value,
10201
10232
  row,
10202
10233
  column: col
@@ -10204,14 +10235,17 @@ function TableInner({
10204
10235
  } catch (err) {
10205
10236
  console.error("cellCallback error", err);
10206
10237
  }
10207
- }, []);
10238
+ }, [getAccessorKey, getAccessorValue]);
10208
10239
  const renderCell = React.useCallback((v, accessor, row, col) => {
10240
+ const isNoData = v === undefined;
10241
+
10209
10242
  // Checkbox column type (editable in-table)
10210
10243
  if (col && col.type === 'checkbox') {
10211
10244
  const checked = !!v;
10212
10245
  return /*#__PURE__*/React.createElement("input", {
10213
10246
  type: "checkbox",
10214
10247
  checked: checked,
10248
+ title: isNoData ? translate("noData") : undefined,
10215
10249
  onClick: e => {
10216
10250
  e.stopPropagation();
10217
10251
  triggerCellCallback(row, col, checked);
@@ -10247,6 +10281,7 @@ function TableInner({
10247
10281
  if (col && col.type === 'switch') {
10248
10282
  const checked = !!v;
10249
10283
  return /*#__PURE__*/React.createElement("div", {
10284
+ title: isNoData ? translate("noData") : undefined,
10250
10285
  onClick: e => {
10251
10286
  e.stopPropagation();
10252
10287
  triggerCellCallback(row, col, checked);
@@ -10282,11 +10317,13 @@ function TableInner({
10282
10317
 
10283
10318
  // Input column type (editable text)
10284
10319
  if (col && col.type === 'input') {
10285
- const text = v == null ? "" : String(v);
10320
+ const text = isNoData ? "" : v == null ? "" : String(v);
10286
10321
  return /*#__PURE__*/React.createElement("input", {
10287
10322
  type: "text",
10288
10323
  className: "table-cell-input",
10289
10324
  value: text,
10325
+ placeholder: isNoData ? "..." : undefined,
10326
+ title: isNoData ? translate("noData") : text,
10290
10327
  onClick: e => {
10291
10328
  e.stopPropagation();
10292
10329
  triggerCellCallback(row, col, text);
@@ -10321,6 +10358,11 @@ function TableInner({
10321
10358
  }
10322
10359
  });
10323
10360
  }
10361
+ if (isNoData) {
10362
+ return /*#__PURE__*/React.createElement("span", {
10363
+ title: translate("noData")
10364
+ }, "...");
10365
+ }
10324
10366
 
10325
10367
  // If column has dateFormat, format value as date/time
10326
10368
  if (col && col.dateFormat && v) {
@@ -10366,7 +10408,7 @@ function TableInner({
10366
10408
  }
10367
10409
  // existing highlight logic for other fields
10368
10410
  return highlight(String(v));
10369
- }, [highlight, isGrouped, triggerCellCallback]);
10411
+ }, [highlight, isGrouped, triggerCellCallback, translate]);
10370
10412
  const showView = buttons.includes("view");
10371
10413
  const showEdit = buttons.includes("edit");
10372
10414
  // show delete only when view is also shown (per request)
@@ -10703,6 +10745,8 @@ function TableInner({
10703
10745
  maxWidth: keyWidth
10704
10746
  } : undefined
10705
10747
  }, visualIndex), allColumns.map((col, i) => {
10748
+ const resolvedAccessor = getAccessorKey(row, col.accessor);
10749
+ const cellValue = getAccessorValue(row, col.accessor);
10706
10750
  let cellStyle = col.style ? {
10707
10751
  ...col.style
10708
10752
  } : undefined;
@@ -10717,7 +10761,7 @@ function TableInner({
10717
10761
  className: "table-cell",
10718
10762
  style: cellStyle,
10719
10763
  onClick: () => triggerCellCallback(row, col)
10720
- }, col.isCustom ? typeof col.render === 'function' ? col.render(row, i) : col.render : renderCell(row[col.accessor], col.accessor, row, col));
10764
+ }, col.isCustom ? typeof col.render === 'function' ? col.render(row, i) : col.render : renderCell(cellValue, resolvedAccessor, row, col));
10721
10765
  })), showActions && /*#__PURE__*/React.createElement("div", {
10722
10766
  className: "table-cell action-cell",
10723
10767
  style: actionColumnStyle
@@ -10791,7 +10835,7 @@ function TableInner({
10791
10835
  }, content);
10792
10836
  }
10793
10837
  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]);
10838
+ }, [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
10839
  const rowHeightGetter = ({
10796
10840
  index
10797
10841
  }) => tableDataFlat[index]?.type === "group" ? groupHeaderHeight : rowHeight;
@@ -10890,7 +10934,7 @@ function TableInner({
10890
10934
  style: cellStyle,
10891
10935
  title: headerTitle,
10892
10936
  onClick: col.isCustom ? undefined : () => setSort(col.accessor)
10893
- }, col.isCustom ? translatedHeader ?? "" : translatedHeader, !col.isCustom && sorting?.column === col.accessor && (sorting.direction === "asc" ? " ↑" : " ↓"));
10937
+ }, col.isCustom ? translatedHeader ?? "" : translatedHeader, !col.isCustom && isSameAccessor(sorting?.column, col.accessor) && (sorting.direction === "asc" ? " ↑" : " ↓"));
10894
10938
  }), showActions && /*#__PURE__*/React.createElement("div", {
10895
10939
  className: "table-cell action-cell",
10896
10940
  style: actionColumnStyle,