There isn't a method specifically for this, but you can access the required property:
[code]
var iColumns = oTable.fnSettings().aoColumns.length;
[/code]
The DataTables settings object contains internal information, and hence is undocumented on this site, but there is a wealth of information in the source code if you need anything more than just the number of columns.
The other option is to query the DOM directly:
[code]
var iColumns = $('#example thead th').length;
[/code]
Regards,
Allan
[code]
$(document).ready(function() {
var oTable = $('#example').dataTable( );
console.log( oTable.fnSettings().aoColumns.length );
} );
[/code]
Gives a length of 3. Have you initialised your table with bStateSave and altered the number of columns - that is showing a few problems in 1.5.2?
Your pages are both rendering in quirks mode - that in combination with the fact that neither page validates ( http://validator.w3.org/ ) will mean that the browser can do some very weird things. I've tried your table code from the first link in a validating page (strict HTML 4) and it works no problem - so I suspect if you add a doctype to the pages, it will work as expected - you might also need to fix the HTML errors.
I totally can't explain that :-). I would imagine it must be an interaction with one of the other script, since I can get your basic HTML table to work for me no problems at all. So yup - I agree - removing the other scripts is the way to go.
Replies
There isn't a method specifically for this, but you can access the required property:
[code]
var iColumns = oTable.fnSettings().aoColumns.length;
[/code]
The DataTables settings object contains internal information, and hence is undocumented on this site, but there is a wealth of information in the source code if you need anything more than just the number of columns.
The other option is to query the DOM directly:
[code]
var iColumns = $('#example thead th').length;
[/code]
Regards,
Allan
Aaron
Any ideas?
aoColumns has a fourth column, eg aoColumns[3], that has a blank name and a width of 6 pixels.
Group
St.
ttt
Odd - it works okay for me:
[code]
$(document).ready(function() {
var oTable = $('#example').dataTable( );
console.log( oTable.fnSettings().aoColumns.length );
} );
[/code]
Gives a length of 3. Have you initialised your table with bStateSave and altered the number of columns - that is showing a few problems in 1.5.2?
Thanks,
Allan
This example doesn't work:
http://www.energyjustice.net/map-test/test.html
When I add an extra column, then this example works:
http://www.energyjustice.net/map-test/test2.html
The only difference is an extra in the only column row.
I've tried making tables with 3 or fewer columns, and they don't work.
Could there be a problem with tables that only have three (or fewer) columns?
Your pages are both rendering in quirks mode - that in combination with the fact that neither page validates ( http://validator.w3.org/ ) will mean that the browser can do some very weird things. I've tried your table code from the first link in a validating page (strict HTML 4) and it works no problem - so I suspect if you add a doctype to the pages, it will work as expected - you might also need to fix the HTML errors.
Regards,
Allan
http://www.energyjustice.net/map-test/test.html
The html validates. The CSS has many errors.
In Firebug, I'm getting "sData is undefined" - line 84 of the jQuery.datatables.min.js file
I guess I'll try removing all the other scripts (except jquery) in case they are causing problems.
I totally can't explain that :-). I would imagine it must be an interaction with one of the other script, since I can get your basic HTML table to work for me no problems at all. So yup - I agree - removing the other scripts is the way to go.
Regards,
Allan
http://www.energyjustice.net/map-test/test4.html
$("#sub-facility").dataTable({"iDisplayLength":20,
"bLengthChange":false,
[{"sType":"html"}, null, null, null]});
Allan