Hyperlink on columns does not call click event using jquery on class

Hyperlink on columns does not call click event using jquery on class

CensorNetCensorNet Posts: 5Questions: 2Answers: 0

Hello,

I have a table which i add a custom hyperlink on a column which then i expect to be clicked and fire a $('.myClass').on('click',function(e){}); call.

this is how i add the hyperlink

"aTargets": [7],
                    "mData": null,
                    "mRender": function (data, type, full) {

                        return '<a href="#" value="'+data.id+'" class="myClass"> Complete </a>';
                    }

Once clicked i would like to fire up a ajax request and reload the data on the table.

Please feel free to suggest any other suggestions on that.

Thanks a lot

Regards
Costas

Answers

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    Hi Costas,

    Have a read over the Q. My events don't work on the second page FAQ. Its basically the same thing.

    Allan

  • CensorNetCensorNet Posts: 5Questions: 2Answers: 0
    edited May 2017

    Hello Allan,

    Thanks a lot for ur fast reply.
    But I cant see what i need to do to make an <a> element (hyperlink) in the tables cell clickable to call an event from the given example.

    $('.myClass').on('click', function (e) {
    
                var data = oTable.row(this).data();
                console.log(data);
                alert('You clicked on ' + data.app_name.name + '\'s row');
    
            });
    

    The above does not work.

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    Change it to be a delegated event like the FAQ says:

    $('#myTable').on('click', '.myClass', function (e) {
      var tr = $(this).closest('tr');
      var data = table.row( tr ).data();
      ...
    

    Allan

This discussion has been closed.