mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 13:09:40 +08:00
Merge pull request #707 from ant-design/fix-table
fix: `rowKey` should work with Radio #697
This commit is contained in:
commit
fd96b1e7f4
@ -23,17 +23,17 @@ const columns = [{
|
||||
dataIndex: 'address'
|
||||
}];
|
||||
const data = [{
|
||||
key: '1',
|
||||
id: '1',
|
||||
name: '胡彦斌',
|
||||
age: 32,
|
||||
address: '西湖区湖底公园1号'
|
||||
}, {
|
||||
key: '2',
|
||||
id: '2',
|
||||
name: '胡彦祖',
|
||||
age: 42,
|
||||
address: '西湖区湖底公园1号'
|
||||
}, {
|
||||
key: '3',
|
||||
id: '3',
|
||||
name: '李大嘴',
|
||||
age: 32,
|
||||
address: '西湖区湖底公园1号'
|
||||
@ -56,6 +56,10 @@ const rowSelection = {
|
||||
}
|
||||
};
|
||||
|
||||
ReactDOM.render(<Table rowSelection={rowSelection} columns={columns} dataSource={data} />
|
||||
function rowKey(record) {
|
||||
return record.id;
|
||||
}
|
||||
|
||||
ReactDOM.render(<Table rowSelection={rowSelection} rowKey={rowKey} columns={columns} dataSource={data} />
|
||||
, document.getElementById('components-table-demo-row-selection-radio-props'));
|
||||
````
|
||||
|
@ -205,7 +205,7 @@ let AntTable = React.createClass({
|
||||
selectedRowKeys = [key];
|
||||
this.setState({
|
||||
selectedRowKeys: selectedRowKeys,
|
||||
radioIndex: record.key,
|
||||
radioIndex: key,
|
||||
selectionDirty: true
|
||||
});
|
||||
if (this.props.rowSelection.onSelect) {
|
||||
@ -271,13 +271,13 @@ let AntTable = React.createClass({
|
||||
}
|
||||
let checked;
|
||||
if (this.state.selectionDirty) {
|
||||
checked = this.state.radioIndex === record.key;
|
||||
checked = this.state.radioIndex === rowIndex;
|
||||
} else {
|
||||
checked = (this.state.radioIndex === record.key ||
|
||||
checked = (this.state.radioIndex === rowIndex ||
|
||||
this.getDefaultSelection().indexOf(rowIndex) >= 0);
|
||||
}
|
||||
return <Radio disabled={props.disabled} onChange={this.handleRadioSelect.bind(this, record, rowIndex)}
|
||||
value={record.key} checked={checked}/>;
|
||||
value={rowIndex} checked={checked}/>;
|
||||
},
|
||||
|
||||
renderSelectionCheckBox(value, record, index) {
|
||||
|
Loading…
Reference in New Issue
Block a user