Skip to content

Commit 47f6340

Browse files
committed
story for #1054
1 parent 23cb0bb commit 47f6340

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import React from 'react';
2+
import BootstrapTable from 'react-bootstrap-table-next';
3+
import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter';
4+
import Code from 'components/common/code-block';
5+
import { productsQualityGenerator } from 'utils/common';
6+
7+
const products = productsQualityGenerator(6);
8+
9+
const selectOptions = {
10+
0: 'good',
11+
1: 'Bad',
12+
2: 'unknown'
13+
};
14+
15+
const selectOptionsArr = [{
16+
value: 0,
17+
label: 'good'
18+
}, {
19+
value: 1,
20+
label: 'Bad'
21+
}, {
22+
value: 2,
23+
label: 'unknown'
24+
}];
25+
26+
const columns1 = [{
27+
dataField: 'id',
28+
text: 'Product ID'
29+
}, {
30+
dataField: 'name',
31+
text: 'Product Name'
32+
}, {
33+
dataField: 'quality',
34+
text: 'Product Quailty',
35+
formatter: cell => selectOptions[cell],
36+
filter: selectFilter({
37+
options: selectOptions
38+
})
39+
}];
40+
41+
const columns2 = [{
42+
dataField: 'id',
43+
text: 'Product ID'
44+
}, {
45+
dataField: 'name',
46+
text: 'Product Name'
47+
}, {
48+
dataField: 'quality',
49+
text: 'Product Quailty',
50+
formatter: cell => selectOptionsArr.filter(opt => opt.value === cell)[0].label || '',
51+
filter: selectFilter({
52+
options: selectOptionsArr
53+
})
54+
}];
55+
56+
const columns3 = [{
57+
dataField: 'id',
58+
text: 'Product ID'
59+
}, {
60+
dataField: 'name',
61+
text: 'Product Name'
62+
}, {
63+
dataField: 'quality',
64+
text: 'Product Quailty',
65+
formatter: cell => selectOptionsArr.filter(opt => opt.value === cell)[0].label || '',
66+
filter: selectFilter({
67+
options: () => selectOptionsArr
68+
})
69+
}];
70+
71+
const sourceCode = `\
72+
import BootstrapTable from 'react-bootstrap-table-next';
73+
import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter';
74+
75+
// Object map options
76+
const selectOptions = {
77+
0: 'good',
78+
1: 'Bad',
79+
2: 'unknown'
80+
};
81+
82+
// Array options
83+
const selectOptionsArr = [{
84+
value: 0,
85+
label: 'good'
86+
}, {
87+
value: 1,
88+
label: 'Bad'
89+
}, {
90+
value: 2,
91+
label: 'unknown'
92+
}];
93+
94+
const columns1 = [..., {
95+
dataField: 'quality',
96+
text: 'Product Quailty',
97+
formatter: cell => selectOptions[cell],
98+
filter: selectFilter({
99+
options: selectOptions
100+
})
101+
}];
102+
<BootstrapTable keyField='id' data={ products } columns={ columns1 } filter={ filterFactory() } />
103+
104+
const columns2 = [..., {
105+
dataField: 'quality',
106+
text: 'Product Quailty',
107+
formatter: cell => selectOptionsArr.filter(opt => opt.value === cell)[0].label || '',
108+
filter: selectFilter({
109+
options: selectOptionsArr
110+
})
111+
}];
112+
<BootstrapTable keyField='id' data={ products } columns={ columns2 } filter={ filterFactory() } />
113+
114+
const columns3 = [..., {
115+
dataField: 'quality',
116+
text: 'Product Quailty',
117+
formatter: cell => selectOptionsArr.filter(opt => opt.value === cell)[0].label || '',
118+
filter: selectFilter({
119+
options: () => selectOptionsArr
120+
})
121+
}];
122+
<BootstrapTable keyField='id' data={ products } columns={ columns3 } filter={ filterFactory() } />
123+
`;
124+
125+
export default () => (
126+
<div>
127+
<h2>Options as an object</h2>
128+
<BootstrapTable
129+
keyField="id"
130+
data={ products }
131+
columns={ columns1 }
132+
filter={ filterFactory() }
133+
/>
134+
<h2>Options as an array</h2>
135+
<BootstrapTable
136+
keyField="id"
137+
data={ products }
138+
columns={ columns2 }
139+
filter={ filterFactory() }
140+
/>
141+
<h2>Options as a function which return an array</h2>
142+
<BootstrapTable
143+
keyField="id"
144+
data={ products }
145+
columns={ columns3 }
146+
filter={ filterFactory() }
147+
/>
148+
<Code>{ sourceCode }</Code>
149+
</div>
150+
);

packages/react-bootstrap-table2-example/stories/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import TextFilterCaseSensitive from 'examples/column-filter/text-filter-caseSens
6868
import CustomTextFilter from 'examples/column-filter/custom-text-filter';
6969
import CustomFilterValue from 'examples/column-filter/custom-filter-value';
7070
import SelectFilter from 'examples/column-filter/select-filter';
71+
import ConfigureSelectFilterOptions from 'examples/column-filter/select-filter-option-type';
7172
import SelectFilterWithDefaultValue from 'examples/column-filter/select-filter-default-value';
7273
import SelectFilterComparator from 'examples/column-filter/select-filter-like-comparator';
7374
import SelectFilterWithPreservedOptionsOrder from 'examples/column-filter/select-filter-preserve-option-order';
@@ -300,6 +301,7 @@ storiesOf('Column Filter', module)
300301
.add('Text Filter with Case Sensitive', () => <TextFilterCaseSensitive />)
301302
// add another filter type example right here.
302303
.add('Select Filter', () => <SelectFilter />)
304+
.add('Configure Select Filter Options', () => <ConfigureSelectFilterOptions />)
303305
.add('Select Filter with Default Value', () => <SelectFilterWithDefaultValue />)
304306
.add('Select Filter with Comparator', () => <SelectFilterComparator />)
305307
.add('MultiSelect Filter', () => <MultiSelectFilter />)

0 commit comments

Comments
 (0)