trotl-table 1.0.50 → 1.0.52
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/README.md +1 -0
- package/dist/Table.cjs.js +39 -31
- package/dist/Table.cjs.js.map +1 -1
- package/dist/Table.esm.js +40 -32
- package/dist/Table.esm.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,6 +122,7 @@ export default function Demo() {
|
|
|
122
122
|
- `showKey`: show row key (true/false)
|
|
123
123
|
- `enableDragRow`: enable drag‑and‑drop (true/false)
|
|
124
124
|
- `selectedRowsCallback`: callback with selected row IDs
|
|
125
|
+
- `initialSelectedRows` (or `initaialSelectedRows`): initial selected row IDs (or row objects with `id`) for preselection
|
|
125
126
|
- `editCallback`: callback when editing a row
|
|
126
127
|
- `viewCallback`: callback when viewing a row
|
|
127
128
|
- `deleteCallback`: async callback for deleting a row
|
package/dist/Table.cjs.js
CHANGED
|
@@ -9662,6 +9662,8 @@ function TableInner({
|
|
|
9662
9662
|
enableDragRow = false,
|
|
9663
9663
|
enableSearchUrlParam = false,
|
|
9664
9664
|
enableMultiSelect = false,
|
|
9665
|
+
initialSelectedRows = [],
|
|
9666
|
+
initaialSelectedRows,
|
|
9665
9667
|
enableExternalRowDrop = false,
|
|
9666
9668
|
onExternalRowDrop = () => {},
|
|
9667
9669
|
useExternalDndContext = false,
|
|
@@ -9724,11 +9726,40 @@ function TableInner({
|
|
|
9724
9726
|
React.useEffect(() => {
|
|
9725
9727
|
duplicateCallbackRef.current = duplicateCallback;
|
|
9726
9728
|
}, [duplicateCallback]);
|
|
9729
|
+
const resolvedInitialSelectedRows = React.useMemo(() => {
|
|
9730
|
+
const source = Array.isArray(initialSelectedRows) ? initialSelectedRows : Array.isArray(initaialSelectedRows) ? initaialSelectedRows : [];
|
|
9731
|
+
return [...new Set(source.map(item => item && typeof item === "object" ? item.id : item).filter(id => id != null))];
|
|
9732
|
+
}, [initialSelectedRows, initaialSelectedRows]);
|
|
9727
9733
|
|
|
9728
9734
|
// Local selection & sorting state (removed TableContext dependency)
|
|
9729
|
-
const [selectedRows, setSelectedRows] = React.useState(
|
|
9735
|
+
const [selectedRows, setSelectedRows] = React.useState(() => resolvedInitialSelectedRows);
|
|
9730
9736
|
const [sorting, setSorting] = React.useState(null);
|
|
9731
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
|
+
// Sync whenever initialSelectedRows changes (handles parent updates like clearing selection)
|
|
9743
|
+
React.useEffect(() => {
|
|
9744
|
+
// Validate: only apply IDs that exist in current data
|
|
9745
|
+
const allRowIds = new Set();
|
|
9746
|
+
const collectRowIds = rowsData => {
|
|
9747
|
+
if (Array.isArray(rowsData)) {
|
|
9748
|
+
rowsData.forEach(item => {
|
|
9749
|
+
if (item.id) allRowIds.add(item.id);
|
|
9750
|
+
if (Array.isArray(item.rows)) {
|
|
9751
|
+
item.rows.forEach(r => allRowIds.add(r.id));
|
|
9752
|
+
}
|
|
9753
|
+
});
|
|
9754
|
+
}
|
|
9755
|
+
};
|
|
9756
|
+
collectRowIds(isGrouped ? localData : localData);
|
|
9757
|
+
|
|
9758
|
+
// Filter to only valid IDs (handles async data loads + parent updates)
|
|
9759
|
+
const validIds = resolvedInitialSelectedRows.filter(id => allRowIds.has(id) || allRowIds.size === 0);
|
|
9760
|
+
setSelectedRows(validIds);
|
|
9761
|
+
}, [resolvedInitialSelectedRows, localData, isGrouped]);
|
|
9762
|
+
|
|
9732
9763
|
// Option to read search param from URL
|
|
9733
9764
|
const [searchTerm, setSearchTerm] = React.useState(extraSearchTerm);
|
|
9734
9765
|
// Track current URL search so date filters rerun when params change
|
|
@@ -9797,8 +9828,6 @@ function TableInner({
|
|
|
9797
9828
|
|
|
9798
9829
|
// console.log(extraSearchTerm)
|
|
9799
9830
|
|
|
9800
|
-
const [localData, setLocalData] = React.useState(data);
|
|
9801
|
-
React.useEffect(() => setLocalData(data), [data]);
|
|
9802
9831
|
const listRef = React.useRef(null);
|
|
9803
9832
|
const headerRef = React.useRef(null);
|
|
9804
9833
|
const [headerPadRight, setHeaderPadRight] = React.useState(0);
|
|
@@ -10389,15 +10418,6 @@ function TableInner({
|
|
|
10389
10418
|
key,
|
|
10390
10419
|
style
|
|
10391
10420
|
}) => {
|
|
10392
|
-
// override virtualization's fixed width so that flex-based cells can
|
|
10393
|
-
// expand/contract with the header. without this the header adjusts but
|
|
10394
|
-
// rows keep the original pixel width from the first render, leading to
|
|
10395
|
-
// the mismatched behaviour described by the user.
|
|
10396
|
-
const fullStyle = {
|
|
10397
|
-
...style,
|
|
10398
|
-
width: "100%",
|
|
10399
|
-
boxSizing: "border-box"
|
|
10400
|
-
};
|
|
10401
10421
|
const item = tableDataFlat[index];
|
|
10402
10422
|
if (!item) return null;
|
|
10403
10423
|
if (item.type === "group") {
|
|
@@ -10430,7 +10450,7 @@ function TableInner({
|
|
|
10430
10450
|
ref: ref,
|
|
10431
10451
|
key: key,
|
|
10432
10452
|
style: {
|
|
10433
|
-
...
|
|
10453
|
+
...style,
|
|
10434
10454
|
background: '#f6f6fa',
|
|
10435
10455
|
border: '2px dashed #bbb',
|
|
10436
10456
|
textAlign: 'center',
|
|
@@ -10480,7 +10500,7 @@ function TableInner({
|
|
|
10480
10500
|
// Default: normal group header
|
|
10481
10501
|
return /*#__PURE__*/React.createElement("div", {
|
|
10482
10502
|
key: key,
|
|
10483
|
-
style:
|
|
10503
|
+
style: style,
|
|
10484
10504
|
className: "table-row group-row",
|
|
10485
10505
|
onClick: () => toggleGroup(gid)
|
|
10486
10506
|
}, enableMultiSelect && showDelete && /*#__PURE__*/React.createElement("div", {
|
|
@@ -10541,15 +10561,14 @@ function TableInner({
|
|
|
10541
10561
|
};
|
|
10542
10562
|
const content = /*#__PURE__*/React.createElement("div", {
|
|
10543
10563
|
key: key,
|
|
10544
|
-
style:
|
|
10564
|
+
style: style,
|
|
10545
10565
|
className: "table-row"
|
|
10546
10566
|
}, /*#__PURE__*/React.createElement("div", {
|
|
10547
10567
|
className: "row-main",
|
|
10548
10568
|
onDoubleClick: doubleClickEnable ? handleRowDoubleClick : undefined,
|
|
10549
10569
|
style: {
|
|
10550
10570
|
display: 'flex',
|
|
10551
|
-
flex:
|
|
10552
|
-
minWidth: 0
|
|
10571
|
+
flex: 1
|
|
10553
10572
|
}
|
|
10554
10573
|
}, enableMultiSelect && showDelete && /*#__PURE__*/React.createElement("div", {
|
|
10555
10574
|
className: "table-cell checkbox-cell"
|
|
@@ -10697,9 +10716,8 @@ function TableInner({
|
|
|
10697
10716
|
position: "sticky",
|
|
10698
10717
|
top: 0,
|
|
10699
10718
|
zIndex: 10,
|
|
10700
|
-
background: "
|
|
10701
|
-
|
|
10702
|
-
paddingRight: undefined
|
|
10719
|
+
background: "#fff",
|
|
10720
|
+
paddingRight: headerPadRight || undefined
|
|
10703
10721
|
}
|
|
10704
10722
|
}, /*#__PURE__*/React.createElement("div", {
|
|
10705
10723
|
className: "table-row header-row"
|
|
@@ -10749,17 +10767,7 @@ function TableInner({
|
|
|
10749
10767
|
title: translate("action")
|
|
10750
10768
|
}, showIcons ? /*#__PURE__*/React.createElement("span", {
|
|
10751
10769
|
title: translate("action")
|
|
10752
|
-
}, "\u2699\uFE0F") : translate("action")),
|
|
10753
|
-
className: "table-cell header-scroll-spacer",
|
|
10754
|
-
style: {
|
|
10755
|
-
flex: `0 0 ${headerPadRight}px`,
|
|
10756
|
-
minWidth: headerPadRight,
|
|
10757
|
-
maxWidth: headerPadRight,
|
|
10758
|
-
padding: 0,
|
|
10759
|
-
border: "none",
|
|
10760
|
-
background: "var(--table-bg)"
|
|
10761
|
-
}
|
|
10762
|
-
}))), /*#__PURE__*/React.createElement("div", {
|
|
10770
|
+
}, "\u2699\uFE0F") : translate("action")))), /*#__PURE__*/React.createElement("div", {
|
|
10763
10771
|
className: "main-table",
|
|
10764
10772
|
ref: listRef
|
|
10765
10773
|
}, tableDataFlat.length === 0 ? /*#__PURE__*/React.createElement(DotsLoading.default, null) : /*#__PURE__*/React.createElement(AutoSizer, null, ({
|