2

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 that row can be displayed in divs on the same page.

Below is the code I am using but it is not working, I would appreciate it if someone could give me an example that works

I get the following error message:

Error - Cannot read property '_aData' of undefined

   $(document).ready(function() {
            var table = $('#datatable-buttons').DataTable();

            $('#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]);
            } );
        } );
2
  • Would you be able to produce a fiddle which replicates your issue? Commented Mar 20, 2018 at 7:15
  • Try outputting the data in console. Also, make sure that the html inside the table is valid i.e., uneven tr/td. Commented Mar 20, 2018 at 12:18

1 Answer 1

3

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]);
    } );
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.