Reputation: 10236
in looking at the following documentation (which I believe to be official):
nowhere does it suggest that a user can click on the table nor, if it does, how to pick up the event. I've seen posts everywhere about how 'onClick' doesn't work in various situations and various hacks and workarounds but if it's not in the official documentation, is the position of Material UI that tables cannot be clicked on?
and if it's possible, how do I do it?
Upvotes: 0
Views: 85
Reputation: 3063
I hope i got you right. But it is possible to use onClick
on material-ui's table components.
I took the SimpleTable example from material-ui documentation and added onClick
property to component.
https://codesandbox.io/s/immutable-field-lm7p9?file=/src/SimpleTable.js
<Table className={classes.table} onClick={() => alert("Table Click")}>
(Works on Cells and Rows as well)
Edit:
So, as for your question in the comments: Material-UI Table component is, at the end of the day, a React component.
(You can take a look at the source to explore this and other things)
Every React component has the known HTML/JS events like onClick etc... these events get the function that triggers once the event happens as an argument (it could be alert() like I made In the example.
Upvotes: 1