Added action to change rows per page
This commit is contained in:
1 parent
c379348581
commit
1419b20591
2 files changed
+21
-8
No files matched your search
@@ -14,6 +14,8 @@ import {
|
|||||||
Typography,
|
Typography,
|
||||||
Stack,
|
Stack,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
import { setRowsPerPage } from "../../Features/UI/uiSlice";
|
||||||
import LeftArrowDouble from "../../assets/icons/left-arrow-double.svg?react";
|
import LeftArrowDouble from "../../assets/icons/left-arrow-double.svg?react";
|
||||||
import RightArrowDouble from "../../assets/icons/right-arrow-double.svg?react";
|
import RightArrowDouble from "../../assets/icons/right-arrow-double.svg?react";
|
||||||
import LeftArrow from "../../assets/icons/left-arrow.svg?react";
|
import LeftArrow from "../../assets/icons/left-arrow.svg?react";
|
||||||
@@ -142,8 +144,10 @@ const TablePaginationActions = (props) => {
|
|||||||
|
|
||||||
const BasicTable = ({ data, paginated, reversed, rows = 5 }) => {
|
const BasicTable = ({ data, paginated, reversed, rows = 5 }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const { table } = useSelector((state) => state.ui);
|
||||||
|
let rowsPerPage = table.rowsPerPage;
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
const [rowsPerPage, setRowsPerPage] = useState(rows);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPage(0);
|
setPage(0);
|
||||||
@@ -154,7 +158,7 @@ const BasicTable = ({ data, paginated, reversed, rows = 5 }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleChangeRowsPerPage = (event) => {
|
const handleChangeRowsPerPage = (event) => {
|
||||||
setRowsPerPage(parseInt(event.target.value, 10));
|
dispatch(setRowsPerPage(parseInt(event.target.value, 10)));
|
||||||
setPage(0);
|
setPage(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -211,7 +215,12 @@ const BasicTable = ({ data, paginated, reversed, rows = 5 }) => {
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
{paginated && <Stack direction="row" alignItems="center" justifyContent="space-between">
|
{paginated && (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
justifyContent="space-between"
|
||||||
|
>
|
||||||
<Typography sx={{ opacity: 0.7 }}>
|
<Typography sx={{ opacity: 0.7 }}>
|
||||||
Showing {getRange()} of {data.rows.length} monitor(s)
|
Showing {getRange()} of {data.rows.length} monitor(s)
|
||||||
</Typography>
|
</Typography>
|
||||||
@@ -226,7 +235,10 @@ const BasicTable = ({ data, paginated, reversed, rows = 5 }) => {
|
|||||||
ActionsComponent={TablePaginationActions}
|
ActionsComponent={TablePaginationActions}
|
||||||
labelRowsPerPage="Rows per page"
|
labelRowsPerPage="Rows per page"
|
||||||
labelDisplayedRows={({ page, count }) =>
|
labelDisplayedRows={({ page, count }) =>
|
||||||
`Page ${page + 1} of ${Math.max(0, Math.ceil(count / rowsPerPage))}`
|
`Page ${page + 1} of ${Math.max(
|
||||||
|
0,
|
||||||
|
Math.ceil(count / rowsPerPage)
|
||||||
|
)}`
|
||||||
}
|
}
|
||||||
slotProps={{
|
slotProps={{
|
||||||
select: {
|
select: {
|
||||||
@@ -254,7 +266,8 @@ const BasicTable = ({ data, paginated, reversed, rows = 5 }) => {
|
|||||||
}}
|
}}
|
||||||
sx={{ mt: theme.gap.medium }}
|
sx={{ mt: theme.gap.medium }}
|
||||||
/>
|
/>
|
||||||
</Stack>}
|
</Stack>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ const uiSlice = createSlice({
|
|||||||
name: "ui",
|
name: "ui",
|
||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
setTablePreferences: (state, action) => {
|
setRowsPerPage: (state, action) => {
|
||||||
state.table = { ...action };
|
state.table.rowsPerPage = action.payload;
|
||||||
},
|
},
|
||||||
toggleSidebar: (state) => {
|
toggleSidebar: (state) => {
|
||||||
state.sidebar.collapsed = !state.sidebar.collapsed;
|
state.sidebar.collapsed = !state.sidebar.collapsed;
|
||||||
@@ -23,4 +23,4 @@ const uiSlice = createSlice({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default uiSlice.reducer;
|
export default uiSlice.reducer;
|
||||||
export const { setTablePreferences, toggleSidebar } = uiSlice.actions;
|
export const { setRowsPerPage, toggleSidebar } = uiSlice.actions;
|
||||||
Reference in new issue
Block a user