问题描述
我为jquery.datatables制作了一张大桌子,这对我来说非常有用。
,但是我需要一个相对于其列的每个td元素设置的类名。
fo例如,我想要一列(包括th和所有td)有一个 class =volume
。
有这个问题:
i使用此代码初始化该类,但它不工作。
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] }
]
编辑:
我的表是动态创建和重新混合。它由一个js数组组成,我不喜欢触摸它。只需添加类名称
编辑:
我使用这个代码来表示我的表:
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
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"]]
});
我希望它有助于
* EIDT:* >
columnsHd
是一个从我的json头创建动态的数组,现在是:
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" },
]
推荐答案
我的猜测是aoColumns:columnsHd,覆盖aoColumnsDefs:[ {sClass:volume,aTargets:[2]},],
尝试在代码
或者直接在aoColumns中添加类:columnsHd,
喜欢这个sClass:volume
完成代码:
将 {sTitle:ip},
转换为 {sTitle:ip,sClass:volume}, / code>
try changing { "sTitle": "ip" },
into { "sTitle": "ip", "sClass": "volume" },
并删除
"aoColumnsDefs": [
{ "sClass": "volume", "aTargets": [2] }
],
请注意,在数据表1.10中,您应该使用
这篇关于如何添加类到jquery.datatables列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!