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