Skip to content

Commit f22fd2a

Browse files
authored
Merge pull request #39 from nmh1999/fix-datatable-reset-pagination-oninit
fix: datatable don't reset pagination on init
2 parents 05d9cde + 58ffd6d commit f22fd2a

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)