Gravatar for abuteau@coveo.com

Question by abuteau, Jun 30, 2014 10:14 AM

Pager Component - Show Active Page when there is only one result page

Hi guys,

I have to always show the number of pages of a result. However, with the default Pager Component I don't see the number of pages (1) when there's only one result page. According to the Pager Components Options, it looks like there's no way to do this by default https://developers.coveo.com/display/JsSearch/Pager+Component. Maybe there's something I don't see.

So, I want to know if there's a way to do this out of the box ? If not I'll do a JQuery function with the Search Interface State.

Regards,

2 Replies
Gravatar for olamothe@coveo.com

Answer by olamothe, Jun 30, 2014 10:24 AM

There is no way to do this out of the box, unfortunately. The page doesn't render itself when there is only one page.

You have the right idea, hook yourself onto the querySuccess event and check for the number of results received + the state (to verify that the first result requested was 0).

If yes, then try to mimick and output the html markup that the pager normally produces, and the css should match correctly.

Gravatar for abuteau@coveo.com

Comment by abuteau, Jun 30, 2014 10:24 AM

Thanks ! Will try.

Gravatar for abuteau@coveo.com

Comment by abuteau, Jul 2, 2014 2:00 PM

$(document).ready(function() { Coveo.$('#search').on('querySuccess', function (e, data) { if(data.results.totalCount <= @Model.ResultsPerPage){ $(".CoveoPager").append('

'); } }); });

Gravatar for abuteau@coveo.com

Comment by abuteau, Jul 2, 2014 2:01 PM

$(document).ready(function() { Coveo.$('#search').on('querySuccess', function (e, data) { if(data.results.totalCount <= @Model.ResultsPerPage){ $(".CoveoPager").append('

'); } }); });

Gravatar for abuteau@coveo.com

Answer by abuteau, Jul 2, 2014 2:02 PM

Edit: Solution of Olivier was better:

$(document).ready(function() {
        Coveo.$('#search').on('querySuccess', function (e, data) {
            if(Coveo.$("#search").coveo('state', 'first') == 0){
                $(".CoveoPager").append('<ul><li class="coveo-active"><a>1</a></li></ul>');
            }
        });
        });
Gravatar for olamothe@coveo.com

Comment by olamothe, Jul 2, 2014 2:07 PM

You will need to also check if the first result requested was 0, otherwise you will end up overriding the normal pager behavior (Say you are rendering page #2, and you have only 5 results in that page)

You can check that with $("#search").coveo('state', 'first') == 0;

Also, you do not need to render the "Next" button, since there is no next page. Plus, since you hook no javascript function on click of the "Next" button, it will do nothing when a user click on it.

Ask a question