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

Filter does not work in all cases

Open gabrielhpugliese opened this issue 11 years ago • 16 comments
trafficstars

Check the demo and try to input "✘" or "partial" on filter, it is strange. EDIT: It filters everything - I'm supposing it's because you return html on these tds?

gabrielhpugliese avatar Mar 14 '14 19:03 gabrielhpugliese

Hmm just read the source and you search on all fields that are on mongo. So, virtual columns can't be filtered, right?

gabrielhpugliese avatar Mar 14 '14 19:03 gabrielhpugliese

That's correct, I made sorting use the virtual columns but forgot do the same for filtering. It shouldn't be too hard though. Thanks for noticing this.

aslagle avatar Mar 14 '14 20:03 aslagle

I've been thinking on a solution and I probably it's easier doing a transform or using a package like https://github.com/dburles/meteor-collection-helpers instead creating the virtual columns in this package. What do you think?

gabrielhpugliese avatar Mar 17 '14 10:03 gabrielhpugliese

Interesting, I hadn't seen that package. It looks like it could be useful but I don't see how it would help with filtering specifically. How are you thinking it would work?

aslagle avatar Mar 17 '14 15:03 aslagle

It's working for me now with collection-helpers with dburles help: https://github.com/dburles/meteor-collection-helpers/issues/5#issuecomment-38373684 But sorting the column does not work =/

I do not need the fn to create the virtual column anymore :)

gabrielhpugliese avatar Mar 24 '14 14:03 gabrielhpugliese

You'd need to change the code in sortedRows to fix the sorting, but it's not obvious how to do it. I'm using the presence of fn to decide how to sort, and that happens before getting the data so it wouldn't be possible to check for functions at that point.

I'm not sure but I think it might be easier to just implement filtering on virtual columns.

aslagle avatar Mar 24 '14 17:03 aslagle

The reason I picked collection-helpers is because I didn't have to change your filter query at all. When you do collection.find(filterQuery) it's like the virtual column exists in the doc, but it actually does not, it's emulated it with the package transformation.

I think it was the clearest solution.

gabrielhpugliese avatar Mar 24 '14 17:03 gabrielhpugliese

That is nice :)

So collection-helpers works in the filter query but not the sort query? I wonder how hard it would be to modify collection-helpers so the transforms would work with sorting...

aslagle avatar Mar 24 '14 17:03 aslagle

I haven't seen the sorting code yet, but I will soon :)

gabrielhpugliese avatar Mar 24 '14 18:03 gabrielhpugliese

hi guys, @gabrielhpugliese i did what you did here dburles/meteor-collection-helpers#5 (comment) but still i cant figure this out...i still cant filter on virtual columns.. how did you make this work?

kmligue avatar Jul 31 '14 02:07 kmligue

That was a long time ago. Idk if it works with the current version, but that's the code: https://github.com/gabrielhpugliese/reactive-table/blob/076e8e2a3ef7f1900e8dbb1e289ee875b072230d/lib/reactive_table.js#L142-L158

If you want to try the whole thing togheter, it's the filter branch :)

Gabriel Pugliese CodersTV.com @coderstv

On Wed, Jul 30, 2014 at 11:11 PM, kelvin martin ligue < [email protected]> wrote:

hi guys, @gabrielhpugliese https://github.com/gabrielhpugliese i did what you did here dburles/meteor-collection-helpers#5 https://github.com/dburles/meteor-collection-helpers/issues/5 (comment) but still i cant figure this out...i still cant filter on virtual columns.. how did you make this work?

— Reply to this email directly or view it on GitHub https://github.com/ecohealthalliance/reactive-table/issues/44#issuecomment-50705158 .

gabrielhpugliese avatar Jul 31 '14 02:07 gabrielhpugliese

@gabrielhpugliese @aslagle it's not in the filter branch anymore I am trying to search on a virtual field that's connected with collection-helpers, or am I doing something wrong ?

        {
          key: 'userID'
          label: 'user'
          fn: (value, object) ->
            # here the getFullName is a collection helper on current collection
            # sorting works fine / filtering doesn't
            return object.getFullname()
        }

This is taken from documentation -

By default, fields that use fn will be sorted by the result of this function. If you want to sort by the field's original value instead (for example, if you are making a date human-readable), set sortByValue to true on the field object.

Sorting is ok, what about filtering ?

tagrudev avatar Feb 24 '15 12:02 tagrudev

@tagrudev I've meant it's in filter branch of my fork: https://github.com/gabrielhpugliese/reactive-table/tree/filter

gabrielhpugliese avatar Feb 24 '15 13:02 gabrielhpugliese

@gabrielhpugliese hmm had some problems running that with meteor 1.0 but after I did it is not filtering by the virtual field :) either

tagrudev avatar Feb 24 '15 14:02 tagrudev

Any ETA on when filtering will work on fn fields?

MichelFloyd avatar Mar 10 '15 23:03 MichelFloyd

I worked around not being able to filter virtual columns by using a client-side table filter library called List.js (https://listjs.com)

graemian avatar Jul 01 '19 20:07 graemian