react-live-data-table 1.0.10 → 1.0.12
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/package.json +1 -1
- package/src/ReactDataTable.jsx +16 -9
package/package.json
CHANGED
package/src/ReactDataTable.jsx
CHANGED
@@ -16,7 +16,8 @@ function ReactDataTable({
|
|
16
16
|
emptyText,
|
17
17
|
rowHeights = 40,
|
18
18
|
headerProps = {},
|
19
|
-
selected={}
|
19
|
+
selected = {},
|
20
|
+
showSelectAllCheckbox=true
|
20
21
|
}) {
|
21
22
|
const tableContainerRef = React.useRef(null);
|
22
23
|
const [data, setData] = React.useState({ pages: [], meta: { totalPages: 1 } });
|
@@ -24,10 +25,10 @@ function ReactDataTable({
|
|
24
25
|
const [pageParam, setPageParam] = React.useState(1);
|
25
26
|
const [selectedRows, setSelectedRows] = React.useState(selected);
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
setSelectedRows({...selected})
|
30
|
-
|
28
|
+
|
29
|
+
useEffect(() => {
|
30
|
+
setSelectedRows({ ...selected })
|
31
|
+
}, [selected])
|
31
32
|
|
32
33
|
useEffect(() => {
|
33
34
|
setData({ pages: [], meta: { totalPages: 1 } });
|
@@ -158,9 +159,14 @@ function ReactDataTable({
|
|
158
159
|
}
|
159
160
|
};
|
160
161
|
|
162
|
+
// This is the problem area - it was causing an infinite loop
|
161
163
|
useEffect(() => {
|
162
|
-
|
163
|
-
|
164
|
+
const containerElement = tableContainerRef.current;
|
165
|
+
if (containerElement && !staticData) {
|
166
|
+
handleScroll(containerElement);
|
167
|
+
}
|
168
|
+
// Don't include 'data' as a dependency here
|
169
|
+
}, [pageParam, isFetching]); // Only depend on pageParam and isFetching
|
164
170
|
|
165
171
|
const flatData = data.pages.flatMap(page => page.data);
|
166
172
|
|
@@ -170,7 +176,7 @@ function ReactDataTable({
|
|
170
176
|
minWidth: 50,
|
171
177
|
textAlign: "center",
|
172
178
|
header: ({ data }) => (
|
173
|
-
<div className="flex items-center justify-center h-[40px]">
|
179
|
+
showSelectAllCheckbox ? <div className="flex items-center justify-center h-[40px]">
|
174
180
|
<input
|
175
181
|
id={data.id}
|
176
182
|
type="checkbox"
|
@@ -179,6 +185,8 @@ function ReactDataTable({
|
|
179
185
|
onChange={(e) => handleSelectAll(e.target.checked, flatData)}
|
180
186
|
/>
|
181
187
|
</div>
|
188
|
+
:
|
189
|
+
<div className="flex items-center justify-center h-[40px]"></div>
|
182
190
|
),
|
183
191
|
cell: ({ row }) => {
|
184
192
|
return (
|
@@ -279,7 +287,6 @@ function ReactDataTable({
|
|
279
287
|
>
|
280
288
|
{enhancedColumns.map(column => (
|
281
289
|
<td
|
282
|
-
|
283
290
|
key={column.accessorKey || column.id}
|
284
291
|
className={`text-left font-normal border-r ${column?.cellProps?.className || ''}`}
|
285
292
|
style={{
|