Data table row click event not working

后端 未结 1 1151
梦毁少年i
梦毁少年i 2021-01-23 01:04

I am pulling data from a database using coldfusion into a dataTable and I would like that when I click on a row in the datatable and event is fired which so that the details of

相关标签:
1条回答
  • 2021-01-23 01:31

    Try unbinding the event for your buttons before you re-assign them: just add the following line before the row click:

    $('#datatable-buttons tbody').off('click');
    

    So changed code is:

    $(document).ready(function() {
        var table = $('#datatable-buttons').DataTable();
        $('#datatable-buttons tbody').off('click');
        $('#datatable-buttons tbody').on('click', 'tr', function () {
            var data = table.row( this ).data();
            // alert( 'You clicked on '+data[0]+'\'s row' );
            alert("table click"+data[0]);
        } );
    });
    
    0 讨论(0)
提交回复
热议问题