trotl-table 1.0.20 → 1.0.22
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.cjs.js +78 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +78 -4
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -9844,9 +9844,50 @@ function TableInner({
|
|
|
9844
9844
|
return normalizeData(isGrouped ? localData : [], isGrouped ? [] : localData);
|
|
9845
9845
|
}, [localData, isGrouped]);
|
|
9846
9846
|
const filterRows = React.useCallback(rows => {
|
|
9847
|
-
|
|
9847
|
+
// Check for date-related URL params first
|
|
9848
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
9849
|
+
const dateParams = ['startDate', 'endDate', 'date'];
|
|
9850
|
+
let dateFiltered = rows;
|
|
9851
|
+
for (const paramKey of dateParams) {
|
|
9852
|
+
const paramValue = urlParams.get(paramKey);
|
|
9853
|
+
if (!paramValue) continue;
|
|
9854
|
+
|
|
9855
|
+
// Check if it's a range (contains ~)
|
|
9856
|
+
if (paramValue.includes('~')) {
|
|
9857
|
+
const [startTs, endTs] = paramValue.split('~').map(Number);
|
|
9858
|
+
if (isNaN(startTs) || isNaN(endTs)) continue;
|
|
9859
|
+
dateFiltered = dateFiltered.filter(row => {
|
|
9860
|
+
// Check if any date field in the row falls within the range
|
|
9861
|
+
const itemStartDate = row.startDate ? new Date(row.startDate).getTime() : null;
|
|
9862
|
+
const itemEndDate = row.endDate ? new Date(row.endDate).getTime() : null;
|
|
9863
|
+
const itemDate = row.date ? new Date(row.date).getTime() : null;
|
|
9864
|
+
|
|
9865
|
+
// Match if any date field overlaps with the range
|
|
9866
|
+
return itemStartDate && itemStartDate >= startTs && itemStartDate <= endTs || itemEndDate && itemEndDate >= startTs && itemEndDate <= endTs || itemDate && itemDate >= startTs && itemDate <= endTs ||
|
|
9867
|
+
// Check if event spans the entire range
|
|
9868
|
+
itemStartDate && itemEndDate && itemStartDate <= startTs && itemEndDate >= endTs;
|
|
9869
|
+
});
|
|
9870
|
+
} else {
|
|
9871
|
+
// Single timestamp
|
|
9872
|
+
const timestamp = Number(paramValue);
|
|
9873
|
+
if (isNaN(timestamp)) continue;
|
|
9874
|
+
dateFiltered = dateFiltered.filter(row => {
|
|
9875
|
+
const itemStartDate = row.startDate ? new Date(row.startDate).getTime() : null;
|
|
9876
|
+
const itemEndDate = row.endDate ? new Date(row.endDate).getTime() : null;
|
|
9877
|
+
const itemDate = row.date ? new Date(row.date).getTime() : null;
|
|
9878
|
+
|
|
9879
|
+
// Match if the timestamp falls within the event's date range or matches the date
|
|
9880
|
+
return itemDate && Math.abs(itemDate - timestamp) < 86400000 ||
|
|
9881
|
+
// Same day (within 24h)
|
|
9882
|
+
itemStartDate && itemEndDate && itemStartDate <= timestamp && itemEndDate >= timestamp || itemStartDate && Math.abs(itemStartDate - timestamp) < 86400000 || itemEndDate && Math.abs(itemEndDate - timestamp) < 86400000;
|
|
9883
|
+
});
|
|
9884
|
+
}
|
|
9885
|
+
}
|
|
9886
|
+
|
|
9887
|
+
// Then apply text search filter
|
|
9888
|
+
if (!searchTerm) return dateFiltered;
|
|
9848
9889
|
const query = searchTerm.toLowerCase();
|
|
9849
|
-
return
|
|
9890
|
+
return dateFiltered.filter(row => columns.some(col => {
|
|
9850
9891
|
const val = row[col.accessor];
|
|
9851
9892
|
if (val == null) return false;
|
|
9852
9893
|
return String(val).toLowerCase().includes(query);
|
|
@@ -10051,7 +10092,40 @@ function TableInner({
|
|
|
10051
10092
|
title: text
|
|
10052
10093
|
}, text.slice(idx + query.length)));
|
|
10053
10094
|
}, [searchTerm]);
|
|
10054
|
-
const renderCell = React.useCallback((v, accessor) => {
|
|
10095
|
+
const renderCell = React.useCallback((v, accessor, row, col) => {
|
|
10096
|
+
// If column has dateFormat, format value as date/time
|
|
10097
|
+
if (col && col.dateFormat && v) {
|
|
10098
|
+
let dateObj = null;
|
|
10099
|
+
if (typeof v === "string" || typeof v === "number") {
|
|
10100
|
+
dateObj = new Date(v);
|
|
10101
|
+
} else if (v instanceof Date) {
|
|
10102
|
+
dateObj = v;
|
|
10103
|
+
}
|
|
10104
|
+
if (dateObj && !isNaN(dateObj.getTime())) {
|
|
10105
|
+
// Always use 24-hour format for 'YYYY-MM-DD HH:mm'
|
|
10106
|
+
if (col.dateFormat === "YYYY-MM-DD HH:mm") {
|
|
10107
|
+
const y = dateObj.getFullYear();
|
|
10108
|
+
const m = String(dateObj.getMonth() + 1).padStart(2, "0");
|
|
10109
|
+
const d = String(dateObj.getDate()).padStart(2, "0");
|
|
10110
|
+
const h = String(dateObj.getHours()).padStart(2, "0");
|
|
10111
|
+
const min = String(dateObj.getMinutes()).padStart(2, "0");
|
|
10112
|
+
return `${y}-${m}-${d} ${h}:${min}`;
|
|
10113
|
+
}
|
|
10114
|
+
if (col.dateFormat === "DD-MM-YYYY HH:mm") {
|
|
10115
|
+
const y = dateObj.getFullYear();
|
|
10116
|
+
const m = String(dateObj.getMonth() + 1).padStart(2, "0");
|
|
10117
|
+
const d = String(dateObj.getDate()).padStart(2, "0");
|
|
10118
|
+
const h = String(dateObj.getHours()).padStart(2, "0");
|
|
10119
|
+
const min = String(dateObj.getMinutes()).padStart(2, "0");
|
|
10120
|
+
return `${d}-${m}-${y} ${h}:${min}`;
|
|
10121
|
+
}
|
|
10122
|
+
// Fallback: use toLocaleString with 24-hour option
|
|
10123
|
+
return dateObj.toLocaleString(undefined, {
|
|
10124
|
+
hour12: false
|
|
10125
|
+
});
|
|
10126
|
+
}
|
|
10127
|
+
}
|
|
10128
|
+
// If accessor is deadlineISO, keep legacy formatting
|
|
10055
10129
|
if (accessor === "deadlineISO") {
|
|
10056
10130
|
return v ? new Date(v).toLocaleString("sl-SI", {
|
|
10057
10131
|
day: "2-digit",
|
|
@@ -10313,7 +10387,7 @@ function TableInner({
|
|
|
10313
10387
|
key: i,
|
|
10314
10388
|
className: "table-cell",
|
|
10315
10389
|
style: cellStyle
|
|
10316
|
-
}, col.isCustom ? typeof col.render === 'function' ? col.render(row, i) : col.render : renderCell(row[col.accessor], col.accessor, row));
|
|
10390
|
+
}, col.isCustom ? typeof col.render === 'function' ? col.render(row, i) : col.render : renderCell(row[col.accessor], col.accessor, row, col));
|
|
10317
10391
|
}), showActions && /*#__PURE__*/React.createElement("div", {
|
|
10318
10392
|
className: "table-cell action-cell"
|
|
10319
10393
|
}, showView && /*#__PURE__*/React.createElement("button", {
|