Browse Source

Fix disabled checkbox logic in table rowSelection

pull/803/head
afc163 9 years ago
parent
commit
27908bf42e
  1. 45
      components/table/index.jsx

45
components/table/index.jsx

@ -152,11 +152,8 @@ let AntTable = React.createClass({
},
handleSelect(record, rowIndex, e) {
let checked = e.target.checked;
let defaultSelection = [];
if (!this.state.selectionDirty) {
defaultSelection = this.getDefaultSelection();
}
const checked = e.target.checked;
const defaultSelection = this.state.selectionDirty ? [] : this.getDefaultSelection();
let selectedRowKeys = this.state.selectedRowKeys.concat(defaultSelection);
let key = this.getRecordKey(record, rowIndex);
if (checked) {
@ -180,11 +177,8 @@ let AntTable = React.createClass({
},
handleRadioSelect: function (record, rowIndex, e) {
let checked = e.target.checked;
let defaultSelection = [];
if (!this.state.selectionDirty) {
defaultSelection = this.getDefaultSelection();
}
const checked = e.target.checked;
const defaultSelection = this.state.selectionDirty ? [] : this.getDefaultSelection();
let selectedRowKeys = this.state.selectedRowKeys.concat(defaultSelection);
let key = this.getRecordKey(record, rowIndex);
selectedRowKeys = [key];
@ -203,18 +197,29 @@ let AntTable = React.createClass({
},
handleSelectAllRow(e) {
let checked = e.target.checked;
let data = this.getCurrentPageData();
let selectedRowKeys = checked ? data.filter((item) => {
if (this.props.rowSelection.getCheckboxProps) {
return !this.props.rowSelection.getCheckboxProps(item).disabled;
const checked = e.target.checked;
const data = this.getCurrentPageData();
const defaultSelection = this.state.selectionDirty ? [] : this.getDefaultSelection();
const selectedRowKeys = this.state.selectedRowKeys.concat(defaultSelection);
const changableRowKeys = data.filter(item =>
!this.props.rowSelection.getCheckboxProps ||
!this.props.rowSelection.getCheckboxProps(item).disabled
).map((item, i) => this.getRecordKey(item, i));
if (checked) {
changableRowKeys.forEach(key => {
if (selectedRowKeys.indexOf(key) < 0) {
selectedRowKeys.push(key);
}
});
} else {
changableRowKeys.forEach(key => {
if (selectedRowKeys.indexOf(key) >= 0) {
selectedRowKeys.splice(selectedRowKeys.indexOf(key), 1);
}
});
}
return true;
}).map((item, i) => {
return this.getRecordKey(item, i);
}) : [];
this.setState({
selectedRowKeys: selectedRowKeys,
selectedRowKeys,
selectionDirty: true
});
if (this.props.rowSelection.onSelectAll) {

Loading…
Cancel
Save