Skip to content

Commit

Permalink
New filtering behavior + default filter definition
Browse files Browse the repository at this point in the history
  • Loading branch information
dana2208 committed Feb 14, 2016
1 parent 3db37b6 commit 47eb362
Show file tree
Hide file tree
Showing 27 changed files with 1,223 additions and 20 deletions.
38 changes: 37 additions & 1 deletion css/react-bootstrap-table.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
}

.react-bs-container .table-header{
height: 42px;
border: hidden;
overflow: hidden;
}
Expand All @@ -17,12 +16,17 @@
border-right-style: hidden;
border-left-style: hidden;
width: 100%;
margin-bottom: 0;
}

.react-bs-container .table-header > table > thead > tr{
border-bottom-style: hidden;
}

.react-bs-container .table-header > table > thead > tr > th {
vertical-align: inherit;
}

.react-bs-container .table-container > table > tbody > tr > td,
.react-bs-container .table-container > table > thead > tr > th,
.react-bs-container .table-header > table > thead > tr > th .table-header-column{
Expand All @@ -33,6 +37,38 @@
white-space: nowrap;
}

.react-bs-container .table-header > table > thead > tr > th .filter{
font-weight: normal;
}

.react-bs-container .table-header > table > thead > tr > th .select-filter option[value=''],
.react-bs-container .table-header > table > thead > tr > th .select-filter.placeholder-selected,
.react-bs-container .table-header > table > thead > tr > th .filter::-webkit-input-placeholder,
.react-bs-container .table-header > table > thead > tr > th .number-filter-input::-webkit-input-placeholder{
color: lightgrey;
font-style: italic;
}

.react-bs-container .table-header > table > thead > tr > th .select-filter.placeholder-selected option:not([value='']) {
color: initial;
font-style: initial;
}

.react-bs-container .table-header > table > thead > tr > th .number-filter {
display: flex;
}

.react-bs-container .table-header > table > thead > tr > th .number-filter-input {
margin-left: 5px;
float: left;
width: calc(100% - 67px - 5px);
}

.react-bs-container .table-header > table > thead > tr > th .number-filter-comparator {
width: 67px;
float: left;
}

