首页 > 解决方案 > 如何在响应式显示的一行上添加一个类?

问题描述

我正在尝试在用户单击的行上添加一个类。为此,我使用responsive-display事件。

$(function () {
    $('#people-waiting-send-up').DataTable().on('responsive-display', function (e, datatable, row, showHide, update) {
        row.addClass('opened')
    });
});

row不是 jQuery 对象,所以addClass()不起作用。我应该怎么做?

标签: javascriptjquerydatatables

解决方案


使用row.index,我可以找到用户单击的行,并为其添加一个类:

$(function () {
    $('#people-waiting-send-up').DataTable().on('responsive-display', function (e, datatable, row, showHide, update) {
        $(datatable.row(row.index()).node()).addClass('opened');
    });
});

推荐阅读