如何添加类到jquery.datatables列? [英] how to add class to jquery.datatables columns?

查看:115
本文介绍了如何添加类到jquery.datatables列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为jquery.datatables创建了一个大表,这对我很有用。

但是我需要为每个td元素设置一个相对于它的列的类名。

fo示例我想要一个列(包括th和所有td)有一个 class =volume

有这个问题:

i使用这个代码初始化类,但它不工作。

 aoColumnsDefs:[
{sClass:volume,aTargets:[2]
]

EDIT:
动态创建和刷新。并且它由js阵列制成,我喜欢不触摸它,即。只是添加类名

EDIT:

使用此代码可以对我的表格进行初始化:

  $('#dataTable')。dataTable({
aaData:dataCnt,
aoColumnsDefs:[
{sClass: volume,aTargets:[2]}
],
aoColumns:columnsHd,
bStateSave:true,//保存coockie中的状态
iCookieDuration :10,// coockie生命周期(秒)
sScrollX:100%,
sScrollY:(winHei-200),
sDom:'<H RCfrl> t< pFi",
oColVis:{
buttonText:& nbsp;,
bRestore:true,
sAlign:left
},
aLengthMenu:[[10,25,50,-1],[10,25,50,All]]
});

我希望能帮助
* EIDT:* >
columnsHd 是一个从我的json头动态创建的数组,现在是:

  [
{sTitle:macaddr},
{sTitle:lat},
{sTitle:ip },
{sTitle:relay0stat},
{sTitle:clientname},
{sTitle:relay0mask sTitle:正常运行时间},
{sTitle:bldname},
{
{sTitle:current},
{sTitle:temperature},
{sTitle:softver},
{sTitle :volume},
{sTitle:hardver},
{sTitle:relay1mask},
{sTitle:pic},
{sTitle:comment},
{sTitle:lon},
{sTitle:rtt},
{sTitle bldaddr},
]


解决方案

p>

尝试以代码替换其顺序



或直接在中添加类aoColumns :columnsHd,
like this sClass:volume



完整代码:



尝试将 {sTitle:ip},更改为 {sTitle:ip,sClass:volume},



b
$ b

 aoColumnsDefs:[
{sClass:volume,aTargets:[2]}
] ,






请注意,在数据表1.10中, a href =http://legacy.datatables.net/usage/columns> aoColumnDefs


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" },
 ] 

解决方案

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

这篇关于如何添加类到jquery.datatables列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