Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  94] [ 7]  / answers: 1 / hits: 30547  / 6 Years ago, fri, july 20, 2018, 12:00:00

I have made a table using Material UI where I have two buttons in the first column of every row. I wish to edit/delete rows on clicking these but Im stuck on logic. Is it even possible with my implementation ? If not then what's the preferred way of doing so?



render() {
var deleteIcon =
(<IconButton onClick={console.log(delete)}>
<DeleteIcon color=secondary />
</IconButton>
);

const editIcon = (
<IconButton onClick={console.log(edited)}>
<EditIcon color=primary />
</IconButton>
);

return(
<TableBody>
{this.state.serviceData.map(n => {
return (
<TableRow key={n.id}>
<TableCell style={styles.editor} component=th scope=row>
{deleteIcon}
{editIcon}
</TableCell>
<TableCell>{n.domain}</TableCell>
<TableCell>{n.service_name}</TableCell>
</TableCell>
</TableRow>
)};


And my result is :
Image


More From » reactjs

 Answers
5

Building on @st4rl00rd's comment, I was able to tie the buttons using :



const editIcon = (
<IconButton onClick={this.editItem}>
<EditIcon color=primary />
</IconButton>
);


and binding them in the constructor. I was able to get the selected row data by doing :



       <TableBody>
{this.state.serviceData.map(n => {
return (
<TableRow key={n.id} onClick={this.getData.bind(this,n)}>

[#53929] Tuesday, July 17, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaceyr

Total Points: 510
Total Questions: 97
Total Answers: 116

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
kaceyr questions
;