Hi All,
I badly need someone to help me. we were implementing pagination in CQ5. We want something similar to google pagination - For example, I want to show 10 results per page and after page 6, I want to move the pagination numbers one by one. ie. first it will show 1 2 3 4.......10 and after page 6 is clicked, it need to show 2 3 4 5 6 7 8 9 10 11 and then for page 11 is clicked then 5 6 7 8 9 10 11 12 13 14 etc. And in the last page we just show last page - 10 pages.
We tried implementing this but this was too complexed as we tried to do as showed below.
private List<ResultPage> extractSubList(SearchResult result){
long currentIndex = result.getStartIndex() / result.getHitsPerPage();
int startIndex = (int)currentIndex - 5;
int endIndex = (int)startIndex + 10;
startIndex = startIndex < 0 ? 0 : startIndex;
endIndex = endIndex >= result.getResultPages().size() ? result.getResultPages().size() : endIndex;
List<ResultPage> subList = result.getResultPages().subList(startIndex, endIndex);
return subList;
}
Though this logic works fine for us till 11th page but as soon as we move to 12th page, the resultPage list index changes and also the result page size changes and hence we could not provide proper start and end indexes. Also we tried to restrict 10 numbers to display but could do that.
Can someone please help me in acheiving this functionality? Let me know where we are doing wrong.