-
Notifications
You must be signed in to change notification settings - Fork 775
/
Copy pathdefault-custom-csv-button.js
66 lines (58 loc) · 1.91 KB
/
default-custom-csv-button.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
59
60
61
62
63
64
65
66
/* eslint max-len: 0 */
/* eslint no-unused-vars: 0 */
/* eslint no-alert: 0 */
import React from 'react';
import { BootstrapTable, TableHeaderColumn, ExportCSVButton } from 'react-bootstrap-table';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i++) {
const id = startId + i;
products.push({
id: id,
name: 'Item name ' + id,
price: 2100 + i
});
}
}
addProducts(5);
export default class DefaultCustomExportButtonTable extends React.Component {
handleExportCSVButtonClick = (onClick) => {
// Custom your onClick event here,
// it's not necessary to implement this function if you have no any process before onClick
console.log('This is my custom function for ExportCSVButton click event');
onClick();
}
createCustomExportCSVButton = (onClick) => {
return (
<ExportCSVButton
btnText='CustomExportText'
btnContextual='btn-danger'
className='my-custom-class'
btnFAwesome='fa-edit'
onClick={ e => this.handleExportCSVButtonClick(onClick) }/>
);
// If you want have more power to custom the child of ExportCSVButton,
// you can do it like following
// return (
// <ExportCSVButton
// btnContextual='btn-warning'
// className='my-custom-class'
// onClick={ () => this.handleExportCSVButtonClick(onClick) }>
// { ... }
// </ExportCSVButton>
// );
}
render() {
const options = {
exportCSVBtn: this.createCustomExportCSVButton
};
return (
<BootstrapTable data={ products } options={ options } exportCSV>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
}