Pagination button events,

Pagination button events,

sahanlaksahanlak Posts: 6Questions: 0Answers: 0
edited April 2011 in General
I'm using a column with check boxes in the data grid where users can select all or select one by one, the problem is when paginating, (from 1 to 2) previously selected checkboxes stays selected, so was planing to bind a click event to the pagination items, so when they get clicked check boxes get unchecked, but that doesn't work, I tried .bind, .live nothing works. I went to the source and added some alerts to $(nFirst).bind('click' and it worked, but not sure of a way to add events to the numbered buttons ?

[code]

$(nFirst).bind( 'click.DT', function () {
if ( oSettings.oApi._fnPageChange( oSettings, "first" ) )
{
alert('works'); //event works
fnCallbackDraw( oSettings );
}
} );

$(nPrevious).bind( 'click.DT', function() {
if ( oSettings.oApi._fnPageChange( oSettings, "previous" ) )
{
fnCallbackDraw( oSettings );
}
} );

$(nNext).bind( 'click.DT', function() {
if ( oSettings.oApi._fnPageChange( oSettings, "next" ) )
{
fnCallbackDraw( oSettings );
}
} );

$(nLast).bind( 'click.DT', function() {
if ( oSettings.oApi._fnPageChange( oSettings, "last" ) )
{
fnCallbackDraw( oSettings );
}
} );
[/code]

Any idea? thanks in advance.

Replies

  • jacqueminvjacqueminv Posts: 1Questions: 0Answers: 0
    Hi sahanlak,

    I needed to bind an handler on the numerical links in the pagination and found a way to do so. Hope that the following explanation will help.

    First, your handler was not called because each numbered link has already an handler attached on creation and this handler stops the propagation at the end of the function. Here is the relevant part of the source:

    [code]
    var fnClick = function() {
    /* Use the information in the element to jump to the required page */
    var iTarget = (this.innerHTML * 1) - 1;
    oSettings._iDisplayStart = iTarget * oSettings._iDisplayLength;
    fnCallbackDraw( oSettings );
    return false;
    };
    [/code]

    As a workaround you can see that fnCallbackDraw is called at the end. Adding your custom callback to oSettings.aoDrawCallback will do the trick. aoDrawCallback is an array containing objects defining every callback that has to be called on a draw operation (so be careful to add only fast functions as callback). Each object is defined as {'sName': 'your-custom-name', 'fn': yourcustomcallback}

    There might be a better solution to your problem but this was my 2 cents.
  • pimperishpimperish Posts: 17Questions: 0Answers: 0
    As an alternative to events on the pagination buttons, you could use fnInfoCallback (or fnFooterCallback or fnHeaderCallback) which all give you information about the current start and end indices displayed on the page. So you could uncheck anything not in the current view. Also belongs in the "workaround" category, but, an option nonetheless.
This discussion has been closed.