File tree Expand file tree Collapse file tree 2 files changed +103
-0
lines changed
packages/react-bootstrap-table2-example Expand file tree Collapse file tree 2 files changed +103
-0
lines changed Original file line number Diff line number Diff line change 1+ /* eslint no-unused-vars: 0 */
2+ import React from 'react' ;
3+ import BootstrapTable from 'react-bootstrap-table-next' ;
4+ import cellEditFactory from 'react-bootstrap-table2-editor' ;
5+ import Code from 'components/common/code-block' ;
6+ import { productsGenerator } from 'utils/common' ;
7+
8+ const products = productsGenerator ( ) ;
9+
10+ const columns = [ {
11+ dataField : 'id' ,
12+ text : 'Product ID'
13+ } , {
14+ dataField : 'name' ,
15+ text : 'Product Name'
16+ } , {
17+ dataField : 'price' ,
18+ text : 'Product Price' ,
19+ validator : ( newValue , row , column , done ) => {
20+ setTimeout ( ( ) => {
21+ if ( isNaN ( newValue ) ) {
22+ return done ( {
23+ valid : false ,
24+ message : 'Price should be numeric'
25+ } ) ;
26+ }
27+ if ( newValue < 2000 ) {
28+ return done ( {
29+ valid : false ,
30+ message : 'Price should bigger than 2000'
31+ } ) ;
32+ }
33+ return done ( ) ;
34+ } , 2000 ) ;
35+ return {
36+ async : true
37+ } ;
38+ }
39+ } ] ;
40+
41+ const sourceCode = `\
42+ import BootstrapTable from 'react-bootstrap-table-next';
43+ import cellEditFactory from 'react-bootstrap-table2-editor';
44+
45+ const columns = [{
46+ dataField: 'id',
47+ text: 'Product ID'
48+ }, {
49+ dataField: 'name',
50+ text: 'Product Name'
51+ }, {
52+ dataField: 'price',
53+ text: 'Product Price',
54+ validator: (newValue, row, column, done) => {
55+ setTimeout(() => {
56+ if (isNaN(newValue)) {
57+ return done({
58+ valid: false,
59+ message: 'Price should be numeric'
60+ });
61+ }
62+ if (newValue < 2000) {
63+ return done({
64+ valid: false,
65+ message: 'Price should bigger than 2000'
66+ });
67+ }
68+ return done();
69+ }, 2000);
70+ return {
71+ async: true
72+ };
73+ }
74+ }];
75+
76+ <BootstrapTable
77+ keyField="id"
78+ data={ products }
79+ columns={ columns }
80+ cellEdit={ cellEditFactory({
81+ mode: 'click',
82+ blurToSave: true
83+ }) }
84+ />
85+ ` ;
86+
87+ export default ( ) => (
88+ < div >
89+ < h3 > Product Price should bigger than $2000</ h3 >
90+ < BootstrapTable
91+ keyField = "id"
92+ data = { products }
93+ columns = { columns }
94+ cellEdit = { cellEditFactory ( {
95+ mode : 'click' ,
96+ blurToSave : true
97+ } ) }
98+ />
99+ < Code > { sourceCode } </ Code >
100+ </ div >
101+ ) ;
Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ import ColumnLevelEditableTable from 'examples/cell-edit/column-level-editable-t
9898import CellLevelEditable from 'examples/cell-edit/cell-level-editable-table' ;
9999import CellEditHooks from 'examples/cell-edit/cell-edit-hooks-table' ;
100100import CellEditValidator from 'examples/cell-edit/cell-edit-validator-table' ;
101+ import AsyncCellEditValidator from 'examples/cell-edit/cell-edit-async-validator-table' ;
101102import CellEditStyleTable from 'examples/cell-edit/cell-edit-style-table' ;
102103import CellEditClassTable from 'examples/cell-edit/cell-edit-class-table' ;
103104import AutoSelectTextInput from 'examples/cell-edit/auto-select-text-input-table' ;
@@ -289,6 +290,7 @@ storiesOf('Cell Editing', module)
289290 . add ( 'Cell Level Editable' , ( ) => < CellLevelEditable /> )
290291 . add ( 'Rich Hook Functions' , ( ) => < CellEditHooks /> )
291292 . add ( 'Validation' , ( ) => < CellEditValidator /> )
293+ . add ( 'Async Validation' , ( ) => < AsyncCellEditValidator /> )
292294 . add ( 'Auto Select Text Input' , ( ) => < AutoSelectTextInput /> )
293295 . add ( 'Custom Cell Style' , ( ) => < CellEditStyleTable /> )
294296 . add ( 'Custom Cell Classes' , ( ) => < CellEditClassTable /> )
You can’t perform that action at this time.
0 commit comments