Failing to add an event handler to the pagination button (only happens once)

Failing to add an event handler to the pagination button (only happens once)

faruzzyfaruzzy Posts: 4Questions: 0Answers: 0
edited February 2013 in General
Hi,
Thank you for providing such a marvelous plugin.

My company is starting to use this plugin and we love it.

I'm trying to perform some operations when the user click on the pagination button, but only the "first", "previous", "next", "last" button seems to have my event attached. Buttons 1, 2, 3 don't.

When I do:
[code]
$('.dataTables_paginate').on('click', 'a', function(e) {
console.log(e)
});
[/code]

I get jQuery.Event {originalEvent: MouseEvent, type: "click", isDefaultPrevented: function, timeStamp: 1361813511506, jQuery183043436975846998394: true…}
when I click "first", "previous", "next", "last".
but when I click 1, 2, 3 .. nothing is logged onto the console.

When I try to select the "1" button directly by doing:

[code]
$('a.fg-button:eq(2)').on('click', function() {
console.log('success');
});
[/code]
It displays that once "success" once when I first click on it, then nothing happens.

Can you help me resolve this issue ?

Thank you for taking the time to help me!

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    I think the problem is that DataTables is cancelling the event bubbling - which perhaps it shouldn't... It might be an idea to listen for the 'page' event: http://datatables.net/docs/DataTables/1.9.4/#page , or you could modify DataTables to allow the bubble (if you do - send a pull request as I think that should be in!).

    Allan
This discussion has been closed.