question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OnFilter change options of other filters

See original GitHub issue

Hi I am using the react-bootstrap-table to display some information in a nice table structure. However I am running into the issue that the filter options for the select filter won’t update. So I was wondering if there is an easy way of having the options default to the values that are currently available in the table for that column. I am currently getting the categories by creating a set of each relevant category using this.state.data, which however won’t update when filtering by any category and thus the options in each select filter always stay the same.

<BootstrapTable keyField='id' data={this.state.data} columns={columns} filter={filterFactory()} resize={{extra: 80}} headerClasses='bootstrap-table-header' striped hover condense />

where columns is something like this:

const columns = [
    { dataField: 'category_1',
      text: 'Category_1',
      headerFormatter: this.headerFormatter,
      sort: true,
      filter: selectFilter({
        placeholder: 'Category 1...',
        options: this.getCategory1()
      })
    },
    { dataField: 'category_2',
      text: 'category_2',
      headerFormatter: this.headerFormatter,
      sort: true,
      filter: selectFilter({
        placeholder: 'Category 2...',
        options: this.getCategory2()
      })
    },
    { dataField: 'category_3',
      text: 'category_3',
      headerFormatter: this.headerFormatter,
      sort: true,
      filter: selectFilter({
        placeholder: 'Category 3...',
        options: this.getCategory3()
      })
    }
]

So is there an easy way of having the options default to the different values in the dataFields and if not, how can I access the filtered data that is currently displayed and use those as base for the options in those filters.

Appreciate your help.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
remoroethlisbergercommented, Feb 20, 2020

I actually found a work around. However, I am still curious why the above happens when following your guidelines… Did something change?

Also more general question: Is the onFilter function not called if I pick the “all value” / “placeholder” value? I think I need that in order to reset the options.

Or if anyone has a better idea, please let me know how I can achieve the dynamic options for select filters.

Keep up the great work!

Cheers, Remo

1reaction
remoroethlisbergercommented, Oct 2, 2019

This was very helpful, as I wasn’t aware of the exposed API… So I did what you suggested and it works just fine. Thanks a lot Allen!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Datatables multi-select Dropdown Filter Update on filter change
What i am trying to do in above code is to add dropdown filter code in the callback of datatable function. So that...
Read more >
Solved: How to filter the options for another filter (mult...
So basically: Filter 1 to select the field I want to filter on, Filter 2 shows the values of the selected field to...
Read more >
Change labels on Filter Options from Applicant List page
This article explains how to change the label fields on Filter Options from Applicant List page.
Read more >
How to change the default filter on filter widget - ServiceNow
Once you create the filter and Run, there is an option to 'Set as default filter' which you can set it. Please find...
Read more >
Creating Dynamic Titles Based on Filters | Tableau Software
How to create dynamic titles that change based on filter selections. Environment. Tableau Desktop. Answer. CLICK TO EXPAND STEPS. Option 1 - All ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found