aslagle / reactive-table

A reactive table designed for Meteor
https://atmospherejs.com/aslagle/reactive-table
Other
328 stars 138 forks source link

Unable to filter on negative numbers #464

Open cormip opened 7 years ago

cormip commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

cormip commented 7 years ago

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