diff --git a/docs/migration.md b/docs/migration.md index 5385172..60edbd2 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -82,7 +82,7 @@ Please see [available filter configuration](https://react-bootstrap-table.github - [x] Text Filter - [x] Custom Text Filter - [x] Remote Filter -- [ ] Custom Filter Component +- [x] Custom Filter Component - [ ] Regex Filter - [x] Select Filter - [x] Custom Select Filter diff --git a/packages/react-bootstrap-table2-filter/README.md b/packages/react-bootstrap-table2-filter/README.md index dc9e621..0af54da 100644 --- a/packages/react-bootstrap-table2-filter/README.md +++ b/packages/react-bootstrap-table2-filter/README.md @@ -20,6 +20,7 @@ You can get all types of filters via import and these filters are a factory func * SelectFilter * NumberFilter * DateFilter +* CustomFilter * **Coming soon!** ## Add CSS @@ -189,4 +190,54 @@ const dateFilter = dateFilter({ }) // omit... -``` \ No newline at end of file +``` + +## Custom Filter + +```js +import filterFactory, { customFilter } from 'react-bootstrap-table2-filter'; + +const columns = [..., { + dataField: 'date', + text: 'Product Name', + filter: customFilter(), + filterRenderer: (onFilter, column) => ..... +}]; + + +``` + +In custom filter case, you are suppose to finish following two steps: +1. Call `customFilter` and pass to `column.filter` +2. Give `column.filterRenderer` as a callback function and return your custom filter element. + +### column.filterRenderer + +This function will pass two argument to you: +1. `onFilter`: call it to trigger filter when you need. +2. `column`: Just the column object! + +In the end, please remember to return your custom filter element! + +### customFilter + +`customFilter` function just same as `textFilter`, `selectFilter` etc, it is for customization reason. However, in the custom filter case, there's only one props is valid: `type` + + +```js +import filterFactory, { FILTER_TYPES } from 'react-bootstrap-table2-filter'; + +const customFilter = customFilter({ + type: FILTER_TYPES.NUMBER, // default is FILTER_TYPES.TEXT +}) +``` + +`type` is a way to ask `react-bootstrap-table` to filter you data as number, select, date or normal text. + +### FILTER_TYPES + +Following properties is valid in `FILTER_TYPES`: +* TEXT +* SELECT +* NUMBER +* DATE \ No newline at end of file