React-table: How to call default filter method from child element

Created on 10 May 2017  Â·  3Comments  Â·  Source: tannerlinsley/react-table

I would like to have a single filter input that filters on all columns with filtering enabled.
I am having trouble firing an event that triggers filtering in the table. Ideally, I'd like to be able to add an onChange call to my input that sends the right data to the table's default onFilterChange method.

So far, I've tried a few things, but this is the closest to what I'd want, though it doesn't work:

<ReactTable
      data={this.state.savedSearches}
      columns={columns}
      showFilters={true}
      defaultFilterMethod={(filter, row) => 
            (row[filter.id].toUpperCase().includes(filter.value.toUpperCase()))}
>
      {(state, makeTable, instance) => {
            return (
                  <div>
                        <div>
                              <label>Search:</label>
                              <input type="text" onChange={(e) => {
                    state.onFilteringChange(state.columns[3], e.target.value)
                }}/>
                        </div>
                        {makeTable()}
                  </div>
            )
      }}
</ReactTable>

I can't seem to find a way to do this.

Most helpful comment

This is now possible in the latest version. Simply build your own filter model using the filtered prop like so:

filtered={[
  {id: 'columnID', value: 'myFilterValue'},
  {id: 'otherColumnID', value: 'myOtherFilterValue'}
]}

All 3 comments

In the next major version, filters will be a fully controllable prop.
Would this help?

On Wed, May 10, 2017 at 10:20 AM Missy Williams notifications@github.com
wrote:

I would like to have a single filter input that filters on all columns
with filtering enabled.
I am having trouble firing an event that triggers filtering in the table.
Ideally, I'd like to be able to add an onChange call to my input that sends
the right data to the table's default onFilterChange method.

So far, I've tried a few things, but this is the closest to what I'd want,
though it doesn't work:

data={this.state.savedSearches}
columns={columns}
showFilters={true}
defaultFilterMethod={(filter, row) =>
(row[filter.id].toUpperCase().includes(filter.value.toUpperCase()))}
>
{(state, makeTable, instance) => {
return (




state.onFilteringChange(state.columns[3], e.target.value)
}}/>

{makeTable()}

)
}}

I can't seem to find a way to do this.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/tannerlinsley/react-table/issues/260, or mute the
thread
https://github.com/notifications/unsubscribe-auth/AFUmCe2NcPOfVLpqWADtcolhmobamiOrks5r4ePNgaJpZM4NW55w
.

It will definitely help if I can hook into the filtering of the main component.

This is now possible in the latest version. Simply build your own filter model using the filtered prop like so:

filtered={[
  {id: 'columnID', value: 'myFilterValue'},
  {id: 'otherColumnID', value: 'myOtherFilterValue'}
]}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

pasichnyk picture pasichnyk  Â·  3Comments

dilipsundarraj1 picture dilipsundarraj1  Â·  3Comments

krishna-shenll picture krishna-shenll  Â·  3Comments

bdkersey picture bdkersey  Â·  3Comments

DaveyEdwards picture DaveyEdwards  Â·  3Comments