datatables number of columns

datatables, javascript, jquery

Solution

The fnGetData can be used to get a single data row. So, you can simply check the length of the data row for the number of columns.

Example:

oTable.fnGetData(someRowNumber).length;

The above will return the number of columns in that data row.

Problem

How do i get the number of columns in a datatable? I can get the number of rows by doing oTable.fnGetData().length but how do I get the number of columns so I can Iterate over each cell like this: ``` var numColumns = //How to get the number of columns? for(var r=0;r<oTable.fnGetData().length;r++){ for(var c=0;c <= numColumns;c++){ console.log("[R]: "+r+ "[C]: "+c+ " data: "+oTable.fnGetData(r,c)); } } ```

Original source