-
Notifications
You must be signed in to change notification settings - Fork 782
/
insert-error-handle-table.js
58 lines (50 loc) · 1.79 KB
/
insert-error-handle-table.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* eslint max-len: 0 */
import React from 'react';
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
const jobs = [];
const jobTypes = [ 'A', 'B', 'C', 'D' ];
function addJobs(quantity) {
const startId = jobs.length;
for (let i = 0; i < quantity; i++) {
const id = startId + i;
jobs.push({
id: id,
name: 'Item name ' + id,
type: 'B',
active: i % 2 === 0 ? 'Y' : 'N'
});
}
}
addJobs(5);
export default class InsertErrorHandleTable extends React.Component {
handleAddRowWithSyncError = () => {
// Force to return an error message anyway.
return 'Sorry, There\'s some error happend';
}
handleAddRowWithASyncError = (row, colInfo, errorCallback) => {
// Use setTimeout to perform a async operation
setTimeout(() => {
// Force to return an error message anyway.
errorCallback('Sorry, There\'s some error happend');
}, 5000);
// return false to tell react-bootstrap-table to handle this operation as async
// react-bootstrap-table will wait errorCallback be called.
return false;
}
render() {
const option = {
onAddRow: this.handleAddRowWithASyncError
// onAddRow: this.handleAddRowWithSyncError
};
return (
<div>
<BootstrapTable data={ jobs } insertRow options={ option }>
<TableHeaderColumn dataField='id' isKey={ true }>Job ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Job Name</TableHeaderColumn>
<TableHeaderColumn dataField='type' editable={ { type: 'select', options: { values: jobTypes } } }>Job Type</TableHeaderColumn>
<TableHeaderColumn dataField='active' editable={ { type: 'checkbox', options: { values: 'Y:N' } } }>Active</TableHeaderColumn>
</BootstrapTable>
</div>
);
}
}