Skip to content

Commit b611797

Browse files
committed
fix #1310
1 parent 24e5b66 commit b611797

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

examples/js/selection/externally-managed-selection.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,43 @@ addProducts(100);
2222
export default class ExternallyManagedSelection extends React.Component {
2323
constructor(props) {
2424
super(props);
25+
this.onSelectAll = this.onSelectAll.bind(this);
26+
this.onRowSelect = this.onRowSelect.bind(this);
2527
this.state = {
2628
selected: [],
2729
currPage: 1
2830
};
2931
}
3032

33+
onRowSelect({ id }, isSelected) {
34+
if (isSelected && this.state.selected.length !== 2) {
35+
this.setState({
36+
selected: [ ...this.state.selected, id ].sort(),
37+
currPage: this.refs.table.state.currPage
38+
});
39+
} else {
40+
this.setState({ selected: this.state.selected.filter(it => it !== id) });
41+
}
42+
return false;
43+
}
44+
45+
onSelectAll(isSelected) {
46+
if (!isSelected) {
47+
this.setState({ selected: [] });
48+
}
49+
return false;
50+
}
51+
3152
render() {
3253
const {
3354
currPage
3455
} = this.state;
35-
const onRowSelect = ({ id }, isSelected) => {
36-
if (isSelected && this.state.selected.length !== 2) {
37-
this.setState({
38-
selected: [ ...this.state.selected, id ].sort(),
39-
currPage: this.refs.table.state.currPage
40-
});
41-
} else {
42-
this.setState({ selected: this.state.selected.filter(it => it !== id) });
43-
}
44-
return false;
45-
};
4656

4757
const selectRowProp = {
4858
mode: 'checkbox',
4959
clickToSelect: true,
50-
onSelect: onRowSelect,
60+
onSelect: this.onRowSelect,
61+
onSelectAll: this.onSelectAll,
5162
selected: this.state.selected
5263
};
5364

0 commit comments

Comments
 (0)