.react-bs-container .table-header > table > thead > tr > .sort-column{
cursor: pointer;
}
Expand Down
2 changes: 1 addition & 1 deletion css/react-bootstrap-table.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions dist/react-bootstrap-table.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const routes = (
<Route path="column" component={require('./column/demo')} />
<Route path="sort" component={require('./sort/demo')} />
<Route path="column-format" component={require('./column-format/demo')} />
<Route path="column-filter" component={require('./column-filter/demo')} />
<Route path="selection" component={require('./selection/demo')} />
<Route path="pagination" component={require('./pagination/demo')} />
<Route path="manipulation" component={require('./manipulation/demo')} />
Expand Down
56 changes: 56 additions & 0 deletions examples/js/column-filter/all-filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';
import React from 'react';
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table';

var products = [];

var qualityType = {
0: "good",
1: "bad",
2: "unknown"
};

function addProducts(quantity) {
var startId = products.length;
const startDate = new Date(2015, 0, 1);
const endDate = new Date();
for (var i = 0; i < quantity; i++) {
const date = new Date(startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime()));
var id = startId + i;
products.push({
id: id,
name: "Item name " + id,
quality: i%3,
price: Math.floor((Math.random() * 100) + 1),
satisfaction: Math.floor(Math.random() * 6),
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()}`;
}

var satisfaction = [0, 1, 2, 3, 4, 5];

export default class AllFilters extends React.Component{
render(){
return (
<BootstrapTable data={products}>
<TableHeaderColumn dataField="id" isKey={true}>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField="name" filter={{type: "TextFilter", placeholder: "Please enter a value"}}>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField="quality" filter={{type: "SelectFilter", options: qualityType}} dataFormat={enumFormatter} formatExtraData={qualityType}>Product Quality</TableHeaderColumn>
<TableHeaderColumn dataField="price" filter={{type: "NumberFilter", delay: 1000}}>Product Price</TableHeaderColumn>
<TableHeaderColumn dataField="satisfaction" filter={{type: "NumberFilter", options: satisfaction}}>Buyer Satisfaction</TableHeaderColumn>
<TableHeaderColumn dataField="inStockDate" filter={{type: "DateFilter"}} dataFormat={dateFormatter}>In Stock From</TableHeaderColumn>
</BootstrapTable>
);
}
};
82 changes: 82 additions & 0 deletions examples/js/column-filter/custom-filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
'use strict';
import React from 'react';
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table';

var products = [];

function addProducts(quantity) {
var startId = products.length;
for (var i = 0; i < quantity; i++) {
var id = startId + i;
products.push({
id: id,
name: "Item name " + id,
isInStock: (i%3 == 0) ? "yes" : "no"
});
}
}

addProducts(5);

class CheckboxFilter extends React.Component {
constructor(props) {
super(props);
this.filter = this.filter.bind(this);
this.isFiltered = this.isFiltered.bind(this);
}

filter(event) {
if (this.refs.nokCheckbox.checked && this.refs.okCheckbox.checked) {
// all checkboxes are checked means we want to remove the filter for this column
this.props.filterHandler();
} else {
this.props.filterHandler({callback: this.isFiltered});
}
}

isFiltered(targetValue) {
if (targetValue === "no") {
return (this.refs.nokCheckbox.checked);
} else {
return (this.refs.okCheckbox.checked);
}
}

render() {
return (
<div>
<input ref="okCheckbox" type="checkbox" className="filter" onChange={this.filter} defaultChecked={true} /><label>{this.props.textOK}</label>
<input ref="nokCheckbox" type="checkbox" className="filter" onChange={this.filter} defaultChecked={true} style={{marginLeft: 30 + "px"}} /><label>{this.props.textNOK}</label>
</div>
);
}
};

CheckboxFilter.propTypes = {
filterHandler: React.PropTypes.func.isRequired,
textOK: React.PropTypes.string,
textNOK: React.PropTypes.string
};

CheckboxFilter.defaultProps = {
textOK: "OK",
textNOK: "Not OK"
}

function getCustomFilter(filterHandler, customFilterParameters){
return (
<CheckboxFilter filterHandler={filterHandler} textOK={customFilterParameters.textOK} textNOK={customFilterParameters.textNOK} />
);
}

export default class CustomFilter extends React.Component{
render(){
return (
<BootstrapTable data={products}>
<TableHeaderColumn dataField="id" isKey={true}>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField="name">Product Name</TableHeaderColumn>
<TableHeaderColumn dataField="isInStock" filter={{type: "CustomFilter", getElement: getCustomFilter, customFilterParameters: {textOK: 'yes', textNOK: 'no'} }}>Product Is In Stock</TableHeaderColumn>
</BootstrapTable>
);
}
};
38 changes: 38 additions & 0 deletions examples/js/column-filter/date-filter-with-default-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
import React from 'react';
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table';

var products = [];

function addProducts(quantity) {
var startId = products.length;
const startDate = new Date(2015, 0, 1);
const endDate = new Date();
for (var i = 0; i < quantity; i++) {
const date = new Date(startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime()));
var id = startId + i;
products.push({
id: id,
name: "Item name " + id,
inStockDate: date
});
}
}

addProducts(5);

function dateFormatter(cell, row) {
return `${("0" + cell.getDate()).slice(-2)}/${("0" + (cell.getMonth() + 1)).slice(-2)}/${cell.getFullYear()}`;
}

export default class DateFilterWithDefaultValue extends React.Component{
render(){
return (
<BootstrapTable data={products}>
<TableHeaderColumn dataField="id" isKey={true}>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField="name">Product Name</TableHeaderColumn>
<TableHeaderColumn dataField="inStockDate" dataFormat={dateFormatter} filter={{type: "DateFilter", defaultValue: new Date(2015,7,22)}}>In Stock From</TableHeaderColumn>
</BootstrapTable>
);
}
};
38 changes: 38 additions & 0 deletions examples/js/column-filter/date-filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
import React from 'react';
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table';

var products = [];

function addProducts(quantity) {
var startId = products.length;
const startDate = new Date(2015, 0, 1);
const endDate = new Date();
for (var i = 0; i < quantity; i++) {
const date = new Date(startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime()));
var id = startId + i;
products.push({
id: id,
name: "Item name " + id,
inStockDate: date
});
}
}

addProducts(5);

function dateFormatter(cell, row) {
return `${("0" + cell.getDate()).slice(-2)}/${("0" + (cell.getMonth() + 1)).slice(-2)}/${cell.getFullYear()}`;
}

export default class DateFilter extends React.Component{
render(){
return (
<BootstrapTable data={products}>
<TableHeaderColumn dataField="id" isKey={true}>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField="name">Product Name</TableHeaderColumn>
<TableHeaderColumn dataField="inStockDate" dataFormat={dateFormatter} filter={{type: "DateFilter"}}>In Stock From</TableHeaderColumn>
</BootstrapTable>
);
}
};
Loading

0 comments on commit 47eb362

Please sign in to comment.