Skip to content

Commit ff31b0d

Browse files
committed
fix for matching requirement from #537
1 parent bd9b06c commit ff31b0d

File tree

2 files changed

+18
-58
lines changed

2 files changed

+18
-58
lines changed

examples/js/selection/all-select.js

+17-57
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/* eslint max-len: 0 */
2+
/* eslint no-alert: 0 */
3+
/* eslint guard-for-in: 0 */
4+
/* eslint no-console: 0 */
25
import React from 'react';
36
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
47

8+
59
const products = [];
610

711
function addProducts(quantity) {
@@ -16,73 +20,29 @@ function addProducts(quantity) {
1620
}
1721
}
1822

19-
addProducts(100);
23+
addProducts(50);
2024

21-
const options = {
22-
sizePerPageList: [ 5, 10, 15, 20 ],
23-
sizePerPage: 10,
24-
sortName: 'id',
25-
sortOrder: 'desc'
26-
};
27-
const selectRowProp = {
28-
mode: 'checkbox',
29-
clickToSelect: true,
30-
bgColor: 'rgb(238, 193, 213)'
31-
};
32-
const filterOptions = {
33-
type: 'TextFilter',
34-
placeholder: 'Product Name'
35-
};
25+
export default class SelectAllOnCurrPage extends React.Component {
3626

37-
export default class SelectAll extends React.Component {
38-
constructor(props) {
39-
super(props);
40-
this.state = {
41-
selected: [],
42-
filteredProducts: products
43-
};
44-
}
45-
46-
onSelect(row, isSelected) {
47-
const selectedProducts = this.state.selected;
27+
onSelectAll = (isSelected) => {
4828
if (isSelected) {
49-
selectedProducts.push(row.id);
50-
} else {
51-
const index = selectedProducts
52-
.indexOf(row.universalId);
53-
selectedProducts.splice(index, 1);
29+
return this.refs.table.state.data.map(row => row.id);
5430
}
55-
this.setState({ selected: selectedProducts });
56-
}
57-
58-
onSelectAll(isSelected) {
59-
const items = isSelected
60-
? this.state.filteredProducts.map(product => product.id)
61-
: [];
62-
this.setState({ selected: items });
63-
}
64-
65-
afterColumnFilter(filterConds, result) {
66-
this.setState({ filteredProducts: result });
6731
}
6832

6933
render() {
70-
Object.assign(selectRowProp, {
71-
selected: this.state.selected,
72-
onSelect: this.onSelect.bind(this),
73-
onSelectAll: this.onSelectAll.bind(this) });
74-
Object.assign(options, {
75-
afterColumnFilter: this.afterColumnFilter.bind(this) });
34+
const selectRowProp = {
35+
mode: 'checkbox',
36+
clickToSelect: true,
37+
onSelectAll: this.onSelectAll
38+
};
7639

7740
return (
78-
<div>
79-
<div>Product selected: { this.state.selected.length }</div>
80-
<BootstrapTable ref='table' selectRow={ selectRowProp } data={ products } pagination={ true } options={ options }>
41+
<BootstrapTable ref='table' data={ products } selectRow={ selectRowProp } pagination>
8142
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
82-
<TableHeaderColumn dataField='name' filter={ filterOptions }>Product Name</TableHeaderColumn>
43+
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
8344
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
84-
</BootstrapTable>
85-
</div>
86-
);
45+
</BootstrapTable>
46+
);
8747
}
8848
}

examples/js/selection/demo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Demo extends React.Component {
129129
</div>
130130
<div className='col-md-offset-1 col-md-8'>
131131
<div className='panel panel-default'>
132-
<div className='panel-heading'>Select all (with pagination and filter)</div>
132+
<div className='panel-heading'>Select All Which Only Active on Current Page</div>
133133
<div className='panel-body'>
134134
<h5>Source in all-select.js</h5>
135135
<SelectAll />

0 commit comments

Comments
 (0)