Reputation: 676
I am trying to get my second datatable to use its own css (for the alternating row color) once i added the { sClass: "myCustomClass" }, my jquery is not firing anymore.
Css for the demo_table.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 I am using to initialize the datatable, which worked perfectly before adding the sclass in but didnt have any of the css that i added.
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
});
}
I have two tables #table_id and #nested_id, I am trying to change row colors on #nested_id.
This is the jquery for the #nested_id
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;
}
This is the html for the #table_id
<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>
Upvotes: 0
Views: 400
Reputation: 1317
I think the problem is in your CSS... sClass
puts the class on every td
in a column, not a tr
. So tr.even.myCustomClass
is never applied.
It should be more like:
table.display tr.even td.myCustomClass { background-color: #FFFFCC; }
table.display tr.odd td.myCustomClass { background-color: #ffeeee; }
EDIT based on update to OP
You can avoid using sClass all together, and just use CSS specific to your nested table:
Your table in your html is missing class="display"
. So you can either add and you CSS is:
table.display#nested_id tr.even { background-color: #FFFFCC; }
table.display#nested_id tr.odd { background-color: #ffeeee; }
Or you can leave it off and your CSS is:
table#nested_id tr.even { background-color: #FFFFCC; }
table#nested_id tr.odd { background-color: #ffeeee; }
Finally, you'll need to add CSS for
table#nested_id tr.even .sorting_1{ /*background-color here*/ }
table#nested_id tr.odd .sorting_1{ /*background-color here*/ }
See this jsfiddle for a working example.
Upvotes: 1