trotl-table 1.0.51 → 1.0.53
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 +38 -3
- package/dist/Table.cjs.js.map +1 -1
- package/dist/Table.esm.js +38 -3
- package/dist/Table.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/Table.cjs.js
CHANGED
|
@@ -9734,8 +9734,45 @@ function TableInner({
|
|
|
9734
9734
|
// Local selection & sorting state (removed TableContext dependency)
|
|
9735
9735
|
const [selectedRows, setSelectedRows] = React.useState(() => resolvedInitialSelectedRows);
|
|
9736
9736
|
const [sorting, setSorting] = React.useState(null);
|
|
9737
|
+
|
|
9738
|
+
// Initialize localData early so it's available for the sync effect below
|
|
9739
|
+
const [localData, setLocalData] = React.useState(data);
|
|
9740
|
+
React.useEffect(() => setLocalData(data), [data]);
|
|
9741
|
+
|
|
9742
|
+
// Track the last applied initialSelectedRows to detect changes and prevent loops
|
|
9743
|
+
const lastSyncedRef = React.useRef(null);
|
|
9744
|
+
|
|
9745
|
+
// Sync only when initialSelectedRows prop itself changes (from parent), not on every data update
|
|
9737
9746
|
React.useEffect(() => {
|
|
9738
|
-
|
|
9747
|
+
// Skip if this is the same as the last time we synced (prevents feedback loops)
|
|
9748
|
+
const isSame = lastSyncedRef.current && lastSyncedRef.current.length === resolvedInitialSelectedRows.length && lastSyncedRef.current.every(id => resolvedInitialSelectedRows.includes(id));
|
|
9749
|
+
if (isSame) return;
|
|
9750
|
+
|
|
9751
|
+
// Validate: only apply IDs that exist in current data
|
|
9752
|
+
const allRowIds = new Set();
|
|
9753
|
+
const collectRowIds = rowsData => {
|
|
9754
|
+
if (Array.isArray(rowsData)) {
|
|
9755
|
+
rowsData.forEach(item => {
|
|
9756
|
+
if (item.id) allRowIds.add(item.id);
|
|
9757
|
+
if (Array.isArray(item.rows)) {
|
|
9758
|
+
item.rows.forEach(r => allRowIds.add(r.id));
|
|
9759
|
+
}
|
|
9760
|
+
});
|
|
9761
|
+
}
|
|
9762
|
+
};
|
|
9763
|
+
collectRowIds(isGrouped ? localData : localData);
|
|
9764
|
+
|
|
9765
|
+
// Filter to only valid IDs (handles async data loads + parent updates)
|
|
9766
|
+
const validIds = resolvedInitialSelectedRows.filter(id => allRowIds.has(id) || allRowIds.size === 0);
|
|
9767
|
+
|
|
9768
|
+
// Only update if different from current
|
|
9769
|
+
setSelectedRows(prev => {
|
|
9770
|
+
if (prev.length === validIds.length && prev.every(id => validIds.includes(id))) {
|
|
9771
|
+
return prev; // No change, prevent re-render
|
|
9772
|
+
}
|
|
9773
|
+
return validIds;
|
|
9774
|
+
});
|
|
9775
|
+
lastSyncedRef.current = resolvedInitialSelectedRows;
|
|
9739
9776
|
}, [resolvedInitialSelectedRows]);
|
|
9740
9777
|
|
|
9741
9778
|
// Option to read search param from URL
|
|
@@ -9806,8 +9843,6 @@ function TableInner({
|
|
|
9806
9843
|
|
|
9807
9844
|
// console.log(extraSearchTerm)
|
|
9808
9845
|
|
|
9809
|
-
const [localData, setLocalData] = React.useState(data);
|
|
9810
|
-
React.useEffect(() => setLocalData(data), [data]);
|
|
9811
9846
|
const listRef = React.useRef(null);
|
|
9812
9847
|
const headerRef = React.useRef(null);
|
|
9813
9848
|
const [headerPadRight, setHeaderPadRight] = React.useState(0);
|