I made a large table for jquery.datatables which is works great for me.
but i need a class name set to each td element relative to its column.
fo example i want a column (including th and all td's) have a class="volume"
.
there is this issues:
i use this code to initialize the class but it is not working.
"aoColumnsDefs": [
{ "sClass": "volume", "aTargets": [2] }
]
EDIT:
my table is created and refeshes dynamically. and it is made of a js-array which i prefer not to touch it ie. just to add class names
EDIT:
iuse this code to itialize my table:
$('#dataTable').dataTable({
"aaData": dataCnt,
"aoColumnsDefs": [
{ "sClass": "volume", "aTargets": [2] }
],
"aoColumns": columnsHd,
"bStateSave": true,//saving status in coockie
"iCookieDuration": 10,//coockie life duration in seconds
"sScrollX": "100%",
"sScrollY": (winHei-200),
"sDom": '<"H"RCfrl>t<p"F"i>',
"oColVis": {
"buttonText": " ",
"bRestore": true,
"sAlign": "left"
},
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
});
i hope it helps
*EIDT: *columnsHd
is an array which is created dynamicaly from my json headers and now is exactly:
[
{ "sTitle": "macaddr" },
{ "sTitle": "lat" },
{ "sTitle": "ip" },
{ "sTitle": "clientname" },
{ "sTitle": "relay0mask" },
{ "sTitle": "relay0stat" },
{ "sTitle": "relay1stat" },
{ "sTitle": "clientid" },
{ "sTitle": "bldname" },
{ "sTitle": "uptime" },
{ "sTitle": "current" },
{ "sTitle": "temperature" },
{ "sTitle": "softver" },
{ "sTitle": "volume" },
{ "sTitle": "hardver" },
{ "sTitle": "relay1mask" },
{ "sTitle": "pic" },
{ "sTitle": "comment" },
{ "sTitle": "lon" },
{ "sTitle": "rtt" },
{ "sTitle": "bldaddr" },
]
My guess is that "aoColumns": columnsHd, overrides the "aoColumnsDefs": [ { "sClass": "volume", "aTargets": [2] } , ],
Try to replace their order in code
Or just add the class directly in "aoColumns": columnsHd,
like this "sClass": "volume"
complete code :
try changing { "sTitle": "ip" },
into { "sTitle": "ip", "sClass": "volume" },
and remove the
"aoColumnsDefs": [
{ "sClass": "volume", "aTargets": [2] }
],
Note that in datatables 1.10 you should use aoColumnDefs
The answer for the question is
"aoColumnsDefs": [
{ "sClass": "classname", "aTargets": [whatever target you want to apply] }
]
to use other options: (ref datatable)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With