admin管理员组文章数量:1328571
i'm having a problem and need some help. We are using ant-design library in our project. /ponents/table The ponent we should use is a table. When i click on a row i must trigger an action. However i must check only one row not many so when i click on a row the checkbox in the previous row should be deselect.
My code is here:
onSelectChange = selectedRowKeys => {
if (selectedRowKeys.length > 1) {
const lastSelectedRowIndex = [...selectedRowKeys].pop();
this.setState({ selectedRowKeys: lastSelectedRowIndex });
}
this.setState({ selectedRowKeys });
console.log('selectedRowKeys changed: ', selectedRowKeys);
};
render() {
const { selectedRowKeys } = this.state;
const rowSelection = {
selectedRowKeys,
onChange: this.onSelectChange,
};
return (
<React.Fragment>
<div style={{ marginBottom: 16 }} />
<Table
rowSelection={rowSelection}
columns={columnEvaluation}
dataSource={result}
/>
</React.Fragment>
);
}
The selectedRow array is having the latest value BUT But the checkbox is NOT checked. Any ideas?
i'm having a problem and need some help. We are using ant-design library in our project. https://ant.design/ponents/table The ponent we should use is a table. When i click on a row i must trigger an action. However i must check only one row not many so when i click on a row the checkbox in the previous row should be deselect.
My code is here:
onSelectChange = selectedRowKeys => {
if (selectedRowKeys.length > 1) {
const lastSelectedRowIndex = [...selectedRowKeys].pop();
this.setState({ selectedRowKeys: lastSelectedRowIndex });
}
this.setState({ selectedRowKeys });
console.log('selectedRowKeys changed: ', selectedRowKeys);
};
render() {
const { selectedRowKeys } = this.state;
const rowSelection = {
selectedRowKeys,
onChange: this.onSelectChange,
};
return (
<React.Fragment>
<div style={{ marginBottom: 16 }} />
<Table
rowSelection={rowSelection}
columns={columnEvaluation}
dataSource={result}
/>
</React.Fragment>
);
}
The selectedRow array is having the latest value BUT But the checkbox is NOT checked. Any ideas?
Share Improve this question asked May 25, 2019 at 9:37 RamAlxRamAlx 7,34424 gold badges64 silver badges110 bronze badges1 Answer
Reset to default 4Checkboxes are used to let a user select one or more options of a limited number of choices, and Radio buttons let a user select only one of a limited number of choices.
pass a type to your table's rowSelection
prop, default is checkbox.
const rowSelection = {
selectedRowKeys,
onChange: this.onSelectChange,
type: 'radio'
};
本文标签: javascriptSelect just one row in antdesign table componentStack Overflow
版权声明:本文标题:javascript - Select just one row in ant-design table component - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742259310a2442213.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论