Typeahead.js: Unable to display more than 5 results with Bloodhound (0.11.1)

Created on 28 Apr 2015  路  17Comments  路  Source: twitter/typeahead.js

Hi there,

I'm using the version 0.11.1 of Typeahead.js with Bloodhound

I'm unable to display more than 5 results.

Here is my settings:

    var cityEngine = new Bloodhound({
            prefetch: './prefetch-cities.json',
            remote: {
                url: './search-cities.json?query=%QUERY',
                wildcard: '%QUERY'
            },
            sufficient: 20,
            identify: function(datum) {
                return datum.id;
            },
            datumTokenizer: function (datum) {
                return Bloodhound.tokenizers.whitespace(datum.name);
            },
            queryTokenizer: Bloodhound.tokenizers.whitespace
        });

I tried "limit" instead of "sufficient" (like in older versions) but it doesn't work.

Prefetch is working fine. When I type in the input, for example I get instantly 2 results... then a remote request is done to get more results. I tried this request directly, and it returns 25+ results... but typeahead displays only 5.

Thank you.

Most helpful comment

I faced same issue.
limit:10 does not work for remote.
but when I set limit:20, it does work.
It is so strange typeahead parameter now.

All 17 comments

did you try setting 'limit' in your dataset configuration? (which defaults to 5)
see https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#datasets

since 0.11 'limit' is not a Bloodhound option anymore.

My bad. Didn't see that, thank you.

Do you have an example showing how to set limit in configuration as opposed to bloodhound settings?
I don't understand your documentation.
Thanks

Same problem here.

I think sufficient is the option again ( https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md#options) but not to display items.

For me what worked is to set the limit property in the Data Source:

        var example_ds = {
            name: 'example',
            displayKey: 'Description',
            source: my_bloodhound_object,
            limit: 20
        };

FWIW, I had to make sure that the limit was one less than the number of results being returned from my remote bloodhound object or nothing would show.

Same thing here @dougludlow, very strange behaviour. Setting the limit to 9 when receiving 10 hits works.

+1. I've encountered same problem.

Is there a more robust solution to this problem (other than ensuring the limit is one less than the number of results being returned)? It isn't always possible to know the number of results being returned.

Is there a PR to address this issue?

+1. I've encountered same problem.

$('#search-input').typeahead({
hint: true,
highlight: true,
}, {
name: 'best-pictures',
display: 'table_name',
source: bestPictures,
limit: 20
});
it works for me for v0.11.1

This works for me

  $('#some_name').typeahead({
            hint: true,
            highlight: true,
            minLength: 1,

        },
        {
            name: 'some_name',
            source: substringMatcher(your_array),
            limit:10
        });

I've encountered same problem.
limit: 10, work's only local, not work for remote calls.

I found the possible solution in https://github.com/twitter/typeahead.js/pull/1675/files

using the v0.11.1. Has there been any resolution to this? if remote dataset returns 20, and limit is set to 20, nothing shows. if limit set to 19, then 19 show. If dataset returns 11, limit set to 20, then 9 show. If dataset returns 12, limit set to 20, then 8 show. What has been the workaround, since no patch is available?

[update] looks like the infinity limit works with the throttle at the end point if that is available. otherwise, seems like you're screwed.

I faced same issue.
limit:10 does not work for remote.
but when I set limit:20, it does work.
It is so strange typeahead parameter now.

FWIW, I had to make sure that the limit was one less than the number of results being returned from my remote bloodhound object or nothing would show.

Same here - even in January 2019. Almost bailed on typeahead because of it.
Thank you so much @fajaryanw !

same here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GreatPotato picture GreatPotato  路  8Comments

viktor-rachuk picture viktor-rachuk  路  3Comments

steswinbank picture steswinbank  路  5Comments

a-lucas picture a-lucas  路  5Comments

DevChive picture DevChive  路  5Comments