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.

Feature Request: Allow for sorting options in filterOptions prop

See original GitHub issue

In v1 overriding the standard filterOptions meant that you could return the options in a completely different order based on the search, whereas the new filterOption is only giving us the option to specify if that option should be shown or not.

I think that having some way of ordering the results is useful in lots of cases. Here’s one with some dummy data. Let’s suppose that my options is a long list of names and we expect that someone will probably start typing the person’s first name in order to get to that person as quickly as possible, but they might also only know a surname.

If we have the following names at the start of the options, "Alexa Nabil", "Alexandra Bilani", "Bill Ward" and the user starts typing "Bi" then currently the default behaviour of react-select is to show the options in their original, alphabetical order, but I’d suggest that "Bill Ward", "Alexandra Bilani", "Alexa Nabil" makes more sense once there’s the user input. That’s possible with filterOptions because you can sort the options at the same time as filtering them, but v2 leaves me without a way of doing this.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:25
  • Comments:9

github_iconTop GitHub Comments

6reactions
jossmaccommented, Jul 4, 2018

It sounds like we need a companion function for filterOptionsortOptions, with the shape of:

(OptionType, OptionType) => 0 | -1 | 1
5reactions
nenostracommented, Jun 13, 2018

Meanwhile i had to do something like this:

class CustomIput extends Component {

  constructor(props) {
    super(props);
    this.state = {
      dynamicOptions: [],
    };
  }

  handleInputChange = (value, { action }) => {
    if (action === 'input-change') {

      // custom logic like sorting or slicing the options array.

      this.setState({ dynamicOptions });
    }
  }

  render() {
    return (
        <Select
          options={this.state.dynamicOptions}
          onInputChange={this.handleInputChange}
          filterOption={() => true}
        />
    );
  }
}

Hope it helps someone

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Request: Allow for sorting options in filterOptions prop
In v1 overriding the standard filterOptions meant that you could return the options in a completely different order based on the search, whereas...
Read more >
Query options overview - OData | Microsoft Learn
A query option is basically requesting that a service perform a set of transformations such as filtering, sorting, etc. to its data before ......
Read more >
Feature request: default homebrew sorting is newest first - D&D ...
I'm new to the homebrew thing here and I love it but its super hard to search through just for interesting things. I...
Read more >
Advanced - React Select
Sortable MultiSelect. Using the react-sortable-hoc package we can easily allow sorting of MultiSelect values by drag and drop. Sortable MultiSelect example.
Read more >
Gateway OData service – how to implement generic filtering ...
In the Data Provider Extension class I have added three new methods, one for each of the three query options: Sorting, Filtering and...
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