Browse Source

Merge pull request #707 from ant-design/fix-table

fix: `rowKey` should work with Radio #697
pull/732/head
afc163 9 years ago
parent
commit
fd96b1e7f4
  1. 12
      components/table/demo/row-selection-radio-props.md
  2. 8
      components/table/index.jsx

12
components/table/demo/row-selection-radio-props.md

@ -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'));
````

8
components/table/index.jsx

@ -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…
Cancel
Save