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

Unable to filter on negative numbers #464

Open
cormip opened this issue May 29, 2017 · 6 comments
Open

Unable to filter on negative numbers #464

cormip opened this issue May 29, 2017 · 6 comments

Comments

@cormip
Copy link

cormip commented May 29, 2017

I have a simple table where one of the columns contains signed integers (statusCode in example below). I can only filter the rows by those integers when the integer is positive. Entering "-999" (one of the unfiltered values) results in 0 records found.

I am NOT using regex searches.

Template:
{{> reactiveTable collection=failingResources settings=settings}}

Helper:

settings: function () {
        return {
            showFilter: true,
            enableRegex: false,
            fields: [
                {
                    label: 'ID',
                    key: '_id'
                },{
                    label: 'URL',
                    key: 'destUrl'
                },{
                    label: 'Status',
                    key: 'statusCode'
                }
            ]
        };
    }
@aslagle
Copy link
Owner

aslagle commented May 31, 2017

That's interesting, I don't think I ever considered that case.

I don't have time to test this right now, but it's possible changing the regex on this line to /^-?\d+$/ would fix it.

@cormip
Copy link
Author

cormip commented May 31, 2017

I installed a local copy of your package and edited that line, but it still does not work.

Once that minus sign is typed, the following conditional (line 102) never evaluates as true:

if (numberRegExp.test(filterWord)) {
   var numberQuery = {};
   numberQuery[field] = parseInt(filterWord, 10);
   filterQueryList.push(numberQuery);
} 

In fact, entering -999 has filterWord evaluate to "\-999" which is why it's always false...

@aslagle
Copy link
Owner

aslagle commented May 31, 2017

Thanks for trying that - it's escaping the dash so it won't be evaluated as a regex. /^(\\-)?-?\d+$/ will match with or without the escaping, but the parseInt call won't work either. You'd have to remove the backslash - parseInt(filterWord.replace("\\", ""), 10).

@cormip
Copy link
Author

cormip commented May 31, 2017

It seems like rather than escaping the dash than removing it later, you should instead determine earlier if the string is a number or not: if (!isNaN(filterWord)) {. You might also want to consider if floats (e.g. 2.1) would cause problems or not as well.

@aslagle
Copy link
Owner

aslagle commented Jun 1, 2017

You're right, that would be better. If you have it working locally, feel free to open a pull request.

@cormip
Copy link
Author

cormip commented Jun 1, 2017

Unfortunately, I don't have the time myself to work out all the details.

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

No branches or pull requests

2 participants