7

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": "&nbsp;",
        "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" },
 ] 
8
  • have you tried templates or dynamically generating your "table"? what exactly is your goal? adding a class tag to a html-column? Commented Jan 9, 2013 at 9:13
  • You aware that its being add to the third column ? Commented Jan 9, 2013 at 9:16
  • yes i know it uses a zero based indexing but i tried any combinations and it just did not worked. i don know where do i do this wrong Commented Jan 9, 2013 at 9:18
  • are you sure that the class in not being applied to your td? have you checked with browser dev tools ? Commented Jan 9, 2013 at 9:25
  • 1
    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" Commented Jan 9, 2013 at 9:42

2 Answers 2

10

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

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

3 Comments

i have changed their order => not working. i changed "aoColumns": columnsHd, like this sClass: "volume" => whole table not working actually not generates
try changing { "sTitle": "ip" }, into { "sTitle": "ip", "sClass": "volume" }, and remove the "aoColumnsDefs": [ { "sClass": "volume", "aTargets": [2] } , ], I guess it didn't work before cause I forgot to add " before and after the sClass
its "aoColumnDefs" without the extra s. legacy.datatables.net/usage/columns
1

The answer for the question is

"aoColumnsDefs": [
    { "sClass": "classname", "aTargets": [whatever target you want to apply] }
]

to use other options: (ref datatable)

enter image description here

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.