Skip to content

Commit e185529

Browse files
committed
examples for #1086
1 parent 4fe30ed commit e185529

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

examples/js/manipulation/demo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class Demo extends React.Component {
116116
<h5>Source in /examples/js/manipulation/export-csv-table.js</h5>
117117
<h5><b>Use <code>csvFormat</code> to format cell when exporting.</b></h5>
118118
<h5><b>Use <code>csvHeader</code> to change the header text in csv.</b></h5>
119+
<h5><b>Use <code>csvFormatExtraData</code> to assign your extra data for formatting csv cell data.</b></h5>
119120
<ExportCSVTable />
120121
</div>
121122
</div>

examples/js/manipulation/export-csv-table.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
66

77
const products = [];
88

9+
const qualityType = {
10+
0: 'good',
11+
1: 'bad',
12+
2: 'unknown'
13+
};
14+
915
function addProducts(quantity) {
1016
const startId = products.length;
1117
for (let i = 0; i < quantity; i++) {
1218
const id = startId + i;
1319
products.push({
1420
id: id,
1521
name: 'Item name ' + id,
16-
price: 2100 + i
22+
price: 2100 + i,
23+
quality: i % 3
1724
});
1825
}
1926
}
@@ -22,16 +29,21 @@ addProducts(5);
2229

2330
export default class ExportCSVTable extends React.Component {
2431

25-
csvFormatter(cell, row) {
32+
csvPriceFormatter(cell, row) {
2633
return `${row.id}: ${cell} USD`;
2734
}
2835

36+
csvQualityFormatter(cell, row, extra) {
37+
return extra[cell];
38+
}
39+
2940
render() {
3041
return (
3142
<BootstrapTable data={ products } exportCSV={ true }>
3243
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
3344
<TableHeaderColumn dataField='name' csvHeader='product-name'>Product Name</TableHeaderColumn>
34-
<TableHeaderColumn dataField='price' csvFormat={ this.csvFormatter }>Product Price</TableHeaderColumn>
45+
<TableHeaderColumn dataField='price' csvFormat={ this.csvPriceFormatter }>Product Price</TableHeaderColumn>
46+
<TableHeaderColumn dataField='quality' csvFormat={ this.csvQualityFormatter } csvFormatExtraData={ qualityType }>Product Quality</TableHeaderColumn>
3547
</BootstrapTable>
3648
);
3749
}

0 commit comments

Comments
 (0)