diff --git a/docs/columns.md b/docs/columns.md index 6d77335a5..5636c26ac 100644 --- a/docs/columns.md +++ b/docs/columns.md @@ -594,6 +594,7 @@ This prop also accept a function: * `column` * `columnIndex` +* `props`: It's an object and contain `text` property only. ## column.footerClasses - [String | Function] It's similar to [`column.classes`](#classes), `footerClasses` is available to have customized class on table footer column: diff --git a/packages/react-bootstrap-table2-example/examples/column-filter/clear-all-filters.js b/packages/react-bootstrap-table2-example/examples/column-filter/clear-all-filters.js index 3e2a25bfa..c15f560a8 100644 --- a/packages/react-bootstrap-table2-example/examples/column-filter/clear-all-filters.js +++ b/packages/react-bootstrap-table2-example/examples/column-filter/clear-all-filters.js @@ -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 = [{ @@ -19,7 +26,19 @@ 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', @@ -27,7 +46,8 @@ const columns = [{ filter: textFilter({ getFilter: (filter) => { priceFilter = filter; - } + }, + onFilter: filterVal => console.log(`Filter Price: ${filterVal}`) }) }, { dataField: 'inStockDate', @@ -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(); }; diff --git a/packages/react-bootstrap-table2-example/examples/column-filter/text-filter.js b/packages/react-bootstrap-table2-example/examples/column-filter/text-filter.js index c3789be40..58dc30828 100644 --- a/packages/react-bootstrap-table2-example/examples/column-filter/text-filter.js +++ b/packages/react-bootstrap-table2-example/examples/column-filter/text-filter.js @@ -14,7 +14,9 @@ const columns = [{ dataField: 'name', text: 'Product Name', footer: 'hello', - filter: textFilter() + filter: textFilter({ + id: 'identify' + }) }, { dataField: 'price', text: 'Product Price', @@ -54,7 +56,6 @@ export default () => ( data={ products } columns={ columns } filter={ filterFactory() } - filterPosition="bottom" selectRow={ selectRow } /> { sourceCode } diff --git a/packages/react-bootstrap-table2-example/examples/footer/column-format-table.js b/packages/react-bootstrap-table2-example/examples/footer/column-format-table.js index 26fbbc08b..ccd85bfd7 100644 --- a/packages/react-bootstrap-table2-example/examples/footer/column-format-table.js +++ b/packages/react-bootstrap-table2-example/examples/footer/column-format-table.js @@ -7,7 +7,7 @@ import { productsGenerator } from 'utils/common'; const products = productsGenerator(); -function priceFormatter(column, colIndex) { +function priceFormatter(column, colIndex, { text }) { return (
$$ {column.text} $$ @@ -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 (
$$ { column.text } $$
); diff --git a/packages/react-bootstrap-table2-example/src/utils/common.js b/packages/react-bootstrap-table2-example/src/utils/common.js index 5592779d7..131e30877 100644 --- a/packages/react-bootstrap-table2-example/src/utils/common.js +++ b/packages/react-bootstrap-table2-example/src/utils/common.js @@ -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())) })); diff --git a/packages/react-bootstrap-table2-filter/README.md b/packages/react-bootstrap-table2-filter/README.md index 78720441a..7d83e1fb7 100644 --- a/packages/react-bootstrap-table2-filter/README.md +++ b/packages/react-bootstrap-table2-filter/README.md @@ -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... @@ -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... @@ -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... @@ -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... @@ -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... diff --git a/packages/react-bootstrap-table2-filter/src/components/date.js b/packages/react-bootstrap-table2-filter/src/components/date.js index 3d8ff4536..54bb761ea 100644 --- a/packages/react-bootstrap-table2-filter/src/components/date.js +++ b/packages/react-bootstrap-table2-filter/src/components/date.js @@ -128,8 +128,9 @@ class DateFilter extends Component { render() { const { + id, placeholder, - column: { text }, + column: { dataField, text }, style, comparatorStyle, dateStyle, @@ -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 (
e.stopPropagation() } @@ -146,12 +150,12 @@ class DateFilter extends Component { > -