trotl-table 1.0.70 → 1.0.71

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
@@ -9965,6 +9965,19 @@ function TableInner({
9965
9965
  }
9966
9966
  return a === b;
9967
9967
  }, []);
9968
+ const formatArrayValue = React.useCallback((value, col) => {
9969
+ if (!Array.isArray(value)) return value;
9970
+ const objectKey = col?.objectKey;
9971
+ const parts = value.map(item => {
9972
+ if (item == null) return "";
9973
+ if (typeof item !== "object") return String(item);
9974
+ if (objectKey && item?.[objectKey] !== undefined) return String(item[objectKey]);
9975
+ if (item.label !== undefined) return String(item.label);
9976
+ if (item.value !== undefined) return String(item.value);
9977
+ return JSON.stringify(item);
9978
+ }).filter(item => item !== "");
9979
+ return parts.join(", ");
9980
+ }, []);
9968
9981
 
9969
9982
  // console.log(extraSearchTerm)
9970
9983
 
@@ -10051,13 +10064,16 @@ function TableInner({
10051
10064
  const query = searchTerm.toLowerCase();
10052
10065
  return dateFiltered.filter(row => columns.some(col => {
10053
10066
  const val = getAccessorValue(row, col.accessor);
10054
- if (val == null) return false;
10055
- return String(val).toLowerCase().includes(query);
10067
+ const normalized = Array.isArray(val) ? formatArrayValue(val, col) : val;
10068
+ if (normalized == null) return false;
10069
+ return String(normalized).toLowerCase().includes(query);
10056
10070
  }));
10057
- }, [searchTerm, columns, urlSearchString, getAccessorValue]);
10071
+ }, [searchTerm, columns, urlSearchString, getAccessorValue, formatArrayValue]);
10058
10072
 
10059
10073
  // Natural-ish comparator: handles nulls, numbers, strings, ISO dates
10060
10074
  const compare = (x, y, dir = "asc") => {
10075
+ if (Array.isArray(x)) x = formatArrayValue(x);
10076
+ if (Array.isArray(y)) y = formatArrayValue(y);
10061
10077
  const nullCmp = () => {
10062
10078
  if (x == null && y == null) return 0;
10063
10079
  if (x == null) return 1; // nulls last
@@ -10492,6 +10508,15 @@ function TableInner({
10492
10508
  title: formatted
10493
10509
  }, formatted);
10494
10510
  }
10511
+ if (col && col.type === 'array') {
10512
+ const arr = Array.isArray(v) ? v : [];
10513
+ const list = formatArrayValue(arr, col);
10514
+ const count = arr.length;
10515
+ const display = count > 0 ? `${count}: ${list}` : "...";
10516
+ return /*#__PURE__*/React.createElement("span", {
10517
+ title: list || translate("noData")
10518
+ }, display);
10519
+ }
10495
10520
 
10496
10521
  // If column has dateFormat, format value as date/time
10497
10522
  if (col && col.dateFormat && v) {
@@ -10537,7 +10562,7 @@ function TableInner({
10537
10562
  }
10538
10563
  // existing highlight logic for other fields
10539
10564
  return highlight(String(v));
10540
- }, [highlight, isGrouped, triggerCellCallback, translate]);
10565
+ }, [highlight, isGrouped, triggerCellCallback, translate, formatArrayValue]);
10541
10566
  const showView = buttons.includes("view");
10542
10567
  const showEdit = buttons.includes("edit");
10543
10568
  // show delete only when view is also shown (per request)