Can anyone help? (Show data for selected row and error in console output)

Can anyone help? (Show data for selected row and error in console output)

asbjotveasbjotve Posts: 3Questions: 2Answers: 0
edited July 2023 in Free community support

This is my table: https://live.datatables.net/vezukubi/1/

I have tried to get a dialog (alert) that will output the line_id for selected row. But I can't get it to work.
Also, the console output shows ""[object Object] (line 3)" - what does that means?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    Answer ✓

    Your test case has a couple errors. First this:

    DataTables warning: table id=example - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

    Its due to having duplicate code in the HTML tab and the Javascript tab. Removing the duplicate code results in this error when clicking a row:

    Uncaught ReferenceError: id is not defined
    at HTMLTableRowElement.<anonymous> (<anonymous>:33:13)

      $('#example tbody').on('click', 'tr', function () {
        let ding = table.row(this).data()[0];
        alert ( id );
      } );
    

    Your assignment is wrong. The issue you are asking about is with .data()[0]. You defined columns.data which means the rows are using object based data but .data()[0] is using array notation. Use .data().line_id. Here is the updated example with all the fixes:
    https://live.datatables.net/vezukubi/1/edit

    Kevin

Sign In or Register to comment.