Roly
Roly

Reputation: 161

DataTables: loop through all rows and get value from specific cell on each row

By using this code I can loop thru all DataTable rows and show the row values:

var table = $('#Example').DataTable();

table.rows().every(function(){

    console.log(this.data());
});

But how can I get the value only from cell 3 on each row?

Upvotes: 0

Views: 5785

Answers (2)

Roly
Roly

Reputation: 161

After trial and error this is what ended up working for me:

var table = $('#dtBasicExample').DataTable();

table.rows().every(function(){

    var Row=this.data();//store every row data in a variable

    console.log(Row[3]);//show Row + Cell index

});

Upvotes: 2

mark_b
mark_b

Reputation: 1471

Use columns().data()

let table = $('#example').DataTable();
let values = table.columns(2) // DataTables is zero-based
                    .data()  
                    .eq(0);  // Convert to 2D array
console.log(values);

Upvotes: 0

Related Questions