reactive-table icon indicating copy to clipboard operation
reactive-table copied to clipboard

Unable to filter on negative numbers

Open cormip opened this issue 8 years ago • 6 comments

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'
                }
            ]
        };
    }

cormip avatar May 29 '17 16:05 cormip

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.

aslagle avatar May 31 '17 03:05 aslagle

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...

cormip avatar May 31 '17 05:05 cormip

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).

aslagle avatar May 31 '17 12:05 aslagle

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.

cormip avatar May 31 '17 13:05 cormip

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

aslagle avatar Jun 01 '17 02:06 aslagle

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

cormip avatar Jun 01 '17 03:06 cormip