react-typeahead icon indicating copy to clipboard operation
react-typeahead copied to clipboard

How to implement search matching sort function?

Open invious opened this issue 7 years ago • 1 comments

I have this function which

    _handleSort = (a, b, input_string) => {
        let distance = this.levenshtein.get(a.name, input_string) - this.levenshtein.get(b.name, input_string)
        console.log(`a:${a.name}, b:${b.name}, input:${input_string}`)
        return distance;
    }

How can I make it so that the results are sorted by this function as I type in the AsyncTypeAhead

invious avatar Jun 28 '18 20:06 invious

something like this?

<AsyncTypeahead
                    onSearch={this._handleSearch}
                    searchOptions={this._handleSort}
    ...

_handleSort = (value, options) => {
        let sorter = (a, b) => {
            let distance = this.levenshtein.get(a.name, value) - this.levenshtein.get(b.name, value)
            console.log(`a:${a.name}, b:${b.name}, input:${value}`)
            return distance;
        }
        return options.sort(sorter)
    }

it doesn't seem like the sorter function is ever getting called

invious avatar Jun 28 '18 21:06 invious