add story for column.filterValue

This commit is contained in:
AllenFang
2017-12-16 17:55:25 +08:00
parent ad98cfe1a8
commit 51ef91b066
3 changed files with 84 additions and 1 deletions
@@ -0,0 +1,72 @@
/* eslint no-unused-vars: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table2';
import fitlerFactory, { textFilter } from 'react-bootstrap-table2-filter';
import Code from 'components/common/code-block';
import { jobsGenerator } from 'utils/common';
const jobs = jobsGenerator(5);
const owners = ['Allen', 'Bob', 'Cat'];
const types = ['Cloud Service', 'Message Service', 'Add Service', 'Edit Service', 'Money'];
const columns = [{
dataField: 'id',
text: 'Job ID'
}, {
dataField: 'name',
text: 'Job Name',
filter: textFilter()
}, {
dataField: 'owner',
text: 'Job Owner',
filter: textFilter(),
formatter: (cell, row) => owners[cell],
filterValue: (cell, row) => owners[cell]
}, {
dataField: 'type',
text: 'Job Type',
filter: textFilter(),
formatter: (cell, row) => types[cell],
filterValue: (cell, row) => types[cell]
}];
const sourceCode = `\
const owners = ['Allen', 'Bob', 'Cat'];
const types = ['Cloud Service', 'Message Service', 'Add Service', 'Edit Service', 'Money'];
const columns = [{
dataField: 'id',
text: 'Job ID'
}, {
dataField: 'name',
text: 'Job Name',
filter: textFilter()
}, {
dataField: 'owner',
text: 'Job Owner',
filter: textFilter(),
formatter: (cell, row) => owners[cell],
filterValue: (cell, row) => owners[cell]
}, {
dataField: 'type',
text: 'Job Type',
filter: textFilter(),
filterValue: (cell, row) => types[cell]
}];
// shape of job: { id: 0, name: 'Job name 0', owner: 1, type: 3 }
<BootstrapTable keyField='id' data={ jobs } columns={ columns } filter={ fitlerFactory() } />
`;
export default () => (
<div>
<BootstrapTable
keyField="id"
data={ jobs }
columns={ columns }
filter={ fitlerFactory() }
/>
<Code>{ sourceCode }</Code>
</div>
);