-
Notifications
You must be signed in to change notification settings - Fork 775
/
Copy pathsearch-format-table.js
56 lines (48 loc) · 1.68 KB
/
search-format-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
/* eslint max-len: 0 */
/* eslint no-console: 0 */
/* eslint no-unused-vars: 0 */
import React from 'react';
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
const products = [];
function addProducts(quantity) {
const startId = products.length;
const pname = [ 'Cloud Service', 'Message Service', 'Add Service', 'Edit Service', 'Money' ];
const icons = [ 'glyphicon-cloud', 'glyphicon-envelope', 'glyphicon-plus', 'glyphicon-pencil', 'glyphicon-euro' ];
const types = [ 'Cloud', 'Mail', 'Insert', 'Modify', 'Money' ];
const years = [ 2005, 2006, 2008, 2001, 2015 ];
for (let i = 0; i < quantity; i++) {
const id = startId + i;
products.push({
id: id,
name: {
pname: pname[i],
type: types[i],
icon: icons[i],
year: years[i]
},
price: 2100 + i
});
}
}
addProducts(5);
function filterType(cell, row) {
// just return type for filtering or searching.
return cell.type;
}
function nameFormatter(cell) {
return `<p><span class='glyphicons ${cell.icon}' aria-hidden='true'></span> ${cell.pname}, from ${cell.year}</p>`;
}
function priceFormatter(cell) {
return `NTD ${cell}`;
}
export default class SearchFormatTable extends React.Component {
render() {
return (
<BootstrapTable data={ products } search={ true }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' filterValue={ filterType } dataFormat={ nameFormatter }>Product</TableHeaderColumn>
<TableHeaderColumn dataField='price' filterFormatted dataFormat={ priceFormatter }>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
}