Skip to content

Commit 58ffd6d

Browse files
author
naharbi
committed
fix: datatable don't reset pagination on init
- don't set currentPage to 0 on first render - remove searchParams internal state
1 parent 05d9cde commit 58ffd6d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/data-table/RruDataTable.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { FC, useEffect, useState } from 'react';
17+
import { FC, useEffect, useRef, useState } from 'react';
1818
import { resolveObjectAttribute } from '../utils/utils';
1919
import useDataSource from './hooks/useDataSource';
2020
import PaginationView from './pagination/PaginationView';
@@ -40,10 +40,13 @@ const RruDataTable: FC<RruDataTableProps> = ({
4040
const [currentPage, setCurrentPage] = useState(defaultPageNumber || 0);
4141
const [sortKey, setSortKey] = useState(defaultSortKey);
4242
const [sortDir, setSortDir] = useState<SortDir>(defaultSortDir);
43-
const [searchParams, setSearchParams] = useState<any>(search);
43+
const hasInit = useRef(false);
4444

4545
useEffect(() => {
46-
setSearchParams(search);
46+
if(!hasInit.current) {
47+
hasInit.current = true;
48+
return;
49+
}
4750
setCurrentPage(0);
4851
}, [search]);
4952

@@ -53,7 +56,7 @@ const RruDataTable: FC<RruDataTableProps> = ({
5356
currentPage,
5457
sortKey,
5558
sortDir,
56-
searchParams,
59+
search,
5760
onChange
5861
);
5962

0 commit comments

Comments
 (0)