Call jquery function from datatable cell

Call jquery function from datatable cell

nono123nono123 Posts: 1Questions: 1Answers: 0

Hi
There is probably a very simple fix for this...I am trying to make a jquery call when clicking on a datatable cell.

Where should I include the jquery 'click ' event definition?
I tried inserting it in 'initComplete' event, it works when first loading the table but not when the table is filtered (as initComplete is not reloaded)

I tried in 'fnDrawCallback', this also works but unfortunately for some reason 'fnDrawCallback' gets called twice when first loading the table (therefore 'are you sure' message gets called twice).

What am I doing wrong here? What is the correct way of calling a function from within a datatable cell?

Thanks for your help.

$('.deleteannonce').on("click", function(event)
{
    event.preventDefault();
    if (confirm("Are you sure ?"))
            {

    $(this).parent().parent().hide(); 
    var post_array = 
    {
        "id_annonce"    : $(this).data("annonce"),     
              
    };

    $.post(baseUrl + "/annonce/ajax_delete_annonce", post_array,
        function(data)
        {

        });
    }

});

$('#annonces').dataTable( {
"ajax": baseUrl+"/annonce/ajax_list_annonces",
                    
                aoColumns: [
                        { mData: 'id_annonce' },
                        { mData: 'id_annonce',
                "render": function ( data, type, full, meta ) {             
                return '<a class="deleteannonce" data-annonce="'+ data +'">Delete</a>';
                }
            }           
                        
                ]
    } );
This discussion has been closed.