From c6ea19fe8a7c22344592a67fc60b61390ff85c62 Mon Sep 17 00:00:00 2001 From: AllenFang Date: Sat, 10 Nov 2018 15:53:20 +0800 Subject: [PATCH] enhance for #649 --- .../select-filter-preserve-option-order.js | 16 ++++++++-------- packages/react-bootstrap-table2-filter/README.md | 8 ++++---- .../src/components/select.js | 5 ++++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/react-bootstrap-table2-example/examples/column-filter/select-filter-preserve-option-order.js b/packages/react-bootstrap-table2-example/examples/column-filter/select-filter-preserve-option-order.js index f7a0fca..0f92088 100644 --- a/packages/react-bootstrap-table2-example/examples/column-filter/select-filter-preserve-option-order.js +++ b/packages/react-bootstrap-table2-example/examples/column-filter/select-filter-preserve-option-order.js @@ -8,9 +8,9 @@ import { productsQualityGenerator } from 'utils/common'; const products = productsQualityGenerator(6); const selectOptions = [ - { label: 0, value: 'good' }, - { label: 1, value: 'Bad' }, - { label: 2, value: 'unknown' } + { value: 0, label: 'good' }, + { value: 1, label: 'Bad' }, + { value: 2, label: 'unknown' } ]; const columns = [{ @@ -22,7 +22,7 @@ const columns = [{ }, { dataField: 'quality', text: 'Product Quailty', - formatter: cell => selectOptions.find(opt => opt.label === cell).value, + formatter: cell => selectOptions.find(opt => opt.value === cell).label, filter: selectFilter({ options: selectOptions }) @@ -33,9 +33,9 @@ import BootstrapTable from 'react-bootstrap-table-next'; import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter'; const selectOptions = [ - { label: 0, value: 'good' }, - { label: 1, value: 'Bad' }, - { label: 2, value: 'unknown' } + { value: 0, label: 'good' }, + { value: 1, label: 'Bad' }, + { value: 2, label: 'unknown' } ]; const columns = [{ @@ -47,7 +47,7 @@ const columns = [{ }, { dataField: 'quality', text: 'Product Quailty', - formatter: cell => selectOptions.find(opt => opt.label === cell).value, + formatter: cell => selectOptions.find(opt => opt.value === cell).label, filter: selectFilter({ options: selectOptions }) diff --git a/packages/react-bootstrap-table2-filter/README.md b/packages/react-bootstrap-table2-filter/README.md index f73b962..b38007e 100644 --- a/packages/react-bootstrap-table2-filter/README.md +++ b/packages/react-bootstrap-table2-filter/README.md @@ -119,15 +119,15 @@ const qualityFilter = selectFilter({ ```js const selectOptions = [ - { label: 0, value: 'good' }, - { label: 1, value: 'Bad' }, - { label: 2, value: 'unknown' } + { value: 0, label: 'good' }, + { value: 1, label: 'Bad' }, + { value: 2, label: 'unknown' } ]; const columns = [ ..., { dataField: 'quality', text: 'Product Quailty', - formatter: cell => selectOptions.find(opt => opt.label === cell).value, + formatter: cell => selectOptions.find(opt => opt.value === cell).label, filter: selectFilter({ options: selectOptions }) diff --git a/packages/react-bootstrap-table2-filter/src/components/select.js b/packages/react-bootstrap-table2-filter/src/components/select.js index 09ec766..973bdb3 100644 --- a/packages/react-bootstrap-table2-filter/src/components/select.js +++ b/packages/react-bootstrap-table2-filter/src/components/select.js @@ -9,7 +9,10 @@ import { FILTER_TYPE } from '../const'; function optionsEquals(currOpts, prevOpts) { if (Array.isArray(currOpts)) { for (let i = 0; i < currOpts.length; i += 1) { - if (currOpts[i].label !== prevOpts[i].label) { + if ( + currOpts[i].value !== prevOpts[i].value || + currOpts[i].label !== prevOpts[i].label + ) { return false; } }