table.row(this).data() returnes Undefined (at first)

table.row(this).data() returnes Undefined (at first)

sean_davidsonsean_davidson Posts: 3Questions: 1Answers: 0

I'm following the example on the row().data() page for how to get the row data into the console. This worked for me before in my project, but now when I try to do this, the browser console at first shows Undefined, and then within a split second it displays the row data.

I'm trying to get the 'id' field value in order to open a details popup, but it fails as the 'id' is undefined at first and so the popup call fails.

What would cause this to return Undefined at first but then almost immediately after, return the actual row data?

Thanks
Sean

Answers

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

    Sounds like you might be Ajax loading the data? It's hard to say without seeing a test case showing the issue.

    Allan

  • sean_davidsonsean_davidson Posts: 3Questions: 1Answers: 0

    I am using Ajax to load the table data using serverside processing. Is there something I need to do in the Ajax call to help this?

    Sean

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    edited July 2023

    When you say you are following the example on the row().data() page are you referring to this?

    $('#example tbody').on( 'click', 'tr', function () {
        console.log( table.row( this ).data() );
    } );
    

    Are you doing anything else in the event handler? It sounds like you might have an asynchronous process in the event handler.

    The above code works with server side processing, for example:
    https://live.datatables.net/qoliyehi/43/edit

    As Allan said we will need a running test case to help debug the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • sean_davidsonsean_davidson Posts: 3Questions: 1Answers: 0

    I just put a check in the event handler to see if the row was undefined or not. If not, it would call my secondary function. A bit of a hack but it seems to work.

    Sean

Sign In or Register to comment.