简体   繁体   中英

Highlighting rows with DataTables (or other table/grid plug-ins)

There's an example in DataTables for highlighting rows on hover: http://datatables.net/examples/advanced_init/highlight.html

However, I'm looking for something a bit different. I'd like the highlight to be trigged when users click on words outside the table. For example, in the above link, I'd like row #2 to be highlighted when a user click on "visibility" in the text above the table (so it's kind of a hyperlink).

I'm assuming I can find an highlighting plug-in that maybe can do what I need. But before I got there, is there any easy way to do this with DateTables or other table/grid plug-ins?

Thank you!

Here is an example of highlight on click .

It also has an example of deleting a row on click from a link outside the table.

EDIT: This example won't do exacly what you want, but it get's you most of the way there. I have retrofitted the example in this fiddle to do what you want. Here is the "click link to highlight row" part of it:

$("#rowHighlightLink").click(function(event) {
    $(oTable.fnSettings().aoData).each(function (){
        $(this.nTr).removeClass('row_selected');
    });
    $('#example tbody tr').eq(1).addClass('row_selected');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM