Added reverse prop to BasicTable to allow for reversing order of data
This commit is contained in:
1 parent
73801fa6cc
commit
5819efadf7
2 files changed
+7
-4
No files matched your search
@@ -32,6 +32,7 @@ import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded";
|
|||||||
* @param {JSX.Element} props.data.rows[].data[].data - The content to display in the cell.
|
* @param {JSX.Element} props.data.rows[].data[].data - The content to display in the cell.
|
||||||
* @param {function} props.data.rows.data.handleClick - Function to call when the row is clicked.
|
* @param {function} props.data.rows.data.handleClick - Function to call when the row is clicked.
|
||||||
* @param {boolean} [props.paginated=false] - Flag to enable pagination.
|
* @param {boolean} [props.paginated=false] - Flag to enable pagination.
|
||||||
|
* @param {boolean} [props.reversed=false] - Flag to enable reverse order.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const data = {
|
* const data = {
|
||||||
@@ -66,7 +67,7 @@ import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded";
|
|||||||
* <BasicTable data={data} rows={rows} paginated={true} />
|
* <BasicTable data={data} rows={rows} paginated={true} />
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const BasicTable = ({ data, paginated }) => {
|
const BasicTable = ({ data, paginated, reversed }) => {
|
||||||
// Add headers to props validation
|
// Add headers to props validation
|
||||||
|
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
@@ -79,9 +80,10 @@ const BasicTable = ({ data, paginated }) => {
|
|||||||
let displayData = [];
|
let displayData = [];
|
||||||
|
|
||||||
if (data && data.rows) {
|
if (data && data.rows) {
|
||||||
|
let rows = reversed ? [...data.rows].reverse() : data.rows;
|
||||||
displayData = paginated
|
displayData = paginated
|
||||||
? data.rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
|
? rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
|
||||||
: data.rows;
|
: rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data || !data.cols || !data.rows) {
|
if (!data || !data.cols || !data.rows) {
|
||||||
@@ -149,6 +151,7 @@ const BasicTable = ({ data, paginated }) => {
|
|||||||
BasicTable.propTypes = {
|
BasicTable.propTypes = {
|
||||||
data: PropTypes.object.isRequired,
|
data: PropTypes.object.isRequired,
|
||||||
paginated: PropTypes.bool,
|
paginated: PropTypes.bool,
|
||||||
|
reversed: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default BasicTable;
|
export default BasicTable;
|
||||||
@@ -298,7 +298,7 @@ const DetailsPage = () => {
|
|||||||
<Typography component="h2" mb={theme.gap.ml}>
|
<Typography component="h2" mb={theme.gap.ml}>
|
||||||
History
|
History
|
||||||
</Typography>
|
</Typography>
|
||||||
<BasicTable data={data} paginated={true} />
|
<BasicTable data={data} paginated={true} reversed={true} />
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user