File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import DefaultSelectTable from './default-select-table';
7
7
import SelectBgColorTable from './select-bgcolor-table' ;
8
8
import SelectHookTable from './select-hook-table' ;
9
9
import HideSelectionColumnTable from './hide-selection-col-table' ;
10
+ import SelectValidationTable from './select-validation-table' ;
10
11
import RowClickTable from './row-click-table' ;
11
12
import OnlySelectedTable from './only-show-selected-table' ;
12
13
import ExternallyManagedSelection from './externally-managed-selection' ;
@@ -78,6 +79,16 @@ class Demo extends React.Component {
78
79
</ div >
79
80
</ div >
80
81
</ div >
82
+ < div className = 'col-md-offset-1 col-md-8' >
83
+ < div className = 'panel panel-default' >
84
+ < div className = 'panel-heading' > Select Validation Example</ div >
85
+ < div className = 'panel-body' >
86
+ < h5 > Source in /examples/js/selection/row-click-table.js</ h5 >
87
+ < h5 > Only able to select the rows which key is less 3.</ h5 >
88
+ < SelectValidationTable />
89
+ </ div >
90
+ </ div >
91
+ </ div >
81
92
< div className = 'col-md-offset-1 col-md-8' >
82
93
< div className = 'panel panel-default' >
83
94
< div className = 'panel-heading' > Row Click Example</ div >
Original file line number Diff line number Diff line change
1
+ /* eslint max-len: 0 */
2
+ /* eslint no-alert: 0 */
3
+ /* eslint guard-for-in: 0 */
4
+ /* eslint no-console: 0 */
5
+ /* eslint no-unused-vars: 0 */
6
+ import React from 'react' ;
7
+ import { BootstrapTable , TableHeaderColumn } from 'react-bootstrap-table' ;
8
+
9
+
10
+ const products = [ ] ;
11
+
12
+ function addProducts ( quantity ) {
13
+ const startId = products . length ;
14
+ for ( let i = 0 ; i < quantity ; i ++ ) {
15
+ const id = startId + i ;
16
+ products . push ( {
17
+ id : id ,
18
+ name : 'Item name ' + id ,
19
+ price : 2100 + i
20
+ } ) ;
21
+ }
22
+ }
23
+
24
+ addProducts ( 5 ) ;
25
+
26
+ function onRowSelect ( row , isSelected , e ) {
27
+ if ( isSelected && row . id >= 3 ) {
28
+ alert ( 'The selection only work on key which less than 3' ) ;
29
+ return false ;
30
+ }
31
+ }
32
+
33
+ function onSelectAll ( isSelected , rows ) {
34
+ if ( isSelected ) {
35
+ alert ( 'The selection only work on key which less than 3' ) ;
36
+ return products . map ( p => p . id ) . filter ( id => id < 3 ) ;
37
+ }
38
+ }
39
+
40
+ const selectRowProp = {
41
+ mode : 'checkbox' ,
42
+ clickToSelect : true ,
43
+ onSelect : onRowSelect ,
44
+ onSelectAll : onSelectAll
45
+ } ;
46
+
47
+ export default class SelectValidationTable extends React . Component {
48
+ render ( ) {
49
+ return (
50
+ < BootstrapTable data = { products } selectRow = { selectRowProp } >
51
+ < TableHeaderColumn dataField = 'id' isKey = { true } > Product ID</ TableHeaderColumn >
52
+ < TableHeaderColumn dataField = 'name' > Product Name</ TableHeaderColumn >
53
+ < TableHeaderColumn dataField = 'price' > Product Price</ TableHeaderColumn >
54
+ </ BootstrapTable >
55
+ ) ;
56
+ }
57
+ }
You can’t perform that action at this time.
0 commit comments