Expose Scroll Event?

Expose Scroll Event?

joshuasiegaljoshuasiegal Posts: 19Questions: 2Answers: 1
edited August 2012 in Feature requests
I've seen some threads (urls below) on Scroller, infinite Scrolling, etc., and I've checked out the Scroller and dataTables source, and one thing I'm not getting is why you would have scrolling, infinite scrolling, and an Extra for scrolling, but then swallow the scroll event on .dataTables_scrollBody for people to hook into. You do expose the ability for people to explicitly bind to other events through your api:

[code]
$(document).ready(function() {
$('#example')
.bind('sort', function () { eventFired( 'Sort' ); })
.bind('filter', function () { eventFired( 'Filter' ); })
.bind('page', function () { eventFired( 'Page' ); })
.dataTable();
} );
[/code]

Why isn't scroll on the list? One example I'm trying to use is to only load images in rows when they are in the scroll view, to save user bandwidth. This is not possible without binding to the scroll event, as far as I know.

If there is a solution that I'm missing somewhere, or I'm just wrong in my understanding of this, then I apologize.

Thanks!

Replies

  • allanallan Posts: 57,229Questions: 1Answers: 9,111 Site admin
    You can just attach a regular jQuery scroll listener:

    [code]
    $('div.dataTables_scrollBody').scroll( ... );
    [/code]

    No need for a custom callback - which is why it is not exposed.

    Allan
  • joshuasiegaljoshuasiegal Posts: 19Questions: 2Answers: 1
    http://www.datatables.net/forums/discussion/9549/so...-the-official-scroller-plug-in./p1

    http://datatables.net/forums/discussion/11191/datatables-scroller-debouncing-scroll-events-and-requestanimationframe/p1

    http://datatables.net/release-datatables/examples/advanced_init/dt_events.html
  • joshuasiegaljoshuasiegal Posts: 19Questions: 2Answers: 1
    I tried exactly that, and don't you know that it didn't work at all.

    But since you are the expert, I tried it again.

    And it works. Clearly, you are some sort of magician. *thanks!*
  • joshuasiegaljoshuasiegal Posts: 19Questions: 2Answers: 1
    Actually, here is what I tried:

    [code]
    $('#datatable_wrapper').on('scroll','.dataTables_scrollBody',function() {...
    [/code]

    If you have any insight as to why that failed, i'd be interested to know. Thanks again.
  • allanallan Posts: 57,229Questions: 1Answers: 9,111 Site admin
    It looks like you can't use 'scroll' as a delegated live event in jQuery. This works: http://live.datatables.net/olutok/edit#javascript,html , but putting the selector as the second parameter for `on` as you did - doesn't work.

    Allan
  • joshuasiegaljoshuasiegal Posts: 19Questions: 2Answers: 1
    Thanks!
This discussion has been closed.