-
Notifications
You must be signed in to change notification settings - Fork 781
/
array-filter-programmatically.js
42 lines (37 loc) · 1.26 KB
/
array-filter-programmatically.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
/* eslint max-len: 0 */
import React from 'react';
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i++) {
const id = startId + i;
products.push({
id: id,
name: 'Item name ' + id,
price: 2100 + i
});
}
}
addProducts(5);
export default class ProgrammaticallyArrayFilter extends React.Component {
/* Filtering passing an array of values */
handleBtnClick = () => {
this.refs.table.handleFilterData({
name: { type: 'ArrayFilter', value: [ 'Item name 3', 'Item name 4' ] },
price: { type: 'ArrayFilter', value: [ 2100, 2104 ] }
});
}
render() {
return (
<div>
<button onClick={ this.handleBtnClick } className='btn btn-default'>Click to apply array filter</button>
<BootstrapTable ref='table' data={ products }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' filter={ { type: 'TextFilter', delay: 1000 } }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
</div>
);
}
}