Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual Count #1494

Open
zoinkydoink opened this issue Mar 18, 2016 · 1 comment
Open

Virtual Count #1494

zoinkydoink opened this issue Mar 18, 2016 · 1 comment

Comments

@zoinkydoink
Copy link

I am trying to get a count returned with the suggestions and display the count in the footer to say showing 10 (number of records i actually return) of 10000 (total number of records matching in my db)

I have everything setup, the only thing I am not sure about is how to return an object with 2 properties, 1 containing the virtual count, the other containing suggestions and then have the suggestions be bound properly and still have access to the count. below is my code

Also any suggestion on the code improvement would be appreciated
`

var results = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.whitespace,
    queryTokenizer: Bloodhound.tokenizers.whitespace,


    remote: {
        url: '/Member/GetPlaces/?query=%QUERY',
        wildcard: '%QUERY',
        'cache': false,
        rateLimitWait: 500

    }
});
$('#search-box').bind('typeahead:asyncrequest', function (ev, query, ds) {
    showHideSearchSpinner(true);
    console.log("start");
});
$('#search-box').bind('typeahead:asyncreceive', function (ev, query, ds) {
    showHideSearchSpinner(false);
    console.log("done");


});
$('#search-box').bind('typeahead:asynccancel', function (ev, query, ds) {
    showHideSearchSpinner(false);
    console.log("cancel");


});

var footer = function (context) {
    // calculate total hits here
    return "Showing " + context.suggestions.length + " of "+ VIRTUALCOUNT +" results</a>";

}


function showHideSearchSpinner(isShow)
{
    setTimeout(function () {

        if (isShow) {
            $("#search-box-icon").removeClass("fa-search");
            $("#search-box-icon").addClass("fa-lg");
            $("#search-box-icon").addClass("fa-spinner");
            $("#search-box-icon").addClass("fa-spin");

        }
        else {
            $("#search-box-icon").addClass("fa-search");
            $("#search-box-icon").removeClass("fa-lg");

            $("#search-box-icon").removeClass("fa-spinner");
            $("#search-box-icon").removeClass("fa-spin");


        }
    }, 100);

}
$('#search-box').typeahead(null, {
    highlight: true,
    minLength: 3,
    source: results,
    limit: 'Infinity',

    templates: {
        footer: footer,
        empty: [
          '<div class="empty-message">',
            '<i class="fa fa-warning"></i> Nothing found...',
          '</div>'
        ].join('\n'),
        suggestion: function (data) {

            return '<div><strong>' + data.Name + '</strong><div class="pull-right"><a class="btn btn-primary btn-xs"><i class="fa fa-plus"></i> Add</a></div><br/><small>'+data.FullAddress + '</small></div>';
        }
    }
}).bind("typeahead:selected", function (obj, datum, name) {
    console.log(datum);
});`
@naumanahmed19
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants