Skip to content
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

filterFormatted not working as expected #589

Closed
rvaldeolmillos opened this issue Jul 27, 2016 · 10 comments
Closed

filterFormatted not working as expected #589

rvaldeolmillos opened this issue Jul 27, 2016 · 10 comments
Labels

Comments

@rvaldeolmillos
Copy link

Hi,
When using a column filter (tried with a SelectFilter) and the property fileFormatted is set to true on column, the filtering is not working properly.
Inspecting the code it seems that the targetVal is converted to lowerCase, but not filterVal, therefore there is no match if value has a capital letter.
Version: 2.3.9

Somewhere in your code:

default:
  {
    if (filterObj[key].type === _Const2['default'].FILTER_TYPE.SELECT && filterFormatted && filterFormatted && format) {
      filterVal = format(filterVal, row, formatExtraData);
    }
    valid = _this4.filterText(targetVal, filterVal);
    break;
  }

where filterText function is defined as:

function filterText(targetVal, filterVal) {
      if (targetVal.toString().toLowerCase().indexOf(filterVal) === -1) {
             return false;
       }
      return true;
}

Regards.

@rvaldeolmillos
Copy link
Author

An obviously solution would be converting the filter value obtained from format() function to lowercase:

if (filterObj[key].type === _Const2['default'].FILTER_TYPE.SELECT && filterFormatted && format) {
                filterVal = format(filterVal, row, formatExtraData)**.toString().toLowerCase()**;
}
valid = _this4.filterText(targetVal, filterVal);

@AllenFang
Copy link
Owner

@rvaldeolmillos sorry for lately reply, busy on work. I'll check this out. BTW, could you please show me an example for reproducing this issue? thanks :)

@rvaldeolmillos
Copy link
Author

rvaldeolmillos commented Aug 3, 2016

OK, here goes a basic example to reproduce the issue. Notice the capital in "Bad".
Select Bad in the filter and no row is matched. The search instead works fine.

import React from 'react';
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';

const products = [];

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

function addProducts(quantity) {
  const startId = products.length;
  for (let i = 0; i < quantity; i++) {
    const id = startId + i;
    products.push({
      id: id,
      name: 'Item name ' + id,
      quality: i % 3
    });
  }
}

addProducts(5);

function enumFormatter(cell, row, enumObject) {
  return enumObject[cell];
}

export default class SelectFilter extends React.Component {
  render() {
    return (
      <BootstrapTable data={ products } search={ true }>
        <TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
        <TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
        <TableHeaderColumn dataField='quality' filterFormatted={ true } dataFormat={ enumFormatter } formatExtraData={ qualityType } filter={ { type: 'SelectFilter', options: qualityType } }>
           Product Quality
        </TableHeaderColumn>
      </BootstrapTable>
    );
  }
}

@rvaldeolmillos
Copy link
Author

example

@AllenFang
Copy link
Owner

@rvaldeolmillos, thanks. I'll check this out.

@AllenFang
Copy link
Owner

@rvaldeolmillos, fixed on newest version.

@rvaldeolmillos
Copy link
Author

Hi @AllenFang, I've updated to version 2.5.0 but I still don't get it right ?

@AllenFang
Copy link
Owner

HI @rvaldeolmillos, are you sure? I cant reproduce this issue by your example. could you please confirm?

@rvaldeolmillos
Copy link
Author

Hi @AllenFang,

Checked with master branch and it's still failing...
I took the example from your own example /examples/js/column-filter/select-filter.js, just turning a capital letter in product qualities - the search flag is not important-, so it should be really easy to reproduce the problem.

@AllenFang AllenFang added the bug label Sep 5, 2016
@AllenFang AllenFang reopened this Sep 5, 2016
AllenFang added a commit that referenced this issue Sep 7, 2016
@AllenFang
Copy link
Owner

@rvaldeolmillos, Fixed on v2.5.2. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants