提交 9f1fbb9e 编写于 作者: A afc163

selectRows

上级 37779330
...@@ -37,11 +37,11 @@ var data = [{ ...@@ -37,11 +37,11 @@ var data = [{
// 通过 rowSelection 对象表明需要行选择 // 通过 rowSelection 对象表明需要行选择
var rowSelection = { var rowSelection = {
onSelect: function(record, selected) { onSelect: function(record, selected, selectedRows) {
console.log(record, selected); console.log(record, selected, selectedRows);
}, },
onSelectAll: function(selected) { onSelectAll: function(selected, selectedRows) {
console.log(selected); console.log(selected, selectedRows);
} }
}; };
......
...@@ -104,7 +104,6 @@ let AntTable = React.createClass({ ...@@ -104,7 +104,6 @@ let AntTable = React.createClass({
this.fetch(); this.fetch();
}, },
handleSelect(rowIndex, checked) { handleSelect(rowIndex, checked) {
let selectedRow = this.state.data[rowIndex - 1];
if (checked) { if (checked) {
this.state.selectedRowKeys.push(rowIndex); this.state.selectedRowKeys.push(rowIndex);
} else { } else {
...@@ -116,17 +115,25 @@ let AntTable = React.createClass({ ...@@ -116,17 +115,25 @@ let AntTable = React.createClass({
selectedRowKeys: this.state.selectedRowKeys selectedRowKeys: this.state.selectedRowKeys
}); });
if (this.props.rowSelection.onSelect) { if (this.props.rowSelection.onSelect) {
this.props.rowSelection.onSelect(selectedRow, checked); let currentRow = this.state.data[rowIndex - 1];
let selectedRows = this.state.data.filter((row, i) => {
return this.state.selectedRowKeys.indexOf(i + 1) >= 0;
});
this.props.rowSelection.onSelect(currentRow, checked, selectedRows);
} }
}, },
handleSelectAllRow(checked) { handleSelectAllRow(checked) {
this.setState({ var selectedRowKeys = checked ? this.state.data.map(function(item, i) {
selectedRowKeys: checked ? this.state.data.map(function(item, i) {
return i + 1; return i + 1;
}) : [] }) : [];
this.setState({
selectedRowKeys: selectedRowKeys
}); });
if (this.props.rowSelection.onSelectAll) { if (this.props.rowSelection.onSelectAll) {
this.props.rowSelection.onSelectAll(checked); let selectedRows = this.state.data.filter((row, i) => {
return selectedRowKeys.indexOf(i + 1) >= 0;
});
this.props.rowSelection.onSelectAll(checked, selectedRows);
} }
}, },
handlePageChange: function(current) { handlePageChange: function(current) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册