Need help adding scrollTo to bottom pagination

Need help adding scrollTo to bottom pagination

brianfidlerbrianfidler Posts: 21Questions: 1Answers: 0
edited May 2011 in General
on this page: http://waldronsfarm.com/index.php/products/

I have added a function to scroll to the top of the page when First, Last, Previous, and Next are clicked. For some reason I can't seem to add the function to the numeric pagers though. Is it because they are dynamically generated?

Here is the jquery function that works on First, Last, Previous, and Next. I've tried a number of different iterations, even hacking the core datatables code to add a class="paginate_button_container" to the span that wraps around the number buttons, but nothing seems work in making them activate the scrollTo function.

[code]
jQuery(".paging_full_numbers").click(function(){
//$.scrollTo scrolls the whole screen
//alert(".paginate_button was just clicked");
jQuery.scrollTo( 0, 400);
return false;

});
[/code]

Please let me know what I need to do to get this functionality to work on the numbers.

thanks.

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    They are indeed dynamically generated on each draw. Try using a live event ($().live()) rather than the static click to do what you are looking for.

    Allan
  • brianfidlerbrianfidler Posts: 21Questions: 1Answers: 0
    Thanks Allan,

    Can you help me out with the syntax, I changed my code to the following, but it still only works on the four non-dynamic elements, First, Last, Previous and Next.

    [code]
    jQuery(".paging_full_numbers span.paginate_button").live({
    click: function() {
    jQuery.scrollTo( 0, 400);
    }
    });
    [/code]

    thanks,
    brian
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Change your selector to ".paging_full_numbers span" and that should do it.

    Allan
  • brianfidlerbrianfidler Posts: 21Questions: 1Answers: 0
    I've changed the selector to ".paging_full_numbers span" however it still only scrolls when the First, Last, Previous, and Next buttons are hit.

    brian
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Damn - sorry about that. I think that it is actually caused by this line in DataTables: https://github.com/DataTables/DataTables/blob/master/media/js/jquery.dataTables.js#L544 . I can't test it right now, but perhaps you could try removing that line in your copy and see if that addresses the issue. Basically the event isn't propagating to your event handler due to the return false.

    Allan
  • brianfidlerbrianfidler Posts: 21Questions: 1Answers: 0
    That worked, but I had to change my selector back to span.paginate_bottom to specifically target the buttons.

    thanks Allan!
This discussion has been closed.