table icon indicating copy to clipboard operation
table copied to clipboard

filterMethod does not return true with < and === operators

Open Omortis opened this issue 8 years ago • 5 comments

What version of React-Table are you using?

[email protected] [email protected]

What bug are you experiencing, or what feature are you proposing?

I am providing an interface that allows the user to select their filter type. Simple comparisons: >, < and =. Greater than works fine, but '<' and '===' refuse to return true, even if the comparison in the javascript console returns true. My filterMethod() code:

          this.props.rawData.data.sigmaps[lru].forEach((signal) => {
            headerArray.push({
              Header  : signal,
              accessor: signal,
              filterMethod: (filter, row) => {
                switch (this.props.rawData.filters[lru][signal]) {
                  case 'gt':
                    return row[filter.id] > filter.value
                  case 'eq':
                    return row[filter.id] === filter.value
                  case 'lt':
                    return row[filter.id] < filter.value
                  default:
                    return row[filter.id] > filter.value
                }
              },

The server side is returning JSON with the data correctly formatted (meaning numbers are numeric and strings are strings - I am mainly concerned with the numbers and have a different plan for strings going forward).

The code above is applied as a prop to <ReactTable /> and otherwise the table loads and operates fine.

Am I missing something simple?

Use (...) to reproduce the issue.

Any numeric data can be used. Hard to share, these are 80k+ line tables.

Thanks in advance for any suggestions. Note that react-table seems to work well with large data sets.

JB

Omortis avatar Jan 04 '18 15:01 Omortis

Hard to do without being able to play with the code. No-one expects the whole code to be available but a cut-down version of it on codesandbox would make this much easier....

The accessor looks wrong - but that is probably due to not being able to see everything.

Also - if you are putting that much logic into a direct prop on ReactTable it will probably make it hard to test.

If you aren't able to share a sandbox demonstrating the problem, all I can really suggest is that you liberally spread console.log statements through your code and check everything - even expand your switch into blocks that assign a variable that you can test the value of before returning it.

Finally, reading your description it sounds like it is more of a Javascript problem than an issue with ReactTable. It can only be data or logic related as to why one operator works and one doesn't.

gary-menzel avatar Jan 04 '18 21:01 gary-menzel

You are correct. I will try to strip it down to its bare essentials and post on codesandbox if I can't sort it out. Thanks! Will close if I sort it out.

Omortis avatar Jan 05 '18 11:01 Omortis

@gary-menzel : I have created a version of this component without redux and with a tiny data set at:

https://codesandbox.io/s/3y28mjp866

I stripped out all of the control logic but left some of the buttons in so you can see what's going on. Without the console logs it's quite performant with 10s of 1000s of lines. With them in filterMethod it's unusable as expected....

Note that codesandbox is not handling my custom bootstrap correctly but that's not important. Also note that I've written 1000s of lines of react/redux code but zero lines w/o redux until this morning, in case my state format is odd...

To pick <, = or > set filter = 'lt', 'eq' or 'gt' in initialState.js.

In the sandbox above, the 'less than' stanza actually works (it does not in my main module) but the 'equals' stanza still does not so I thought I'd post it just in case they are related. The component's guts are in DataView.js.

Thanks for the help!

JB

Omortis avatar Jan 05 '18 13:01 Omortis

I removed my last comment. Apparently, according to javascript,

23 > null = true 23 < null = false

With such large data sets (and a lot of null/empties) the "<" condition was filtering, but leaving behind the empty fields. Apparently I need to manually deal with null entries...

Omortis avatar Jan 05 '18 16:01 Omortis

Edit: yes, the null/None values are making a mess of things. Thanks for the feedback and help!

Omortis avatar Jan 05 '18 16:01 Omortis