jQuery 数据表 - 突出显示选定的行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17398226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:58:22  来源:igfitidea点击:

Datatables - highlight selected row

jquerycssdatatables

提问by user2444474

How to highlight the selected row in datatables. I have updated the html with jquery code datatables in jsfiddle. Please help me to write css to highlight the selected row in different color.

如何突出显示数据表中的选定行。我已经用 jsfiddle 中的 jquery 代码数据表更新了 html。请帮助我编写 css 以突出显示不同颜色的选定行。

var oTable = $("#products1").dataTable({
       "aaData": newarray,
       "bProcessing": true,
       "bDeferRender": true,
       "bFilter": false,
       "bJQueryUI": true,
       "bRetrieve": true,
       "bPaginate": false,
       "bSort": true,
       "aaSorting": [[4, "desc"]],
       "iDisplayLength": 25,
       "aoColumns": [{"sWidth": "100%","sClass": "center","bSortable": false},
             {
            "sWidth": "150%","sClass": "center","bSortable": false},
             {
            "sWidth": "150%","sClass": "center","bSortable": false},
             {
            "sWidth": "150%","sClass": "center","bSortable": false}


            ],
        "aoColumnDefs": [{ "fnRender": function (o, val) {
            return o.aData[0];
        },
            "sClass": "col1","aTargets": [0]
    }, {
        "fnRender": function (o, val) {

            return o.aData[1];
        },
            "sClass": "col2","aTargets": [1]
    }, {
    "fnRender": function (o, val) {

            return o.aData[2];
        },
            "sClass": "Number","aTargets": [2]
    },{
    "fnRender": function (o, val) {

            return o.aData[3];
        },
            "sClass": "Name","aTargets": [3]
    }]

});

here find jsfiddle

在这里找到jsfiddle

回答by yeyene

Check the demo here

此处查看演示

Add this after the table call.

在 table 调用之后添加它。

    $("#products tbody tr").on('click',function(event) {
        $("#products tbody tr").removeClass('row_selected');        
        $(this).addClass('row_selected');
    });