Skip to content

20200307 release #1277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ This prop also accept a function:

* `column`
* `columnIndex`
* `props`: It's an object and contain `text` property only.

## <a name='footerClasses'>column.footerClasses - [String | Function]</a>
It's similar to [`column.classes`](#classes), `footerClasses` is available to have customized class on table footer column:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import filterFactory, { textFilter, dateFilter } from 'react-bootstrap-table2-filter';
import filterFactory, { textFilter, dateFilter, selectFilter } from 'react-bootstrap-table2-filter';
import Code from 'components/common/code-block';
import { stockGenerator } from 'utils/common';

const products = stockGenerator(8);

const selectOptions = {
0: 'good',
1: 'Bad',
2: 'unknown'
};

let nameFilter;
let priceFilter;
let qualityFilter;
let stockDateFilter;

const columns = [{
Expand All @@ -19,15 +26,28 @@ const columns = [{
filter: textFilter({
getFilter: (filter) => {
nameFilter = filter;
}
},
onFilter: filterVal => console.log(`Filter product name ${filterVal}`)
})
}, {
dataField: 'quality',
text: 'Product Quailty',
formatter: cell => selectOptions[cell],
filter: selectFilter({
options: selectOptions,
getFilter: (filter) => {
qualityFilter = filter;
},
onFilter: filterVal => console.log(`Filter quality ${filterVal}`)
})
}, {
dataField: 'price',
text: 'Price',
filter: textFilter({
getFilter: (filter) => {
priceFilter = filter;
}
},
onFilter: filterVal => console.log(`Filter Price: ${filterVal}`)
})
}, {
dataField: 'inStockDate',
Expand All @@ -36,13 +56,15 @@ const columns = [{
filter: dateFilter({
getFilter: (filter) => {
stockDateFilter = filter;
}
},
onFilter: filterVal => console.log(`Filter date: ${filterVal}`)
})
}];

const handleClick = () => {
nameFilter('');
priceFilter('');
qualityFilter('');
stockDateFilter();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const columns = [{
dataField: 'name',
text: 'Product Name',
footer: 'hello',
filter: textFilter()
filter: textFilter({
id: 'identify'
})
}, {
dataField: 'price',
text: 'Product Price',
Expand Down Expand Up @@ -54,7 +56,6 @@ export default () => (
data={ products }
columns={ columns }
filter={ filterFactory() }
filterPosition="bottom"
selectRow={ selectRow }
/>
<Code>{ sourceCode }</Code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { productsGenerator } from 'utils/common';

const products = productsGenerator();

function priceFormatter(column, colIndex) {
function priceFormatter(column, colIndex, { text }) {
return (
<h5>
<strong>$$ {column.text} $$</strong>
Expand Down Expand Up @@ -37,7 +37,7 @@ const columns = [
const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';

function priceFormatter(column, colIndex) {
function priceFormatter(column, colIndex, { text }) {
return (
<h5><strong>$$ { column.text } $$</strong></h5>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const stockGenerator = (quantity = 5) =>
name: `Stock Name ${index}`,
price: Math.floor((Math.random() * 2) + 1),
visible: Math.random() > 0.5,
quality: index % 3,
inStockDate:
new Date(startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime()))
}));
Expand Down
7 changes: 6 additions & 1 deletion packages/react-bootstrap-table2-filter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ const priceFilter = textFilter({
comparator: Comparator.EQ, // default is Comparator.LIKE
caseSensitive: true, // default is false, and true will only work when comparator is LIKE
style: { ... }, // your custom styles on input
delay: 1000 // how long will trigger filtering after user typing, default is 500 ms
delay: 1000, // how long will trigger filtering after user typing, default is 500 ms
id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page
});

// omit...
Expand Down Expand Up @@ -110,6 +111,7 @@ const qualityFilter = selectFilter({
comparator: Comparator.LIKE, // default is Comparator.EQ
style: { ... }, // your custom styles on input
withoutEmptyOption: true // hide the default select option
id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page
});

// omit...
Expand Down Expand Up @@ -197,6 +199,7 @@ const qualityFilter = multiSelectFilter({
comparator: Comparator.LIKE, // default is Comparator.EQ
style: { ... }, // your custom styles on input
withoutEmptyOption: true // hide the default select option
id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page
});

// omit...
Expand Down Expand Up @@ -236,6 +239,7 @@ const numberFilter = numberFilter({
numberStyle: { backgroundColor: 'cadetblue', margin: '0px' }, // custom the style on number input/select
numberClassName: 'custom-number-class', // custom the class on ber input/select
defaultValue: { number: 2103, comparator: Comparator.GT } // default value
id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page
})

// omit...
Expand Down Expand Up @@ -275,6 +279,7 @@ const dateFilter = dateFilter({
dateStyle: { backgroundColor: 'cadetblue', margin: '0px' }, // custom the style on date input
dateClassName: 'custom-date-class', // custom the class on date input
defaultValue: { date: new Date(2018, 0, 1), comparator: Comparator.GT } // default value
id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page
})

// omit...
Expand Down
18 changes: 12 additions & 6 deletions packages/react-bootstrap-table2-filter/src/components/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ class DateFilter extends Component {

render() {
const {
id,
placeholder,
column: { text },
column: { dataField, text },
style,
comparatorStyle,
dateStyle,
Expand All @@ -138,6 +139,9 @@ class DateFilter extends Component {
dateClassName
} = this.props;

const comparatorElmId = `date-filter-comparator-${dataField}${id ? `-${id}` : ''}`;
const inputElmId = `date-filter-column-${dataField}${id ? `-${id}` : ''}`;

return (
<div
onClick={ e => e.stopPropagation() }
Expand All @@ -146,12 +150,12 @@ class DateFilter extends Component {
>
<label
className="filter-label"
htmlFor={ `date-filter-comparator-${text}` }
htmlFor={ comparatorElmId }
>
<span className="sr-only">Filter comparator</span>
<select
ref={ n => this.dateFilterComparator = n }
id={ `date-filter-comparator-${text}` }
id={ comparatorElmId }
style={ comparatorStyle }
className={ `date-filter-comparator form-control ${comparatorClassName}` }
onChange={ this.onChangeComparator }
Expand All @@ -160,11 +164,11 @@ class DateFilter extends Component {
{ this.getComparatorOptions() }
</select>
</label>
<label htmlFor={ `date-filter-column-${text}` }>
<label htmlFor={ inputElmId }>
<span className="sr-only">Enter ${ text }</span>
<input
ref={ n => this.inputDate = n }
id={ `date-filter-column-${text}` }
id={ inputElmId }
className={ `filter date-filter-input form-control ${dateClassName}` }
style={ dateStyle }
type="date"
Expand All @@ -181,6 +185,7 @@ class DateFilter extends Component {
DateFilter.propTypes = {
onFilter: PropTypes.func.isRequired,
column: PropTypes.object.isRequired,
id: PropTypes.string,
filterState: PropTypes.object,
delay: PropTypes.number,
defaultValue: PropTypes.shape({
Expand Down Expand Up @@ -232,7 +237,8 @@ DateFilter.defaultProps = {
comparatorStyle: undefined,
comparatorClassName: '',
dateStyle: undefined,
dateClassName: ''
dateClassName: '',
id: null
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class MultiSelectFilter extends Component {

render() {
const {
id,
style,
className,
filterState,
Expand All @@ -128,17 +129,18 @@ class MultiSelectFilter extends Component {

const selectClass =
`filter select-filter form-control ${className} ${this.state.isSelected ? '' : 'placeholder-selected'}`;
const elmId = `multiselect-filter-column-${column.dataField}${id ? `-${id}` : ''}`;

return (
<label
className="filter-label"
htmlFor={ `multiselect-filter-column-${column.text}` }
htmlFor={ elmId }
>
<span className="sr-only">Filter by {column.text}</span>
<select
{ ...rest }
ref={ n => this.selectInput = n }
id={ `multiselect-filter-column-${column.text}` }
id={ elmId }
style={ style }
multiple
className={ selectClass }
Expand All @@ -157,6 +159,7 @@ MultiSelectFilter.propTypes = {
onFilter: PropTypes.func.isRequired,
column: PropTypes.object.isRequired,
options: PropTypes.object.isRequired,
id: PropTypes.string,
filterState: PropTypes.object,
comparator: PropTypes.oneOf([LIKE, EQ]),
placeholder: PropTypes.string,
Expand All @@ -174,7 +177,8 @@ MultiSelectFilter.defaultProps = {
className: '',
withoutEmptyOption: false,
comparator: EQ,
caseSensitive: true
caseSensitive: true,
id: null
};

export default MultiSelectFilter;
20 changes: 13 additions & 7 deletions packages/react-bootstrap-table2-filter/src/components/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class NumberFilter extends Component {
render() {
const { isSelected } = this.state;
const {
id,
column,
options,
style,
Expand All @@ -188,6 +189,9 @@ class NumberFilter extends Component {
${!isSelected ? 'placeholder-selected' : ''}
`;

const comparatorElmId = `number-filter-comparator-${column.dataField}${id ? `-${id}` : ''}`;
const inputElmId = `number-filter-column-${column.dataField}${id ? `-${id}` : ''}`;

return (
<div
onClick={ e => e.stopPropagation() }
Expand All @@ -196,13 +200,13 @@ class NumberFilter extends Component {
>
<label
className="filter-label"
htmlFor={ `number-filter-comparator-${column.text}` }
htmlFor={ comparatorElmId }
>
<span className="sr-only">Filter comparator</span>
<select
ref={ n => this.numberFilterComparator = n }
style={ comparatorStyle }
id={ `number-filter-comparator-${column.text}` }
id={ comparatorElmId }
className={ `number-filter-comparator form-control ${comparatorClassName}` }
onChange={ this.onChangeComparator }
defaultValue={ this.getDefaultComparator() }
Expand All @@ -214,12 +218,12 @@ class NumberFilter extends Component {
options ?
<label
className="filter-label"
htmlFor={ `number-filter-column-${column.text}` }
htmlFor={ inputElmId }
>
<span className="sr-only">{`Select ${column.text}`}</span>
<select
ref={ n => this.numberFilter = n }
id={ `number-filter-column-${column.text}` }
id={ inputElmId }
style={ numberStyle }
className={ selectClass }
onChange={ this.onChangeNumberSet }
Expand All @@ -228,11 +232,11 @@ class NumberFilter extends Component {
{ this.getNumberOptions() }
</select>
</label> :
<label htmlFor={ `number-filter-column-${column.text}` }>
<label htmlFor={ inputElmId }>
<span className="sr-only">{`Enter ${column.text}`}</span>
<input
ref={ n => this.numberFilter = n }
id={ `number-filter-column-${column.text}` }
id={ inputElmId }
type="number"
style={ numberStyle }
className={ `number-filter-input form-control ${numberClassName}` }
Expand All @@ -250,6 +254,7 @@ class NumberFilter extends Component {
NumberFilter.propTypes = {
onFilter: PropTypes.func.isRequired,
column: PropTypes.object.isRequired,
id: PropTypes.string,
filterState: PropTypes.object,
options: PropTypes.arrayOf(PropTypes.number),
defaultValue: PropTypes.shape({
Expand Down Expand Up @@ -305,7 +310,8 @@ NumberFilter.defaultProps = {
comparatorStyle: undefined,
comparatorClassName: '',
numberStyle: undefined,
numberClassName: ''
numberClassName: '',
id: null
};

export default NumberFilter;
Loading