mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
2018/04/01 release
2018/04/01 release
This commit is contained in:
commit
1d7df6819e
@ -11,6 +11,8 @@ branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
except:
|
||||
- gh-pages-src
|
||||
|
||||
before_install:
|
||||
- curl -o- -L https://yarnpkg.com/install.sh | bash -s
|
||||
|
||||
@ -158,12 +158,12 @@ const selectRow = {
|
||||
|
||||
### <a name='onSelect'>selectRow.onSelect - [Function]</a>
|
||||
This callback function will be called when a row is select/unselect and pass following three arguments:
|
||||
`row`, `isSelect` and `rowIndex`.
|
||||
`row`, `isSelect`, `rowIndex` and `e`.
|
||||
|
||||
```js
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
onSelect: (row, isSelect, rowIndex) => {
|
||||
onSelect: (row, isSelect, rowIndex, e) => {
|
||||
// ...
|
||||
}
|
||||
};
|
||||
@ -175,7 +175,7 @@ This callback function will be called when select/unselect all and it only work
|
||||
```js
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
onSelectAll: (isSelect, results) => {
|
||||
onSelectAll: (isSelect, results, e) => {
|
||||
// ...
|
||||
}
|
||||
};
|
||||
|
||||
@ -72,9 +72,15 @@ function styles() {
|
||||
.pipe(gulp.dest(PKG_PATH));
|
||||
}
|
||||
|
||||
function umd() {
|
||||
return gulp.src('./webpack.prod.config.babel.js')
|
||||
.pipe(shell(['webpack --config <%= file.path %>']));
|
||||
function umd(done) {
|
||||
gulp.parallel(
|
||||
() => gulp.src('./webpack/next.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
|
||||
() => gulp.src('./webpack/editor.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
|
||||
() => gulp.src('./webpack/filter.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
|
||||
() => gulp.src('./webpack/overlay.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
|
||||
() => gulp.src('./webpack/paginator.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>']))
|
||||
)();
|
||||
done();
|
||||
}
|
||||
|
||||
const buildJS = gulp.parallel(umd, scripts);
|
||||
|
||||
85
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-number-filter.js
vendored
Normal file
85
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-number-filter.js
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
import React from 'react';
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { numberFilter, Comparator } from 'react-bootstrap-table2-filter';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const products = productsGenerator(8);
|
||||
|
||||
let priceFilter;
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
filter: numberFilter({
|
||||
getFilter: (filter) => {
|
||||
// pricerFilter was assigned once the component has been mounted.
|
||||
priceFilter = filter;
|
||||
}
|
||||
})
|
||||
}];
|
||||
|
||||
const handleClick = () => {
|
||||
priceFilter({
|
||||
number: 2103,
|
||||
comparator: Comparator.GT
|
||||
});
|
||||
};
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { numberFilter } from 'react-bootstrap-table2-filter';
|
||||
|
||||
let priceFilter;
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
filter: numberFilter({
|
||||
getFilter: (filter) => {
|
||||
// pricerFilter was assigned once the component has been mounted.
|
||||
priceFilter = filter;
|
||||
}
|
||||
})
|
||||
}];
|
||||
|
||||
const handleClick = () => {
|
||||
priceFilter({
|
||||
number: 2103,
|
||||
comparator: Comparator.GT
|
||||
});
|
||||
};
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<button className="btn btn-lg btn-primary" onClick={ handleClick }> filter all columns which is greater than 2103 </button>
|
||||
|
||||
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
||||
</div>
|
||||
);
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<button className="btn btn-lg btn-primary" onClick={ handleClick }> filter all columns which is greater than 2103 </button>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
96
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-select-filter.js
vendored
Normal file
96
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-select-filter.js
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
import React from 'react';
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsQualityGenerator } from 'utils/common';
|
||||
|
||||
const products = productsQualityGenerator(6);
|
||||
|
||||
let qualityFilter;
|
||||
|
||||
const selectOptions = {
|
||||
0: 'good',
|
||||
1: 'Bad',
|
||||
2: 'unknown'
|
||||
};
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quality',
|
||||
formatter: cell => selectOptions[cell],
|
||||
filter: selectFilter({
|
||||
options: selectOptions,
|
||||
getFilter: (filter) => {
|
||||
// qualityFilter was assigned once the component has been mounted.
|
||||
qualityFilter = filter;
|
||||
}
|
||||
})
|
||||
}];
|
||||
|
||||
const handleClick = () => {
|
||||
qualityFilter(0);
|
||||
};
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter';
|
||||
|
||||
let qualityFilter;
|
||||
|
||||
const selectOptions = {
|
||||
0: 'good',
|
||||
1: 'Bad',
|
||||
2: 'unknown'
|
||||
};
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quality',
|
||||
formatter: cell => selectOptions[cell],
|
||||
filter: selectFilter({
|
||||
options: selectOptions,
|
||||
getFilter: (filter) => {
|
||||
// qualityFilter was assigned once the component has been mounted.
|
||||
qualityFilter = filter;
|
||||
}
|
||||
})
|
||||
}];
|
||||
|
||||
const handleClick = () => {
|
||||
qualityFilter(0);
|
||||
};
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<button className="btn btn-lg btn-primary" onClick={ handleClick }>{' filter columns by option "good" '}</button>
|
||||
|
||||
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
||||
</div>
|
||||
);
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<button className="btn btn-lg btn-primary" onClick={ handleClick }>{' filter columns by option "good" '}</button>
|
||||
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
81
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-text-filter.js
vendored
Normal file
81
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-text-filter.js
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
import React from 'react';
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const products = productsGenerator(8);
|
||||
|
||||
let nameFilter;
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
filter: textFilter({
|
||||
getFilter: (filter) => {
|
||||
// nameFilter was assigned once the component has been mounted.
|
||||
nameFilter = filter;
|
||||
}
|
||||
})
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
filter: textFilter()
|
||||
}];
|
||||
|
||||
const handleClick = () => {
|
||||
nameFilter(0);
|
||||
};
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||
|
||||
let nameFilter;
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
filter: textFilter({
|
||||
getFilter: (filter) => {
|
||||
// nameFilter was assigned once the component has been mounted.
|
||||
nameFilter = filter;
|
||||
}
|
||||
})
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
filter: textFilter()
|
||||
}];
|
||||
|
||||
const handleClick = () => {
|
||||
nameFilter(0);
|
||||
};
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<button className="btn btn-lg btn-primary" onClick={ handleClick }> filter columns by 0 </button>
|
||||
|
||||
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
||||
</div>
|
||||
);
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<button className="btn btn-lg btn-primary" onClick={ handleClick }> filter columns by 0 </button>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
@ -22,14 +22,16 @@ const columns = [{
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true,
|
||||
onSelect: (row, isSelect, rowIndex) => {
|
||||
onSelect: (row, isSelect, rowIndex, e) => {
|
||||
console.log(row.id);
|
||||
console.log(isSelect);
|
||||
console.log(rowIndex);
|
||||
console.log(e);
|
||||
},
|
||||
onSelectAll: (isSelect, rows) => {
|
||||
onSelectAll: (isSelect, rows, e) => {
|
||||
console.log(isSelect);
|
||||
console.log(rows);
|
||||
console.log(e);
|
||||
}
|
||||
};
|
||||
|
||||
@ -49,7 +51,18 @@ const columns = [{
|
||||
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true
|
||||
clickToSelect: true,
|
||||
onSelect: (row, isSelect, rowIndex, e) => {
|
||||
console.log(row.id);
|
||||
console.log(isSelect);
|
||||
console.log(rowIndex);
|
||||
console.log(e);
|
||||
},
|
||||
onSelectAll: (isSelect, rows, e) => {
|
||||
console.log(isSelect);
|
||||
console.log(rows);
|
||||
console.log(e);
|
||||
}
|
||||
};
|
||||
|
||||
<BootstrapTable
|
||||
|
||||
@ -48,6 +48,9 @@ import CustomSelectFilter from 'examples/column-filter/custom-select-filter';
|
||||
import NumberFilter from 'examples/column-filter/number-filter';
|
||||
import NumberFilterWithDefaultValue from 'examples/column-filter/number-filter-default-value';
|
||||
import CustomNumberFilter from 'examples/column-filter/custom-number-filter';
|
||||
import ProgrammaticallyTextFilter from 'examples/column-filter/programmatically-text-filter';
|
||||
import ProgrammaticallySelectFilter from 'examples/column-filter/programmatically-select-filter';
|
||||
import ProgrammaticallyNumberFilter from 'examples/column-filter/programmatically-number-filter';
|
||||
|
||||
// work on rows
|
||||
import RowStyleTable from 'examples/rows/row-style';
|
||||
@ -166,7 +169,10 @@ storiesOf('Column Filter', module)
|
||||
.add('Custom Text Filter', () => <CustomTextFilter />)
|
||||
.add('Custom Select Filter', () => <CustomSelectFilter />)
|
||||
.add('Custom Number Filter', () => <CustomNumberFilter />)
|
||||
.add('Custom Filter Value', () => <CustomFilterValue />);
|
||||
.add('Custom Filter Value', () => <CustomFilterValue />)
|
||||
.add('Programmatically Text Filter ', () => <ProgrammaticallyTextFilter />)
|
||||
.add('Programmatically Select Filter ', () => <ProgrammaticallySelectFilter />)
|
||||
.add('Programmatically Number Filter ', () => <ProgrammaticallyNumberFilter />);
|
||||
|
||||
storiesOf('Work on Rows', module)
|
||||
.add('Customize Row Style', () => <RowStyleTable />)
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint react/require-default-props: 0 */
|
||||
/* eslint no-return-assign: 0 */
|
||||
|
||||
import React, { Component } from 'react';
|
||||
@ -30,11 +31,25 @@ class NumberFilter extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { column, onFilter } = this.props;
|
||||
const { column, onFilter, getFilter } = this.props;
|
||||
const comparator = this.numberFilterComparator.value;
|
||||
const number = this.numberFilter.value;
|
||||
if (comparator && number) {
|
||||
onFilter(column, { number, comparator }, FILTER_TYPE.NUMBER);
|
||||
onFilter(column, FILTER_TYPE.NUMBER)({ number, comparator });
|
||||
}
|
||||
|
||||
// export onFilter function to allow users to access
|
||||
if (getFilter) {
|
||||
getFilter((filterVal) => {
|
||||
this.setState(() => ({ isSelected: (filterVal !== '') }));
|
||||
this.numberFilterComparator.value = filterVal.comparator;
|
||||
this.numberFilter.value = filterVal.number;
|
||||
|
||||
onFilter(column, FILTER_TYPE.NUMBER)({
|
||||
number: filterVal.number,
|
||||
comparator: filterVal.comparator
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +68,7 @@ class NumberFilter extends Component {
|
||||
}
|
||||
const filterValue = e.target.value;
|
||||
this.timeout = setTimeout(() => {
|
||||
onFilter(column, { number: filterValue, comparator }, FILTER_TYPE.NUMBER);
|
||||
onFilter(column, FILTER_TYPE.NUMBER)({ number: filterValue, comparator });
|
||||
}, delay);
|
||||
}
|
||||
|
||||
@ -65,7 +80,7 @@ class NumberFilter extends Component {
|
||||
// if (comparator === '') {
|
||||
// return;
|
||||
// }
|
||||
onFilter(column, { number: value, comparator }, FILTER_TYPE.NUMBER);
|
||||
onFilter(column, FILTER_TYPE.NUMBER)({ number: value, comparator });
|
||||
}
|
||||
|
||||
onChangeComparator(e) {
|
||||
@ -75,7 +90,7 @@ class NumberFilter extends Component {
|
||||
// if (value === '') {
|
||||
// return;
|
||||
// }
|
||||
onFilter(column, { number: value, comparator }, FILTER_TYPE.NUMBER);
|
||||
onFilter(column, FILTER_TYPE.NUMBER)({ number: value, comparator });
|
||||
}
|
||||
|
||||
getComparatorOptions() {
|
||||
@ -116,7 +131,7 @@ class NumberFilter extends Component {
|
||||
this.setState(() => ({ isSelected: (number !== '') }));
|
||||
this.numberFilterComparator.value = comparator;
|
||||
this.numberFilter.value = number;
|
||||
onFilter(column, { number, comparator }, FILTER_TYPE.NUMBER);
|
||||
onFilter(column, FILTER_TYPE.NUMBER)({ number, comparator });
|
||||
}
|
||||
|
||||
cleanFiltered() {
|
||||
@ -126,7 +141,7 @@ class NumberFilter extends Component {
|
||||
this.setState(() => ({ isSelected: (value !== '') }));
|
||||
this.numberFilterComparator.value = comparator;
|
||||
this.numberFilter.value = value;
|
||||
onFilter(column, { number: value, comparator }, FILTER_TYPE.NUMBER);
|
||||
onFilter(column, FILTER_TYPE.NUMBER)({ number: value, comparator });
|
||||
}
|
||||
|
||||
render() {
|
||||
@ -224,7 +239,8 @@ NumberFilter.propTypes = {
|
||||
comparatorStyle: PropTypes.object,
|
||||
comparatorClassName: PropTypes.string,
|
||||
numberStyle: PropTypes.object,
|
||||
numberClassName: PropTypes.string
|
||||
numberClassName: PropTypes.string,
|
||||
getFilter: PropTypes.func
|
||||
};
|
||||
|
||||
NumberFilter.defaultProps = {
|
||||
|
||||
@ -25,9 +25,21 @@ class SelectFilter extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { column, onFilter, getFilter } = this.props;
|
||||
|
||||
const value = this.selectInput.value;
|
||||
if (value && value !== '') {
|
||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.SELECT);
|
||||
onFilter(column, FILTER_TYPE.SELECT)(value);
|
||||
}
|
||||
|
||||
// export onFilter function to allow users to access
|
||||
if (getFilter) {
|
||||
getFilter((filterVal) => {
|
||||
this.setState(() => ({ isSelected: filterVal !== '' }));
|
||||
this.selectInput.value = filterVal;
|
||||
|
||||
onFilter(column, FILTER_TYPE.SELECT)(filterVal);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +53,7 @@ class SelectFilter extends Component {
|
||||
if (needFilter) {
|
||||
const value = this.selectInput.value;
|
||||
if (value) {
|
||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.SELECT);
|
||||
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -64,19 +76,19 @@ class SelectFilter extends Component {
|
||||
const value = (this.props.defaultValue !== undefined) ? this.props.defaultValue : '';
|
||||
this.setState(() => ({ isSelected: value !== '' }));
|
||||
this.selectInput.value = value;
|
||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.SELECT);
|
||||
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
||||
}
|
||||
|
||||
applyFilter(value) {
|
||||
this.selectInput.value = value;
|
||||
this.setState(() => ({ isSelected: value !== '' }));
|
||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.SELECT);
|
||||
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
||||
}
|
||||
|
||||
filter(e) {
|
||||
const { value } = e.target;
|
||||
this.setState(() => ({ isSelected: value !== '' }));
|
||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.SELECT);
|
||||
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
||||
}
|
||||
|
||||
render() {
|
||||
@ -90,6 +102,7 @@ class SelectFilter extends Component {
|
||||
comparator,
|
||||
withoutEmptyOption,
|
||||
caseSensitive,
|
||||
getFilter,
|
||||
...rest
|
||||
} = this.props;
|
||||
|
||||
@ -121,7 +134,8 @@ SelectFilter.propTypes = {
|
||||
className: PropTypes.string,
|
||||
withoutEmptyOption: PropTypes.bool,
|
||||
defaultValue: PropTypes.any,
|
||||
caseSensitive: PropTypes.bool
|
||||
caseSensitive: PropTypes.bool,
|
||||
getFilter: PropTypes.func
|
||||
};
|
||||
|
||||
SelectFilter.defaultProps = {
|
||||
|
||||
@ -17,10 +17,21 @@ class TextFilter extends Component {
|
||||
value: props.defaultValue
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { onFilter, getFilter, column } = this.props;
|
||||
const defaultValue = this.input.value;
|
||||
|
||||
if (defaultValue) {
|
||||
this.props.onFilter(this.props.column, defaultValue, FILTER_TYPE.TEXT);
|
||||
onFilter(this.props.column, FILTER_TYPE.TEXT)(defaultValue);
|
||||
}
|
||||
|
||||
// export onFilter function to allow users to access
|
||||
if (getFilter) {
|
||||
getFilter((filterVal) => {
|
||||
this.setState(() => ({ value: filterVal }));
|
||||
onFilter(column, FILTER_TYPE.TEXT)(filterVal);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +51,7 @@ class TextFilter extends Component {
|
||||
const filterValue = e.target.value;
|
||||
this.setState(() => ({ value: filterValue }));
|
||||
this.timeout = setTimeout(() => {
|
||||
this.props.onFilter(this.props.column, filterValue, FILTER_TYPE.TEXT);
|
||||
this.props.onFilter(this.props.column, FILTER_TYPE.TEXT)(filterValue);
|
||||
}, this.props.delay);
|
||||
}
|
||||
|
||||
@ -53,12 +64,12 @@ class TextFilter extends Component {
|
||||
cleanFiltered() {
|
||||
const value = this.props.defaultValue;
|
||||
this.setState(() => ({ value }));
|
||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.TEXT);
|
||||
this.props.onFilter(this.props.column, FILTER_TYPE.TEXT)(value);
|
||||
}
|
||||
|
||||
applyFilter(filterText) {
|
||||
this.setState(() => ({ value: filterText }));
|
||||
this.props.onFilter(this.props.column, filterText, FILTER_TYPE.TEXT);
|
||||
this.props.onFilter(this.props.column, FILTER_TYPE.TEXT)(filterText);
|
||||
}
|
||||
|
||||
handleClick(e) {
|
||||
@ -77,8 +88,10 @@ class TextFilter extends Component {
|
||||
onFilter,
|
||||
caseSensitive,
|
||||
defaultValue,
|
||||
getFilter,
|
||||
...rest
|
||||
} = this.props;
|
||||
|
||||
// stopPropagation for onClick event is try to prevent sort was triggered.
|
||||
return (
|
||||
<input
|
||||
@ -105,7 +118,8 @@ TextFilter.propTypes = {
|
||||
placeholder: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
className: PropTypes.string,
|
||||
caseSensitive: PropTypes.bool
|
||||
caseSensitive: PropTypes.bool,
|
||||
getFilter: PropTypes.func
|
||||
};
|
||||
|
||||
TextFilter.defaultProps = {
|
||||
|
||||
@ -6,9 +6,13 @@ import { LIKE, EQ, NE, GT, GE, LT, LE } from './comparison';
|
||||
export const filterByText = _ => (
|
||||
data,
|
||||
dataField,
|
||||
{ filterVal = '', comparator = LIKE, caseSensitive },
|
||||
{ filterVal: userInput = '', comparator = LIKE, caseSensitive },
|
||||
customFilterValue
|
||||
) =>
|
||||
) => {
|
||||
// make sure filter value to be a string
|
||||
const filterVal = userInput.toString();
|
||||
|
||||
return (
|
||||
data.filter((row) => {
|
||||
let cell = _.get(row, dataField);
|
||||
if (customFilterValue) {
|
||||
@ -21,15 +25,18 @@ export const filterByText = _ => (
|
||||
if (caseSensitive) {
|
||||
return cellStr.includes(filterVal);
|
||||
}
|
||||
|
||||
return cellStr.toLocaleUpperCase().indexOf(filterVal.toLocaleUpperCase()) !== -1;
|
||||
});
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
export const filterByNumber = _ => (
|
||||
data,
|
||||
dataField,
|
||||
{ filterVal: { comparator, number } },
|
||||
customFilterValue
|
||||
) =>
|
||||
) => (
|
||||
data.filter((row) => {
|
||||
if (number === '' || !comparator) return true;
|
||||
let valid = true;
|
||||
@ -81,7 +88,8 @@ export const filterByNumber = _ => (
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
export const filterFactory = _ => (filterType) => {
|
||||
let filterFn;
|
||||
|
||||
@ -40,7 +40,15 @@ export default (Base, {
|
||||
}
|
||||
}
|
||||
|
||||
onFilter(column, filterVal, filterType) {
|
||||
/**
|
||||
* filter the table like below:
|
||||
* onFilter(column, filterType)(filterVal)
|
||||
* @param {Object} column
|
||||
* @param {String} filterType
|
||||
* @param {String} filterVal - user input for filtering.
|
||||
*/
|
||||
onFilter(column, filterType) {
|
||||
return (filterVal) => {
|
||||
const { store, columns } = this.props;
|
||||
const currFilters = Object.assign({}, this.state.currFilters);
|
||||
const { dataField, filter } = column;
|
||||
@ -55,6 +63,7 @@ export default (Base, {
|
||||
} = filter.props;
|
||||
currFilters[dataField] = { filterVal, filterType, comparator, caseSensitive };
|
||||
}
|
||||
|
||||
store.filters = currFilters;
|
||||
|
||||
if (this.isRemoteFiltering() || this.isRemotePagination()) {
|
||||
@ -67,6 +76,7 @@ export default (Base, {
|
||||
|
||||
store.filteredData = filters(store, columns, _)(currFilters);
|
||||
this.setState(() => ({ currFilters, isDataChanged: true }));
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@ -9,7 +9,11 @@ import * as Comparator from '../../src/comparison';
|
||||
|
||||
describe('Number Filter', () => {
|
||||
let wrapper;
|
||||
|
||||
// onFilter(x)(y) = filter result
|
||||
const onFilter = sinon.stub();
|
||||
const onFilterFirstReturn = sinon.stub();
|
||||
|
||||
const column = {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
@ -17,6 +21,9 @@ describe('Number Filter', () => {
|
||||
|
||||
afterEach(() => {
|
||||
onFilter.reset();
|
||||
onFilterFirstReturn.reset();
|
||||
|
||||
onFilter.returns(onFilterFirstReturn);
|
||||
});
|
||||
|
||||
describe('initialization', () => {
|
||||
@ -90,6 +97,36 @@ describe('Number Filter', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when props.getFilter is defined', () => {
|
||||
let programmaticallyFilter;
|
||||
|
||||
const comparator = Comparator.EQ;
|
||||
const number = 123;
|
||||
|
||||
const getFilter = (filter) => {
|
||||
programmaticallyFilter = filter;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = mount(
|
||||
<NumberFilter onFilter={ onFilter } column={ column } getFilter={ getFilter } />
|
||||
);
|
||||
|
||||
programmaticallyFilter({ comparator, number });
|
||||
});
|
||||
|
||||
it('should do onFilter correctly when exported function was executed', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.NUMBER)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith({ comparator, number })).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should setState correctly when exported function was executed', () => {
|
||||
expect(wrapper.state().isSelected).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when defaultValue.number and defaultValue.comparator props is defined', () => {
|
||||
const number = 203;
|
||||
const comparator = Comparator.EQ;
|
||||
@ -110,8 +147,9 @@ describe('Number Filter', () => {
|
||||
|
||||
it('should calling onFilter on componentDidMount', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(
|
||||
column, { number: `${number}`, comparator }, FILTER_TYPE.NUMBER)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.NUMBER)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith({ number: `${number}`, comparator })).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -9,19 +9,27 @@ import { FILTER_TYPE } from '../../src/const';
|
||||
describe('Select Filter', () => {
|
||||
let wrapper;
|
||||
let instance;
|
||||
|
||||
// onFilter(x)(y) = filter result
|
||||
const onFilter = sinon.stub();
|
||||
const onFilterFirstReturn = sinon.stub();
|
||||
|
||||
const column = {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quality'
|
||||
};
|
||||
|
||||
const options = {
|
||||
0: 'Bad',
|
||||
1: 'Good',
|
||||
2: 'Unknow'
|
||||
2: 'Unknown'
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
onFilter.reset();
|
||||
onFilterFirstReturn.reset();
|
||||
|
||||
onFilter.returns(onFilterFirstReturn);
|
||||
});
|
||||
|
||||
describe('initialization', () => {
|
||||
@ -83,11 +91,48 @@ describe('Select Filter', () => {
|
||||
|
||||
it('should calling onFilter on componentDidMount', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when props.getFilter is defined', () => {
|
||||
let programmaticallyFilter;
|
||||
|
||||
const filterValue = 'foo';
|
||||
|
||||
const getFilter = (filter) => {
|
||||
programmaticallyFilter = filter;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = mount(
|
||||
<SelectFilter
|
||||
onFilter={ onFilter }
|
||||
column={ column }
|
||||
options={ options }
|
||||
getFilter={ getFilter }
|
||||
/>
|
||||
);
|
||||
instance = wrapper.instance();
|
||||
|
||||
programmaticallyFilter(filterValue);
|
||||
});
|
||||
|
||||
it('should do onFilter correctly when exported function was executed', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(filterValue)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should setState correctly when exported function was executed', () => {
|
||||
expect(instance.state.isSelected).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when placeholder is defined', () => {
|
||||
const placeholder = 'test';
|
||||
beforeEach(() => {
|
||||
@ -170,8 +215,9 @@ describe('Select Filter', () => {
|
||||
|
||||
it('should update', () => {
|
||||
expect(onFilter.callCount).toBe(2);
|
||||
expect(onFilter.calledWith(
|
||||
column, instance.props.defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.callCount).toBe(2);
|
||||
expect(onFilterFirstReturn.calledWith(instance.props.defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -198,8 +244,9 @@ describe('Select Filter', () => {
|
||||
|
||||
it('should update', () => {
|
||||
expect(onFilter.callCount).toBe(2);
|
||||
expect(onFilter.calledWith(
|
||||
column, instance.props.defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.callCount).toBe(2);
|
||||
expect(onFilterFirstReturn.calledWith(instance.props.defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -226,7 +273,9 @@ describe('Select Filter', () => {
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.callCount).toBe(2);
|
||||
expect(onFilter.calledWith(column, defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.callCount).toBe(2);
|
||||
expect(onFilterFirstReturn.calledWith(defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -249,6 +298,7 @@ describe('Select Filter', () => {
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.callCount).toBe(1);
|
||||
expect(onFilterFirstReturn.callCount).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -268,8 +318,10 @@ describe('Select Filter', () => {
|
||||
});
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.callCount).toBe(1);
|
||||
expect(onFilter.calledWith(column, value, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(value)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -289,8 +341,10 @@ describe('Select Filter', () => {
|
||||
});
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.callCount).toBe(1);
|
||||
expect(onFilter.calledWith(column, event.target.value, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(event.target.value)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,7 +9,11 @@ jest.useFakeTimers();
|
||||
describe('Text Filter', () => {
|
||||
let wrapper;
|
||||
let instance;
|
||||
|
||||
// onFilter(x)(y) = filter result
|
||||
const onFilter = sinon.stub();
|
||||
const onFilterFirstReturn = sinon.stub();
|
||||
|
||||
const column = {
|
||||
dataField: 'price',
|
||||
text: 'Price'
|
||||
@ -17,6 +21,9 @@ describe('Text Filter', () => {
|
||||
|
||||
afterEach(() => {
|
||||
onFilter.reset();
|
||||
onFilterFirstReturn.reset();
|
||||
|
||||
onFilter.returns(onFilterFirstReturn);
|
||||
});
|
||||
|
||||
describe('initialization', () => {
|
||||
@ -58,7 +65,39 @@ describe('Text Filter', () => {
|
||||
|
||||
it('should calling onFilter on componentDidMount', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, defaultValue, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when props.getFilter is defined', () => {
|
||||
let programmaticallyFilter;
|
||||
|
||||
const filterValue = 'foo';
|
||||
|
||||
const getFilter = (filter) => {
|
||||
programmaticallyFilter = filter;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = mount(
|
||||
<TextFilter onFilter={ onFilter } column={ column } getFilter={ getFilter } />
|
||||
);
|
||||
instance = wrapper.instance();
|
||||
|
||||
programmaticallyFilter(filterValue);
|
||||
});
|
||||
|
||||
it('should do onFilter correctly when exported function was executed', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(filterValue)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should setState correctly when exported function was executed', () => {
|
||||
expect(instance.state.value).toEqual(filterValue);
|
||||
});
|
||||
});
|
||||
|
||||
@ -114,7 +153,9 @@ describe('Text Filter', () => {
|
||||
|
||||
it('should calling onFilter correctly when props.defaultValue is changed', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, nextDefaultValue, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(nextDefaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -133,8 +174,9 @@ describe('Text Filter', () => {
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(
|
||||
column, instance.props.defaultValue, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(instance.props.defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -154,7 +196,9 @@ describe('Text Filter', () => {
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, filterText, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(filterText)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -42,6 +42,19 @@ describe('filter', () => {
|
||||
filterFn = filters(store, columns, _);
|
||||
});
|
||||
|
||||
describe('when filter value is not a String', () => {
|
||||
it('should transform to string and do the filter', () => {
|
||||
currFilters.name = {
|
||||
filterVal: 3,
|
||||
filterType: FILTER_TYPE.TEXT
|
||||
};
|
||||
|
||||
const result = filterFn(currFilters);
|
||||
expect(result).toBeDefined();
|
||||
expect(result).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe(`when default comparator is ${LIKE}`, () => {
|
||||
it('should returning correct result', () => {
|
||||
currFilters.name = {
|
||||
|
||||
@ -167,14 +167,14 @@ describe('Wrapper', () => {
|
||||
|
||||
it('should setting store object correctly', () => {
|
||||
filterVals.forEach((filterVal) => {
|
||||
instance.onFilter(props.columns[1], filterVal, FILTER_TYPE.TEXT);
|
||||
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||
expect(props.store.filtering).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should setting state correctly', () => {
|
||||
filterVals.forEach((filterVal) => {
|
||||
instance.onFilter(props.columns[1], filterVal, FILTER_TYPE.TEXT);
|
||||
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||
expect(instance.state.isDataChanged).toBeTruthy();
|
||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(0);
|
||||
});
|
||||
@ -185,12 +185,12 @@ describe('Wrapper', () => {
|
||||
const filterVal = '3';
|
||||
|
||||
it('should setting store object correctly', () => {
|
||||
instance.onFilter(props.columns[1], filterVal, FILTER_TYPE.TEXT);
|
||||
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||
});
|
||||
|
||||
it('should setting state correctly', () => {
|
||||
instance.onFilter(props.columns[1], filterVal, FILTER_TYPE.TEXT);
|
||||
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||
expect(instance.state.isDataChanged).toBeTruthy();
|
||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
||||
});
|
||||
@ -203,7 +203,7 @@ describe('Wrapper', () => {
|
||||
props = createTableProps();
|
||||
props.remote = { filter: true };
|
||||
createFilterWrapper(props);
|
||||
instance.onFilter(props.columns[1], filterVal, FILTER_TYPE.TEXT);
|
||||
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||
});
|
||||
|
||||
it('should not setting store object correctly', () => {
|
||||
@ -222,27 +222,27 @@ describe('Wrapper', () => {
|
||||
|
||||
describe('combination', () => {
|
||||
it('should setting store object correctly', () => {
|
||||
instance.onFilter(props.columns[1], '3', FILTER_TYPE.TEXT);
|
||||
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)('3');
|
||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||
expect(instance.state.isDataChanged).toBeTruthy();
|
||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
||||
|
||||
instance.onFilter(props.columns[1], '2', FILTER_TYPE.TEXT);
|
||||
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)('2');
|
||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||
expect(instance.state.isDataChanged).toBeTruthy();
|
||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
||||
|
||||
instance.onFilter(props.columns[2], '2', FILTER_TYPE.TEXT);
|
||||
instance.onFilter(props.columns[2], FILTER_TYPE.TEXT)('2');
|
||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||
expect(instance.state.isDataChanged).toBeTruthy();
|
||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(2);
|
||||
|
||||
instance.onFilter(props.columns[2], '', FILTER_TYPE.TEXT);
|
||||
instance.onFilter(props.columns[2], FILTER_TYPE.TEXT)('');
|
||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||
expect(instance.state.isDataChanged).toBeTruthy();
|
||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
||||
|
||||
instance.onFilter(props.columns[1], '', FILTER_TYPE.TEXT);
|
||||
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)('');
|
||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||
expect(instance.state.isDataChanged).toBeTruthy();
|
||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(0);
|
||||
|
||||
@ -47,7 +47,7 @@ export default ExtendBase =>
|
||||
}
|
||||
if (selectable) {
|
||||
const key = _.get(row, keyField);
|
||||
onRowSelect(key, !selected, rowIndex);
|
||||
onRowSelect(key, !selected, rowIndex, e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ export default class SelectionCell extends Component {
|
||||
return nextProps.selected !== selected;
|
||||
}
|
||||
|
||||
handleClick() {
|
||||
handleClick(e) {
|
||||
const {
|
||||
mode: inputType,
|
||||
rowKey,
|
||||
@ -46,7 +46,7 @@ export default class SelectionCell extends Component {
|
||||
? true
|
||||
: !selected;
|
||||
|
||||
onRowSelect(rowKey, checked, rowIndex);
|
||||
onRowSelect(rowKey, checked, rowIndex, e);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@ -44,10 +44,10 @@ export default class SelectionHeaderCell extends Component {
|
||||
return nextProps.checkedStatus !== checkedStatus;
|
||||
}
|
||||
|
||||
handleCheckBoxClick() {
|
||||
handleCheckBoxClick(e) {
|
||||
const { onAllRowsSelect } = this.props;
|
||||
|
||||
onAllRowsSelect();
|
||||
onAllRowsSelect(e);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@ -41,7 +41,7 @@ export default Base =>
|
||||
* @param {String} rowKey - row key of what was selected.
|
||||
* @param {Boolean} checked - next checked status of input button.
|
||||
*/
|
||||
handleRowSelect(rowKey, checked, rowIndex) {
|
||||
handleRowSelect(rowKey, checked, rowIndex, e) {
|
||||
const { selectRow: { mode, onSelect }, store } = this.props;
|
||||
const { ROW_SELECT_SINGLE } = Const;
|
||||
|
||||
@ -59,7 +59,7 @@ export default Base =>
|
||||
|
||||
if (onSelect) {
|
||||
const row = getRowByRowId(store)(rowKey);
|
||||
onSelect(row, checked, rowIndex);
|
||||
onSelect(row, checked, rowIndex, e);
|
||||
}
|
||||
|
||||
this.setState(() => ({
|
||||
@ -68,18 +68,16 @@ export default Base =>
|
||||
}
|
||||
|
||||
/**
|
||||
* handle all rows selection on header cell by store.selected or given specific result.
|
||||
* @param {Boolean} option - customized result for all rows selection
|
||||
* handle all rows selection on header cell by store.selected
|
||||
*/
|
||||
handleAllRowsSelect(option) {
|
||||
handleAllRowsSelect(e) {
|
||||
const { store, selectRow: {
|
||||
onSelectAll,
|
||||
nonSelectable
|
||||
} } = this.props;
|
||||
const selected = isAnySelectedRow(store)(nonSelectable);
|
||||
|
||||
// set next status of all row selected by store.selected or customizing by user.
|
||||
const result = option || !selected;
|
||||
const result = !selected;
|
||||
|
||||
const currSelected = result ?
|
||||
selectableKeys(store)(nonSelectable) :
|
||||
@ -89,7 +87,7 @@ export default Base =>
|
||||
store.selected = currSelected;
|
||||
|
||||
if (onSelectAll) {
|
||||
onSelectAll(result, getSelectedRows(store));
|
||||
onSelectAll(result, getSelectedRows(store), e);
|
||||
}
|
||||
|
||||
this.setState(() => ({
|
||||
|
||||
@ -162,14 +162,6 @@ describe('RowSelectionWrapper', () => {
|
||||
wrapper.instance().handleAllRowsSelect();
|
||||
expect(wrapper.state('selectedRowKeys')).toEqual([]);
|
||||
});
|
||||
|
||||
it('call handleAllRowsSelect function with a bool args should setting correct state.selectedRowKeys', () => {
|
||||
wrapper.instance().handleAllRowsSelect(true);
|
||||
expect(wrapper.state('selectedRowKeys')).toEqual(expect.arrayContaining([firstSelectedRow, secondSelectedRow]));
|
||||
|
||||
wrapper.instance().handleAllRowsSelect(false);
|
||||
expect(wrapper.state('selectedRowKeys')).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when selectRow.onSelect is defined', () => {
|
||||
@ -219,13 +211,14 @@ describe('RowSelectionWrapper', () => {
|
||||
});
|
||||
|
||||
it('selectRow.onSelect callback should be called correctly when calling handleRowSelect function', () => {
|
||||
wrapper.instance().handleAllRowsSelect();
|
||||
const e = {};
|
||||
wrapper.instance().handleAllRowsSelect(e);
|
||||
expect(onSelectAllCallBack.callCount).toEqual(1);
|
||||
expect(onSelectAllCallBack.calledWith(true, data)).toBeTruthy();
|
||||
expect(onSelectAllCallBack.calledWith(true, data, e)).toBeTruthy();
|
||||
|
||||
wrapper.instance().handleAllRowsSelect();
|
||||
wrapper.instance().handleAllRowsSelect(e);
|
||||
expect(onSelectAllCallBack.callCount).toEqual(2);
|
||||
expect(onSelectAllCallBack.calledWith(false, [])).toBeTruthy();
|
||||
expect(onSelectAllCallBack.calledWith(false, [], e)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
import * as path from 'path';
|
||||
import webpack from 'webpack';
|
||||
|
||||
module.exports = {
|
||||
entry: {
|
||||
'react-bootstrap-table2/dist/react-bootstrap-table2': './packages/react-bootstrap-table2/index.js',
|
||||
'react-bootstrap-table2/dist/react-bootstrap-table2.min': './packages/react-bootstrap-table2/index.js',
|
||||
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor': './packages/react-bootstrap-table2-editor/index.js',
|
||||
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor.min': './packages/react-bootstrap-table2-editor/index.js',
|
||||
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter': './packages/react-bootstrap-table2-filter/index.js',
|
||||
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min': './packages/react-bootstrap-table2-filter/index.js',
|
||||
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay': './packages/react-bootstrap-table2-overlay/index.js',
|
||||
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay.min': './packages/react-bootstrap-table2-overlay/index.js',
|
||||
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator': './packages/react-bootstrap-table2-paginator/index.js',
|
||||
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator.min': './packages/react-bootstrap-table2-paginator/index.js'
|
||||
},
|
||||
devtool: 'source-map',
|
||||
output: {
|
||||
path: path.join(__dirname, 'packages'),
|
||||
filename: '[name].js',
|
||||
library: 'ReactBootstrapTable',
|
||||
libraryTarget: 'umd'
|
||||
},
|
||||
externals: [{
|
||||
'react': {
|
||||
root: 'React',
|
||||
commonjs2: 'react',
|
||||
commonjs: 'react',
|
||||
amd: 'react'
|
||||
}
|
||||
}, {
|
||||
'react-dom': {
|
||||
root: 'ReactDOM',
|
||||
commonjs2: 'react-dom',
|
||||
commonjs: 'react-dom',
|
||||
amd: 'react-dom'
|
||||
}
|
||||
}],
|
||||
module: {
|
||||
rules: [{
|
||||
enforce: 'pre',
|
||||
test: /\.js?$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'eslint-loader'
|
||||
}, {
|
||||
test: /\.js?$/,
|
||||
use: ['babel-loader'],
|
||||
exclude: /node_modules/
|
||||
}]
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify('production')
|
||||
}),
|
||||
new webpack.SourceMapDevToolPlugin(),
|
||||
new webpack.optimize.DedupePlugin(),
|
||||
new webpack.optimize.OccurrenceOrderPlugin(),
|
||||
new webpack.optimize.AggressiveMergingPlugin(),
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
include: /\.min\.js$/,
|
||||
compress: { warnings: false }
|
||||
})
|
||||
]
|
||||
};
|
||||
16
webpack/editor.umd.babel.js
Normal file
16
webpack/editor.umd.babel.js
Normal file
@ -0,0 +1,16 @@
|
||||
import * as path from 'path';
|
||||
import umdConfig from './webpack.umd.babel';
|
||||
|
||||
module.exports = {
|
||||
...umdConfig,
|
||||
entry: {
|
||||
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor': './packages/react-bootstrap-table2-editor/index.js',
|
||||
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor.min': './packages/react-bootstrap-table2-editor/index.js'
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, '../packages'),
|
||||
filename: '[name].js',
|
||||
library: 'ReactBootstrapTable2Editor',
|
||||
libraryTarget: 'umd'
|
||||
}
|
||||
};
|
||||
16
webpack/filter.umd.babel.js
Normal file
16
webpack/filter.umd.babel.js
Normal file
@ -0,0 +1,16 @@
|
||||
import * as path from 'path';
|
||||
import umdConfig from './webpack.umd.babel';
|
||||
|
||||
module.exports = {
|
||||
...umdConfig,
|
||||
entry: {
|
||||
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter': './packages/react-bootstrap-table2-filter/index.js',
|
||||
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min': './packages/react-bootstrap-table2-filter/index.js'
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, '../packages'),
|
||||
filename: '[name].js',
|
||||
library: 'ReactBootstrapTable2Filter',
|
||||
libraryTarget: 'umd'
|
||||
}
|
||||
};
|
||||
16
webpack/next.umd.babel.js
Normal file
16
webpack/next.umd.babel.js
Normal file
@ -0,0 +1,16 @@
|
||||
import * as path from 'path';
|
||||
import umdConfig from './webpack.umd.babel';
|
||||
|
||||
module.exports = {
|
||||
...umdConfig,
|
||||
entry: {
|
||||
'react-bootstrap-table2/dist/react-bootstrap-table-next': './packages/react-bootstrap-table2/index.js',
|
||||
'react-bootstrap-table2/dist/react-bootstrap-table-next.min': './packages/react-bootstrap-table2/index.js'
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, '../packages'),
|
||||
filename: '[name].js',
|
||||
library: 'ReactBootstrapTable2',
|
||||
libraryTarget: 'umd'
|
||||
}
|
||||
};
|
||||
16
webpack/overlay.umd.babel.js
Normal file
16
webpack/overlay.umd.babel.js
Normal file
@ -0,0 +1,16 @@
|
||||
import * as path from 'path';
|
||||
import umdConfig from './webpack.umd.babel';
|
||||
|
||||
module.exports = {
|
||||
...umdConfig,
|
||||
entry: {
|
||||
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay': './packages/react-bootstrap-table2-overlay/index.js',
|
||||
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay.min': './packages/react-bootstrap-table2-overlay/index.js'
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, '../packages'),
|
||||
filename: '[name].js',
|
||||
library: 'ReactBootstrapTable2Overlay',
|
||||
libraryTarget: 'umd'
|
||||
}
|
||||
};
|
||||
16
webpack/paginator.umd.babel.js
Normal file
16
webpack/paginator.umd.babel.js
Normal file
@ -0,0 +1,16 @@
|
||||
import * as path from 'path';
|
||||
import umdConfig from './webpack.umd.babel';
|
||||
|
||||
module.exports = {
|
||||
...umdConfig,
|
||||
entry: {
|
||||
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator': './packages/react-bootstrap-table2-paginator/index.js',
|
||||
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator.min': './packages/react-bootstrap-table2-paginator/index.js'
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, '../packages'),
|
||||
filename: '[name].js',
|
||||
library: 'ReactBootstrapTable2Paginator',
|
||||
libraryTarget: 'umd'
|
||||
}
|
||||
};
|
||||
45
webpack/webpack.umd.babel.js
Normal file
45
webpack/webpack.umd.babel.js
Normal file
@ -0,0 +1,45 @@
|
||||
import webpack from 'webpack';
|
||||
|
||||
module.exports = {
|
||||
devtool: 'source-map',
|
||||
externals: [{
|
||||
'react': {
|
||||
root: 'React',
|
||||
commonjs2: 'react',
|
||||
commonjs: 'react',
|
||||
amd: 'react'
|
||||
}
|
||||
}, {
|
||||
'react-dom': {
|
||||
root: 'ReactDOM',
|
||||
commonjs2: 'react-dom',
|
||||
commonjs: 'react-dom',
|
||||
amd: 'react-dom'
|
||||
}
|
||||
}],
|
||||
module: {
|
||||
rules: [{
|
||||
enforce: 'pre',
|
||||
test: /\.js?$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'eslint-loader'
|
||||
}, {
|
||||
test: /\.js?$/,
|
||||
use: ['babel-loader'],
|
||||
exclude: /node_modules/
|
||||
}]
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify('production')
|
||||
}),
|
||||
new webpack.SourceMapDevToolPlugin(),
|
||||
new webpack.optimize.DedupePlugin(),
|
||||
new webpack.optimize.OccurrenceOrderPlugin(),
|
||||
new webpack.optimize.AggressiveMergingPlugin(),
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
include: /\.min\.js$/,
|
||||
compress: { warnings: false }
|
||||
})
|
||||
]
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user