[英]jQuery datatable highlight single row
I am trying to highlight a single row in my jQuery datatable. 我试图在我的jQuery数据表中突出显示一行。
I attempted to use the information here: https://datatables.net/examples/api/select_single_row.html 我试图在这里使用这些信息: https : //datatables.net/examples/api/select_single_row.html
Using that, I can use Chrome's inspector and I can verify that the class is being added to the table row. 使用它,我可以使用Chrome的检查器,我可以验证该类是否被添加到表行。 But the row is not being highlighted.
但该行没有突出显示。
Here is the jQuery: 这是jQuery:
// not sure if this was necessary to show
$('#example1').DataTable({
"iDisplayLength": 25,
"order": [[ 6, "desc" ]],
"scrollY": 550,
"scrollX": true,
"bDestroy": true,
"stateSave": true
});
var table = $('#example1').DataTable();
$('#example1 tbody').on('click', 'tr', function()
{
if($(this).hasClass('selected')){
$(this).removeClass('selected');
}
else{
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
});
With this, as stated, I can see the class being added to the row, I'm just not seeing the row color change. 有了这个,如上所述,我可以看到正在添加到行中的类,我只是没有看到行颜色的变化。
I added some CSS on the HTML page to see if it would work. 我在HTML页面上添加了一些CSS,看它是否有效。 As follows:
如下:
<style>
.selected tr {background-color: blue;}
</style>
To no avail. 无济于事。 Does anyone see my error?
有人看到我的错误吗?
I cannot test this, but the error seems to be in the CSS selector you're using for the background-color
. 我无法测试这个,但错误似乎是你用于
background-color
的CSS选择器。
It should be tr.selected
(a tr
element with the class selected
) and not .selected tr
(a tr
element in an element with the class .selected
). 它应该是
tr.selected
( selected
了类的tr
元素)而不是.selected tr
(带有.selected
类的元素中的tr
元素)。
确保加载jquery.dataTables.min.css
。
Maybe you can use the jQuery click
function and a little JS logic track 也许你可以使用jQuery
click
功能和一点JS逻辑轨道
https://jsfiddle.net/moongod101/mbLnrcg6/ https://jsfiddle.net/moongod101/mbLnrcg6/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.