一旦我添加了 { sClass: "myCustomClass" },我试图让我的第二个数据表使用它自己的 css(用于交替行颜色),我的 jquery 不再触发。
demo_table.css 的 CSS
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* DataTables row classes
*/
table.display tr.odd.gradeA {
background-color: #ddffdd;
}
table.display tr.even.gradeA {
background-color: #eeffee;
}
table.display tr.odd.gradeC {
background-color: #ddddff;
}
table.display tr.even.gradeC {
background-color: #eeeeff;
}
table.display tr.odd.gradeX {
background-color: #ffdddd;
}
table.display tr.even.gradeX {
background-color: #ffeeee;
}
table.display tr.odd.gradeU {
background-color: #ddd;
}
table.display tr.even.gradeU {
background-color: #eee;
}
tr.odd {
background-color: #E2E4FF;
}
tr.even {
background-color: white;
}
table.display tr.even.myCustomClass { background-color: #FFFFCC; }
table.display tr.odd.myCustomClass { background-color: #ffeeee; }
我用来初始化数据表的 Jquery,在添加 sclass 之前工作得很好,但没有我添加的任何 css。
function nestedtable(systemid) {
var dbselected = $('#dblist').find(":selected").text();
$('#nested_id').dataTable({
"sAjaxSource": '/php/connect/nestedsearchtablequery.php',
"bProcessing": true,
"bDeferRender": true,
"bDestroy": true,
"sAjaxDataProp": "",
"fnServerParams": function (aoData) {
aoData.push({ "name": "db", "value": dbselected}),
aoData.push({ "name": "systemid", "value": systemid });
},
"aoColumns": [
{ sClass: "myCustomClass" },
{ "mData": "eventtime" },
{ "mData": "eventtype" },
{ "mData": "cid_name" },
{ "mData": "cid_num" },
{ "mData": "cid_ani" },
{ "mData": "cid_dnid" },
{ "mData": "exten" },
{ "mData": "context" },
{ "mData": "appname" },
{ "mData": "channame" }, ]
//"bJQueryUI": true //This is commented out to remove the smooth datatable style
});
}
我有两个表#table_id 和#nested_id,我正在尝试更改#nested_id 上的行颜色。
这是 #nested_id 的 jquery
function fnFormatDetails(oTable, nTr, systemid) {
var sOut =
'<div class="innerDetails">' +
'<table id="nested_id" cellpadding="5" cellspacing="0" border="0" style="padding-left:50px; background:white;">' +
'<thead>'
+ '<tr>'
+ '<th>Time</th>'
+ '<th>Event</th>'
+ '<th>CNAM</th>'
+ '<th>CNUM</th>'
+ '<th>ANI</th>'
+ '<th>DID</th>'
+ '<th>Exten</th>'
+ '<th>Context</th>'
+ '<th>AppName</th>'
+ '<th>Channel</th>'
+ '</tr>'
+ '</thead>'
+ '<tbody></tbody>'
'</table>' +
'</div>';
return sOut;
}
这是#table_id 的 html
<body>
<div id="stable" style=" margin-left: 2%; margin-right: 2%; display: none">
<table class="display" id="table_id">
<thead>
<tr>
<th>Call Date</th>
<th>Recording</th>
<th>System</th>
<th>CallerID</th>
<th>App</th>
<th>Destination</th>
<th>Disposition</th>
<th>Duration</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</body>