File tree 3 files changed +124
-0
lines changed
3 files changed +124
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import RemoteStoreInsertRow from './remote-store-insert-row';
7
7
import RemoteStoreDeleteRow from './remote-store-delete-row' ;
8
8
import RemoteStoreCellEdit from './remote-store-cell-edit' ;
9
9
import RemoteStoreExportCSV from './remote-store-export-csv' ;
10
+ import RemoteStoreAlternative from './remote-store-alternative' ;
10
11
import RemoteStoreAll from './remote-store-all' ;
11
12
12
13
class Demo extends React . Component {
@@ -93,6 +94,17 @@ class Demo extends React.Component {
93
94
</ div >
94
95
</ div >
95
96
</ div >
97
+ < div className = 'col-md-offset-1 col-md-8' >
98
+ < div className = 'panel panel-default' >
99
+ < div className = 'panel-heading' > Alternative Configure Remote Example</ div >
100
+ < div className = 'panel-body' >
101
+ < h5 > Source in /examples/js/remote/remote-store-alternative.js and
102
+ /examples/js/remote/remote-alternative.js</ h5 >
103
+ < span > Remote mode also allow you to choose which functionality should be handle by remote.</ span >
104
+ < RemoteStoreAlternative />
105
+ </ div >
106
+ </ div >
107
+ </ div >
96
108
< div className = 'col-md-offset-1 col-md-8' >
97
109
< div className = 'panel panel-default' >
98
110
< div className = 'panel-heading' > Remote All Features Together Example</ div >
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { BootstrapTable , TableHeaderColumn } from 'react-bootstrap-table' ;
3
+
4
+ export default class RemoteAlternative extends React . Component {
5
+ constructor ( props ) {
6
+ super ( props ) ;
7
+ }
8
+
9
+ remote ( remoteObj ) {
10
+ // Only cell editing, insert and delete row will be handled by remote store
11
+ remoteObj . cellEdit = true ;
12
+ remoteObj . insertRow = true ;
13
+ remoteObj . dropRow = true ;
14
+ return remoteObj ;
15
+ }
16
+
17
+ render ( ) {
18
+ const cellEditProp = {
19
+ mode : 'click'
20
+ } ;
21
+ const selectRow = {
22
+ mode : 'checkbox' ,
23
+ cliclToSelct : true
24
+ } ;
25
+ return (
26
+ < BootstrapTable data = { this . props . data }
27
+ selectRow = { selectRow }
28
+ remote = { this . remote }
29
+ insertRow deleteRow search pagination
30
+ cellEdit = { cellEditProp }
31
+ options = { {
32
+ onCellEdit : this . props . onCellEdit ,
33
+ onDeleteRow : this . props . onDeleteRow ,
34
+ onAddRow : this . props . onAddRow
35
+ } } >
36
+ < TableHeaderColumn dataField = 'id' isKey = { true } > Product ID</ TableHeaderColumn >
37
+ < TableHeaderColumn dataField = 'name' > Product Name</ TableHeaderColumn >
38
+ < TableHeaderColumn dataField = 'price' dataSort > Product Price</ TableHeaderColumn >
39
+ </ BootstrapTable >
40
+ ) ;
41
+ }
42
+ }
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import RemoteAlternative from './remote-alternative' ;
3
+
4
+ function getProducts ( ) {
5
+ const products = [ ] ;
6
+ const startId = products . length ;
7
+ for ( let i = 0 ; i < 12 ; i ++ ) {
8
+ const id = startId + i ;
9
+ products . push ( {
10
+ id : id ,
11
+ name : 'Item name ' + id ,
12
+ price : Math . floor ( ( Math . random ( ) * 2000 ) + 1 )
13
+ } ) ;
14
+ }
15
+ return products ;
16
+ }
17
+
18
+ export default class RemoteStoreAlternative extends React . Component {
19
+ constructor ( props ) {
20
+ super ( props ) ;
21
+ this . products = getProducts ( ) ;
22
+ this . state = {
23
+ data : this . products
24
+ } ;
25
+ }
26
+
27
+ onCellEdit = ( row , fieldName , value ) => {
28
+ const { data } = this . state ;
29
+ let rowIdx ;
30
+ const targetRow = data . find ( ( prod , i ) => {
31
+ if ( prod . id === row . id ) {
32
+ rowIdx = i ;
33
+ return true ;
34
+ }
35
+ return false ;
36
+ } ) ;
37
+ if ( targetRow ) {
38
+ targetRow [ fieldName ] = value ;
39
+ data [ rowIdx ] = targetRow ;
40
+ this . setState ( { data } ) ;
41
+ }
42
+ }
43
+
44
+ onAddRow = ( row ) => {
45
+ this . products . push ( row ) ;
46
+ this . setState ( {
47
+ data : this . products
48
+ } ) ;
49
+ }
50
+
51
+ onDeleteRow = ( row ) => {
52
+ this . products = this . products . filter ( ( product ) => {
53
+ return product . id !== row [ 0 ] ;
54
+ } ) ;
55
+
56
+ this . setState ( {
57
+ data : this . products
58
+ } ) ;
59
+ }
60
+
61
+ render ( ) {
62
+ return (
63
+ < RemoteAlternative
64
+ onCellEdit = { this . onCellEdit }
65
+ onAddRow = { this . onAddRow }
66
+ onDeleteRow = { this . onDeleteRow }
67
+ { ...this . state } />
68
+ ) ;
69
+ }
70
+ }
You can’t perform that action at this time.
0 commit comments