fix: `rowKey` should work with Radio #697

pull/707/head
Benjy Cui 9 years ago
parent 3ec39dcb62
commit d1c73231a1

@ -23,17 +23,17 @@ const columns = [{
dataIndex: 'address' dataIndex: 'address'
}]; }];
const data = [{ const data = [{
key: '1', id: '1',
name: '胡彦斌', name: '胡彦斌',
age: 32, age: 32,
address: '西湖区湖底公园1号' address: '西湖区湖底公园1号'
}, { }, {
key: '2', id: '2',
name: '胡彦祖', name: '胡彦祖',
age: 42, age: 42,
address: '西湖区湖底公园1号' address: '西湖区湖底公园1号'
}, { }, {
key: '3', id: '3',
name: '李大嘴', name: '李大嘴',
age: 32, age: 32,
address: '西湖区湖底公园1号' 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')); , document.getElementById('components-table-demo-row-selection-radio-props'));
```` ````

@ -205,7 +205,7 @@ let AntTable = React.createClass({
selectedRowKeys = [key]; selectedRowKeys = [key];
this.setState({ this.setState({
selectedRowKeys: selectedRowKeys, selectedRowKeys: selectedRowKeys,
radioIndex: record.key, radioIndex: key,
selectionDirty: true selectionDirty: true
}); });
if (this.props.rowSelection.onSelect) { if (this.props.rowSelection.onSelect) {
@ -271,13 +271,13 @@ let AntTable = React.createClass({
} }
let checked; let checked;
if (this.state.selectionDirty) { if (this.state.selectionDirty) {
checked = this.state.radioIndex === record.key; checked = this.state.radioIndex === rowIndex;
} else { } else {
checked = (this.state.radioIndex === record.key || checked = (this.state.radioIndex === rowIndex ||
this.getDefaultSelection().indexOf(rowIndex) >= 0); this.getDefaultSelection().indexOf(rowIndex) >= 0);
} }
return <Radio disabled={props.disabled} onChange={this.handleRadioSelect.bind(this, record, rowIndex)} 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) { renderSelectionCheckBox(value, record, index) {

Loading…
Cancel
Save