0

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?

4
  • does cell 3 have a class? Commented Jul 22, 2019 at 15:52
  • cell 3 was an example, it can be whatever cell I want Commented Jul 22, 2019 at 15:56
  • @AndrewDaly and no it does not have a class Commented Jul 22, 2019 at 15:57
  • var dataRow = table.rows( ':nth-child(3)' ).data(); Commented Jul 22, 2019 at 15:59

2 Answers 2

2

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

});
Sign up to request clarification or add additional context in comments.

Comments

0

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);

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.