Add rowSelection onChange, #786

This commit is contained in:
afc163 2016-01-01 20:08:30 +08:00
parent 27908bf42e
commit 28b75ce8da
4 changed files with 24 additions and 6 deletions

View File

@ -47,12 +47,15 @@ const rowSelection = {
disabled: record.name === '胡彦祖' // 配置无法勾选的列 disabled: record.name === '胡彦祖' // 配置无法勾选的列
}; };
}, },
onChange(selectedRowKeys) {
console.log('selectedRowKeys changed: ' + selectedRowKeys);
},
onSelect: function(record, selected, selectedRows) { onSelect: function(record, selected, selectedRows) {
console.log(record, selected, selectedRows); console.log(record, selected, selectedRows);
}, },
onSelectAll: function(selected, selectedRows) { onSelectAll: function(selected, selectedRows) {
console.log(selected, selectedRows); console.log(selected, selectedRows);
} },
}; };
ReactDOM.render(<Table rowSelection={rowSelection} columns={columns} dataSource={data} /> ReactDOM.render(<Table rowSelection={rowSelection} columns={columns} dataSource={data} />

View File

@ -51,9 +51,6 @@ const rowSelection = {
onSelect: function(record, selected, selectedRows) { onSelect: function(record, selected, selectedRows) {
console.log(record, selected, selectedRows); console.log(record, selected, selectedRows);
}, },
onSelectAll: function(selected, selectedRows) {
console.log(selected, selectedRows);
}
}; };
function rowKey(record) { function rowKey(record) {

View File

@ -41,6 +41,9 @@ const data = [{
// 通过 rowSelection 对象表明需要行选择 // 通过 rowSelection 对象表明需要行选择
const rowSelection = { const rowSelection = {
onChange(selectedRowKeys) {
console.log('selectedRowKeys changed: ' + selectedRowKeys);
},
onSelect: function(record, selected, selectedRows) { onSelect: function(record, selected, selectedRows) {
console.log(record, selected, selectedRows); console.log(record, selected, selectedRows);
}, },

View File

@ -88,6 +88,9 @@ let AntTable = React.createClass({
selectionDirty: false, selectionDirty: false,
selectedRowKeys: [], selectedRowKeys: [],
}); });
if (this.props.rowSelection && this.props.rowSelection.onChange) {
this.props.rowSelection.onChange([]);
}
} }
}, },
@ -164,7 +167,7 @@ let AntTable = React.createClass({
}); });
} }
this.setState({ this.setState({
selectedRowKeys: selectedRowKeys, selectedRowKeys,
selectionDirty: true selectionDirty: true
}); });
if (this.props.rowSelection.onSelect) { if (this.props.rowSelection.onSelect) {
@ -174,6 +177,9 @@ let AntTable = React.createClass({
}); });
this.props.rowSelection.onSelect(record, checked, selectedRows); this.props.rowSelection.onSelect(record, checked, selectedRows);
} }
if (this.props.rowSelection.onChange) {
this.props.rowSelection.onChange(selectedRowKeys);
}
}, },
handleRadioSelect: function (record, rowIndex, e) { handleRadioSelect: function (record, rowIndex, e) {
@ -183,7 +189,7 @@ let AntTable = React.createClass({
let key = this.getRecordKey(record, rowIndex); let key = this.getRecordKey(record, rowIndex);
selectedRowKeys = [key]; selectedRowKeys = [key];
this.setState({ this.setState({
selectedRowKeys: selectedRowKeys, selectedRowKeys,
radioIndex: key, radioIndex: key,
selectionDirty: true selectionDirty: true
}); });
@ -194,6 +200,9 @@ let AntTable = React.createClass({
}); });
this.props.rowSelection.onSelect(record, checked, selectedRows); this.props.rowSelection.onSelect(record, checked, selectedRows);
} }
if (this.props.rowSelection.onChange) {
this.props.rowSelection.onChange(selectedRowKeys);
}
}, },
handleSelectAllRow(e) { handleSelectAllRow(e) {
@ -228,6 +237,9 @@ let AntTable = React.createClass({
}); });
this.props.rowSelection.onSelectAll(checked, selectedRows); this.props.rowSelection.onSelectAll(checked, selectedRows);
} }
if (this.props.rowSelection.onChange) {
this.props.rowSelection.onChange(selectedRowKeys);
}
}, },
handlePageChange(current) { handlePageChange(current) {
@ -244,6 +256,9 @@ let AntTable = React.createClass({
pagination pagination
}; };
this.setState(newState); this.setState(newState);
if (this.props.rowSelection && this.props.rowSelection.onChange) {
this.props.rowSelection.onChange([]);
}
this.props.onChange.apply(this, this.prepareParamsArguments(objectAssign({}, this.state, newState))); this.props.onChange.apply(this, this.prepareParamsArguments(objectAssign({}, this.state, newState)));
}, },