row data by index

row data by index

haraldharald Posts: 16Questions: 7Answers: 1

After clicking on the table, I am retrieving my row data with the respective index in the following way:

$('#testTable').on('click', 'tr td', function () {
    var tableClass = $('#testTable').DataTable();
    var idx = tableClass
        .row( this )
        .index();
    // row data
    var tr = $(this).closest('tr');
    row = tableClass.row( tr );
});

Later, I need to get the row data simply via the index. How can I do this.
Thanks for any help!

Answers

  • haraldharald Posts: 16Questions: 7Answers: 1

    var row = tableClass.row( 4 );

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    edited May 2022

    Yep, you could also use the td node for cell-selector into cell() - something like this :

    $('#example').on('click', 'tr td', function () {
        var tableClass = $('#example').DataTable();
        var idx = tableClass
            .cell( this )
            .index()
            .row; // <<<<<<<<
    
      console.log(tableClass.row(idx).data())
    });  
    
Sign In or Register to comment.