@@ -4,7 +4,24 @@ import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
44
55
66const jobs = [ ] ;
7- const jobTypes = [ 'A' , 'B' , 'C' , 'D' ] ;
7+ // editable, select type also accept a string array
8+ // it's most simple case for using select, but the text and value will all be the value in array
9+ // const jobTypes = [ 'A', 'B', 'C', 'D' ];
10+ //
11+ // Following case will be more easy to control the text and value in select.
12+ const jobTypes = [ {
13+ value : 'A' ,
14+ text : 'TYPE_A'
15+ } , {
16+ value : 'B' ,
17+ text : 'TYPE_B'
18+ } , {
19+ value : 'C' ,
20+ text : 'TYPE_C'
21+ } , {
22+ value : 'D' ,
23+ text : 'TYPE_D'
24+ } ] ;
825
926function addJobs ( quantity ) {
1027 const startId = jobs . length ;
@@ -28,12 +45,21 @@ const cellEditProp = {
2845} ;
2946
3047export default class EditTypeTable extends React . Component {
48+ constructor ( props ) {
49+ super ( props ) ;
50+ this . formatType = this . formatType . bind ( this ) ;
51+ }
52+
53+ formatType ( cell ) {
54+ return `TYPE_${ cell } ` ;
55+ }
56+
3157 render ( ) {
3258 return (
3359 < BootstrapTable data = { jobs } cellEdit = { cellEditProp } >
3460 < TableHeaderColumn dataField = 'id' isKey = { true } > Job ID</ TableHeaderColumn >
3561 < TableHeaderColumn dataField = 'name' editable = { { type : 'textarea' } } > Job Name</ TableHeaderColumn >
36- < TableHeaderColumn dataField = 'type' editable = { { type : 'select' , options : { values : jobTypes } } } > Job Type</ TableHeaderColumn >
62+ < TableHeaderColumn dataField = 'type' dataFormat = { this . formatType } editable = { { type : 'select' , options : { values : jobTypes } } } > Job Type</ TableHeaderColumn >
3763 < TableHeaderColumn dataField = 'active' editable = { { type : 'checkbox' , options : { values : 'Y:N' } } } > Active</ TableHeaderColumn >
3864 < TableHeaderColumn dataField = 'datetime' editable = { { type : 'datetime' } } > Date Time</ TableHeaderColumn >
3965 </ BootstrapTable >
0 commit comments