Pagination issue

Pagination issue

rainolfrainolf Posts: 56Questions: 6Answers: 0
edited November 2014 in DataTables

Hi,
i'm working on a simple ajax request when clicked on a link in Data Table.
like so:

{
            "sWidth": "2%",
            "mData": "extension",
            className: 'td-center',
            "mRender": function ( data, type, full ) {
            return '<a class=link href="#" title="Click2Call '+data+'">'  + data  + '</a>';
            }
        },

and the ajax request is:

 $('.link').on('click',function () {
        var number = $(this).text();
    $.ajax({
        type: 'POST',
        async: false,
        url: "click2call/call.php",
        data: {number:number},
        success: function(){ tempAlert("Call in Progress...",5000);},
        error: function(){ alert("An error has occured!!!");}
    });
    } );

    function tempAlert(msg,duration)
    {
     var el = document.createElement("div");
     el.setAttribute("style","color: gray; font: 1em Calibri, Sans-Serif;position:absolute;top:30%;left:50%;background-color:white;");
     el.innerHTML = msg;
     setTimeout(function(){
      el.parentNode.removeChild(el);
     },duration);
     document.body.appendChild(el);
}
});

It seems that in the first view all is working well while when navigate across other pages (with pagination) nothing happens.
The ajax request are not made.

Do u notice any particular behavior?

Thank you

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Top FAQ :-)

    Allan

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    Thank you Allan,
    however this link:
    http://datatables.net/examples/advanced_init/events_live.html
    was exactly my starting point but in that case you are searching for the first column(var name = $('td', this).eq(0).text();).
    My needs is to get the value of the third column (for example) but if i hide it(with show/hide columns) the script will gets me a wrong value.

    That's why i've put a class and make a selector to find class=link.

    Do u think could i use a better way?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    The problem is that you aren't using a delegated event:

    $('.link').on('click',function () {

    should be:

     $('#myTable').on('click', '.link', function () {
    

    Allan

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    really cool...

    thank you

This discussion has been closed.