diff --git a/Client/src/Components/BasicTable/index.jsx b/Client/src/Components/BasicTable/index.jsx index a80c7bfb6..7457b7abf 100644 --- a/Client/src/Components/BasicTable/index.jsx +++ b/Client/src/Components/BasicTable/index.jsx @@ -20,6 +20,7 @@ import PropTypes from "prop-types"; * @param {Array} props.headers - Array of header titles for the table. * @param {Array} props.rowItems - Array of row data objects for the table. * @param {boolean} props.paginated - Flag to enable pagination. + * @param {function} props.handleClick - Function to handle click on row. * * @example * @@ -47,6 +48,10 @@ import PropTypes from "prop-types"; * { id: 3, data:
5
}, * // More rows... * ]; + * + * ROW CLICK HANDLING + * If you want to set a listener for a row click, you can add a handleClick function to FIRST ITEM IN EACH ROW + * * */ @@ -94,7 +99,14 @@ const BasicTable = ({ headers, rowItems, paginated }) => { {paginated === false && Object.keys(groupedRowItems).map((key) => { return ( - + { + groupedRowItems[key].items[0].item.handleClick + ? groupedRowItems[key].items[0].item.handleClick() + : null; + }} + key={groupedRowItems[key].idx} + > {groupedRowItems[key].items.map(({ item }) => { return {item.data}; })} @@ -103,7 +115,14 @@ const BasicTable = ({ headers, rowItems, paginated }) => { })} {paginated === true && paginatedRowsKeys.map((key) => ( - + { + groupedRowItems[key].items[0].item.handleClick + ? groupedRowItems[key].items[0].item.handleClick() + : null; + }} + key={groupedRowItems[key].idx} + > {groupedRowItems[key].items.map(({ item }) => ( {item.data} ))} @@ -141,6 +160,7 @@ BasicTable.propTypes = { }) ).isRequired, paginated: PropTypes.bool, + handleClick: PropTypes.func, }; export default BasicTable; diff --git a/Client/src/Components/MonitorTable/index.jsx b/Client/src/Components/MonitorTable/index.jsx index 6904978c8..f26b44a78 100644 --- a/Client/src/Components/MonitorTable/index.jsx +++ b/Client/src/Components/MonitorTable/index.jsx @@ -122,9 +122,21 @@ const MonitorTable = ({ monitors = [] }) => { }); data.push({ id: data.length + 1, + data: , + handleClick: () => { + console.log(monitor._id); + }, + }); + data.push({ + id: data.length + 1, + data: , + }); + data.push({ + id: data.length + 1, + data: , }); - data.push({ id: data.length + 1, data: "TODO" }); + data.push({ id: data.length + 1, itemId: monitor._id, data: "TODO" }); }); return ;