Skip to content

Commit

Permalink
Refactor logic for handling page change (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dagonite authored Feb 10, 2025
1 parent 7cf65c4 commit e8b0daf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/Jobs/JobsAll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ const JobsAll: React.FC = () => {
totalRows={totalRows}
currentPage={currentPage}
rowsPerPage={rowsPerPage}
handleChangePage={(_, newPage) => setCurrentPage(newPage)} // Update page number
handleChangeRowsPerPage={(e) => setRowsPerPage(parseInt(e.target.value, 10))} // Update rows per page based on what the user has selected (10 is the radix, do not confuse for number of rows)
handleChangePage={(_, newPage) => setCurrentPage(newPage)}
handleChangeRowsPerPage={(e) => {
setRowsPerPage(parseInt(e.target.value, 10));
setCurrentPage(Math.floor((currentPage * rowsPerPage) / parseInt(e.target.value, 10))); // Prevents the offset from going out of range (NOTE: 10 is the radix for the parseInt func, do not confuse for number of rows)
}}
handleSort={(property) => {
const isAsc = orderBy === property && orderDirection === 'asc';
setOrderDirection(isAsc ? 'desc' : 'asc'); // Toggle sorting order
Expand Down
7 changes: 5 additions & 2 deletions src/Jobs/JobsGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ const JobsGeneral: React.FC = () => {
totalRows={totalRows}
currentPage={currentPage}
rowsPerPage={rowsPerPage}
handleChangePage={(_, newPage) => setCurrentPage(newPage)} // Update page number
handleChangeRowsPerPage={(e) => setRowsPerPage(parseInt(e.target.value, 10))} // Update rows per page based on what user has selected (10 is the radix, do not confuse for number of rows)
handleChangePage={(_, newPage) => setCurrentPage(newPage)}
handleChangeRowsPerPage={(e) => {
setRowsPerPage(parseInt(e.target.value, 10));
setCurrentPage(Math.floor((currentPage * rowsPerPage) / parseInt(e.target.value, 10))); // Prevents the offset from going out of range (NOTE: 10 is the radix for the parseInt func, do not confuse for number of rows)
}}
handleSort={(property) => {
const isAsc = orderBy === property && orderDirection === 'asc';
setOrderDirection(isAsc ? 'desc' : 'asc'); // Toggle sorting order
Expand Down

0 comments on commit e8b0daf

Please sign in to comment.