Skip to content

Commit e9c3a90

Browse files
committed
example for using select editor with text and value customization
1 parent face547 commit e9c3a90

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

examples/js/advance/edit-type-table.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,24 @@ import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
44

55

66
const 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

926
function addJobs(quantity) {
1027
const startId = jobs.length;
@@ -28,12 +45,21 @@ const cellEditProp = {
2845
};
2946

3047
export 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

Comments
 (0)