1
1
/* eslint max-len: 0 */
2
+ /* eslint no-alert: 0 */
3
+ /* eslint guard-for-in: 0 */
4
+ /* eslint no-console: 0 */
2
5
import React from 'react' ;
3
6
import { BootstrapTable , TableHeaderColumn } from 'react-bootstrap-table' ;
4
7
8
+
5
9
const products = [ ] ;
6
10
7
11
function addProducts ( quantity ) {
@@ -16,73 +20,29 @@ function addProducts(quantity) {
16
20
}
17
21
}
18
22
19
- addProducts ( 100 ) ;
23
+ addProducts ( 50 ) ;
20
24
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 {
36
26
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 ) => {
48
28
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 ) ;
54
30
}
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 } ) ;
67
31
}
68
32
69
33
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
+ } ;
76
39
77
40
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 >
81
42
< TableHeaderColumn dataField = 'id' isKey = { true } > Product ID</ TableHeaderColumn >
82
- < TableHeaderColumn dataField = 'name' filter = { filterOptions } > Product Name</ TableHeaderColumn >
43
+ < TableHeaderColumn dataField = 'name' > Product Name</ TableHeaderColumn >
83
44
< TableHeaderColumn dataField = 'price' > Product Price</ TableHeaderColumn >
84
- </ BootstrapTable >
85
- </ div >
86
- ) ;
45
+ </ BootstrapTable >
46
+ ) ;
87
47
}
88
48
}
0 commit comments