using html attributes to set settings like aoColumDefs
using html attributes to set settings like aoColumDefs
Hi all,
Maybe this is more general javascript than jquery or datatables, but I am trying to read html attributes and pass them to the datatable. For example, I would like to have this:
[code]
ID
Account
Address 1
Address 2
Zip code
City
Country
Site
[/code]
I couldn't find anything to make this work, but unsuccessfully. So I tried this:
[code]
...
[/code]
and then have this in javascript:
[code]
var aoColumnDefs = [];
var aTargets = [];
jQuery( ".dropdowntotable_col_hidden" ).each( function( ix ) {
aTargets.push( jQuery(this).attr( "col" ) );
} );
aoColumnDefs.push( { "bVisible" : false, "aTargets": aTargets } );
aTargets = [];
jQuery( ".dropdowntotable_col_nosort" ).each( function( ix ) {
aTargets.push( jQuery(this).attr( "col" ) );
} );
aoColumnDefs.push( { "bSortable" : false, "aTargets": aTargets } );
jQuery( "#mytable" ).dataTable( {
"aoColumnDefs" : aoColumnDefs
} );
[/code]
This doesn't work... I get a little confused by the arrays in curly braces and brackets.
Any help is much appreciated!
Thanks!
Jerry
br
Maybe this is more general javascript than jquery or datatables, but I am trying to read html attributes and pass them to the datatable. For example, I would like to have this:
[code]
ID
Account
Address 1
Address 2
Zip code
City
Country
Site
[/code]
I couldn't find anything to make this work, but unsuccessfully. So I tried this:
[code]
...
[/code]
and then have this in javascript:
[code]
var aoColumnDefs = [];
var aTargets = [];
jQuery( ".dropdowntotable_col_hidden" ).each( function( ix ) {
aTargets.push( jQuery(this).attr( "col" ) );
} );
aoColumnDefs.push( { "bVisible" : false, "aTargets": aTargets } );
aTargets = [];
jQuery( ".dropdowntotable_col_nosort" ).each( function( ix ) {
aTargets.push( jQuery(this).attr( "col" ) );
} );
aoColumnDefs.push( { "bSortable" : false, "aTargets": aTargets } );
jQuery( "#mytable" ).dataTable( {
"aoColumnDefs" : aoColumnDefs
} );
[/code]
This doesn't work... I get a little confused by the arrays in curly braces and brackets.
Any help is much appreciated!
Thanks!
Jerry
br
This discussion has been closed.
Replies
[code]
parseInt( jQuery(this).attr( "col" ) )
[/code]