-
Notifications
You must be signed in to change notification settings - Fork 775
/
Copy pathfilter-style.js
81 lines (70 loc) · 2.34 KB
/
filter-style.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* eslint max-len: 0 */
/* eslint no-unused-vars: 0 */
import React from 'react';
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
const products = [];
const qualityType = {
0: 'good',
1: 'bad',
2: 'unknown'
};
function addProducts(quantity) {
const startId = products.length;
const startDate = new Date(2015, 0, 1);
const endDate = new Date();
for (let i = 0; i < quantity; i++) {
const date = new Date(startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime()));
const id = startId + i;
products.push({
id: id,
name: 'Item name ' + id,
quality: i % 3,
price: Math.floor((Math.random() * 100) + 1),
inStockDate: date
});
}
}
addProducts(5);
function enumFormatter(cell, row, enumObject) {
return enumObject[cell];
}
function dateFormatter(cell, row) {
return `${('0' + cell.getDate()).slice(-2)}/${('0' + (cell.getMonth() + 1)).slice(-2)}/${cell.getFullYear()}`;
}
const nameFilterStyle = {
borderColor: 'black'
};
const qualityFilterStyle = {
borderColor: 'red'
};
const priceFilterStyle = {
number: {
backgroundColor: 'antiquewhite'
},
comparator: {
border: '#0000FF 2.5px solid'
}
};
const dateFilterStyle = {
date: {
backgroundColor: 'antiquewhite'
},
comparator: {
border: '#0000FF 2.5px solid'
}
};
export default class FilterStyle extends React.Component {
render() {
return (
<BootstrapTable ref='table' data={ products }>
<TableHeaderColumn dataField='id' isKey={ true }>
Product ID
</TableHeaderColumn>
<TableHeaderColumn ref='name1' dataField='name' filter={ { type: 'TextFilter', style: nameFilterStyle } }>Product Name</TableHeaderColumn>
<TableHeaderColumn ref='quality' dataField='quality' filter={ { type: 'SelectFilter', options: qualityType, style: qualityFilterStyle } } dataFormat={ enumFormatter } formatExtraData={ qualityType }>Product Quality</TableHeaderColumn>
<TableHeaderColumn ref='price' dataField='price' filter={ { type: 'NumberFilter', delay: 1000, style: priceFilterStyle } }>Product Price</TableHeaderColumn>
<TableHeaderColumn ref='inStockDate' dataField='inStockDate' filter={ { type: 'DateFilter', style: dateFilterStyle } } dataFormat={ dateFormatter }>In Stock From</TableHeaderColumn>
</BootstrapTable>
);
}
}