Skip to content

Commit

Permalink
fix #704
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Sep 18, 2016
1 parent 62ce772 commit 41e3723
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,30 @@ class BootstrapTable extends Component {

isSelectAll() {
if (this.store.isEmpty()) return false;

const unselectable = this.props.selectRow.unselectable;
const defaultSelectRowKeys = this.store.getSelectedRowKeys();
const allRowKeys = this.store.getAllRowkey();

if (defaultSelectRowKeys.length === 0) return false;
let match = 0;
let noFound = 0;
let unSelectableCnt = 0;
defaultSelectRowKeys.forEach(selected => {
if (allRowKeys.indexOf(selected) !== -1) match++;
else noFound++;
if (unselectable &&
unselectable.indexOf(selected) !== -1) unSelectableCnt++;
});

if (noFound === defaultSelectRowKeys.length) return false;
return (match === allRowKeys.length) ? true : 'indeterminate';
if (match === allRowKeys.length) {
return true;
} else {
if (unselectable && match <= unSelectableCnt &&
unSelectableCnt === unselectable.length) return false;
else return 'indeterminate';
}
// return (match === allRowKeys.length) ? true : 'indeterminate';
}

cleanSelected() {
Expand Down Expand Up @@ -418,25 +428,37 @@ class BootstrapTable extends Component {
handleSelectAllRow = e => {
const isSelected = e.currentTarget.checked;
const keyField = this.store.getKeyField();
const { selectRow: { onSelectAll, unselectable } } = this.props;
const { selectRow: { onSelectAll, unselectable, selected } } = this.props;
let selectedRowKeys = [];
let result = true;
let rows = this.store.get();
let rows = isSelected ?
this.store.get() :
this.store.getRowByKey(this.state.selectedRowKeys);

if (isSelected && unselectable && unselectable.length > 0) {
rows = rows.filter(r => unselectable.indexOf(r[keyField]) === -1);
if (unselectable && unselectable.length > 0) {
if (isSelected) {
rows = rows.filter(r => {
return unselectable.indexOf(r[keyField]) === -1 ||
(selected && selected.indexOf(r[keyField]) !== -1);
});
} else {
rows = rows.filter(r => unselectable.indexOf(r[keyField]) === -1);
}
}

if (onSelectAll) {
result = this.props.selectRow.onSelectAll(isSelected,
isSelected ? rows : this.store.getRowByKey(this.state.selectedRowKeys));
result = this.props.selectRow.onSelectAll(isSelected, rows);
}

if (typeof result == 'undefined' || result !== false) {
if (isSelected) {
selectedRowKeys = Array.isArray(result) ?
result :
rows.map(r => r[keyField]);
} else {
if (unselectable && selected) {
selectedRowKeys = selected.filter(r => unselectable.indexOf(r) > -1 );
}
}

this.store.setSelectedRowKey(selectedRowKeys);
Expand Down

0 comments on commit 41e3723

Please sign in to comment.