javapaginationwicket

How to send to the top with AjaxPagingNavigator


I want to send to the top of the page each time the user clicks on a page in a AjaxPagingNavigator. I can send via a href="#topofpage" which works for a static link, but setting this value in the href ov my extended PagingNavigator (for GUI customization only) does not work.

What would be the right approach?


Solution

  • You can add to the links in the AjaxPagingNavigator an AjaxEventBehavior which would on click perform the scroll top:

    add(new AjaxPagingNavigator("id", pageable){
    
        @Override
        protected AbstractLink newPagingNavigationLink(String id, IPageable pageable, int pageNumber) {
            AbstractLink link = newPagingNavigationLink(id, pageable, pageNumber); 
            link.add(new AjaxEventBehavior("click") {
                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    target.appendJavaScript("$(\"html\").scrollTop(0);");
                }
            });
    
            return link;
        }
    
    });