admin管理员组文章数量:1356271
I'm using a Table ponent in the newest version of Material UI, and I'm not sure how I'm supposed to be acquiring data from a Table's row when it's selected.
The documentation mentions a prop for the Table ponent called onRowSelection
, but it only gives you a RowNumber for the row that was selected, nothing else.
How are you supposed to make any use of this at all? I don't understand how you're meant to grab say...the key prop that's set to the TableRow
using nothing but the RowNumber prop of that same TableRow
.
Code below shows how I'm rendering the table itself, and assigning the key:
handleSelect(id) {
console.log(id);
this.props.dispatch({ type: 'SET_SELECTED_USER', user: id });
}
renderUsers() {
if (this.props.users && this.props.currentUser) {
const currUser = this.props.currentUser.username;
const userList = this.props.users.map((user) => {
if (currUser !== user.username) {
return (
<TableRow key={user._id}>
<TableRowColumn>{user.username}</TableRowColumn>
<TableRowColumn>{user.roles[0]}</TableRowColumn>
</TableRow>
);
}
});
return userList;
}
}
I just don't understand how the RowNumber of the row being selected is supposed to help me whatsoever, when I need to access they key of the row instead.
Any assistance would be really appreciated! Thanks!
Docs for Table:
I'm using a Table ponent in the newest version of Material UI, and I'm not sure how I'm supposed to be acquiring data from a Table's row when it's selected.
The documentation mentions a prop for the Table ponent called onRowSelection
, but it only gives you a RowNumber for the row that was selected, nothing else.
How are you supposed to make any use of this at all? I don't understand how you're meant to grab say...the key prop that's set to the TableRow
using nothing but the RowNumber prop of that same TableRow
.
Code below shows how I'm rendering the table itself, and assigning the key:
handleSelect(id) {
console.log(id);
this.props.dispatch({ type: 'SET_SELECTED_USER', user: id });
}
renderUsers() {
if (this.props.users && this.props.currentUser) {
const currUser = this.props.currentUser.username;
const userList = this.props.users.map((user) => {
if (currUser !== user.username) {
return (
<TableRow key={user._id}>
<TableRowColumn>{user.username}</TableRowColumn>
<TableRowColumn>{user.roles[0]}</TableRowColumn>
</TableRow>
);
}
});
return userList;
}
}
I just don't understand how the RowNumber of the row being selected is supposed to help me whatsoever, when I need to access they key of the row instead.
Any assistance would be really appreciated! Thanks!
Docs for Table: http://www.material-ui./#/ponents/table
Share Improve this question asked May 18, 2016 at 16:46 MisutoWolfMisutoWolf 1,2431 gold badge20 silver badges33 bronze badges 4- Is the same question answered here? stackoverflow./questions/36656447/… – Marc Commented May 18, 2016 at 16:58
-
In a way, I guess...but my problem seems to be that, contrary to how that question is replied, the
key
prop isn't what's being used to identify the row being selected when usingonRowSelection
. Instead, some abritraryrowNumber
property is automatically generated byTable
and is used, which is not helpful at all, when I actually need it to be using thekey
prop as suggested by that question/answer. – MisutoWolf Commented May 18, 2016 at 17:16 - You can populate the key value with whatever you want. Look at the row creation .map in the example in that linked question/answer. You can even link to the full object. Does that help? – Larry Maccherone Commented May 18, 2016 at 17:22
-
I don't know. The problem isn't being able to stick whatever values I want in the key/value props for the rows as they're created. The problem is that when I go to trigger the selection of said rows, I don't understand how I'm supposed to access those props, when you're only able to pass one parameter (I guess?) into the function that gets called when triggering
onRowSelection
. Unless I'm wrong, and my code forhandleSelect
above could be something likefunction handleSelect(row, key) ...
– MisutoWolf Commented May 18, 2016 at 17:31
1 Answer
Reset to default 6You could use the row number as an index in your users array (this.props.users):
handleSelect(userIndex) {
const currUser = this.props.currentUser.username;
const users = this.props.users.filter(user => user.username !== currUser)
this.props.dispatch({ type: 'SET_SELECTED_USER', user: users[userIndex].id });
}
本文标签: javascriptGetting data from TableRow component in Material UIStack Overflow
版权声明:本文标题:javascript - Getting data from TableRow component in Material UI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744043648a2581125.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论