通过行的data属性使用jquery触发Datatables行上的click事件 [英] Trigger click event on Datatables row with jquery by the row's data attribute

查看:503
本文介绍了通过行的data属性使用jquery触发Datatables行上的click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Datatables 1.10.7.我有一个用Datatables初始化的表,如下所示:

I'm using Datatables 1.10.7. I have a table initialized with Datatables like so:

var user_table = $("#user_table").DataTable({
    "bInfo":false,
    "bLengthChange":false
});

我编写的代码会在某人单击该表中的一行时触发一系列事件,如下所示:

I've written code that triggers a series of events when someone clicks a row in that table like this:

$("#user_table tbody").on('click', 'tr', function () {
    // Series of actions here
});

我的#user_table具有这样的行:

<tr data-user-id="4287">
    <td>Jane Smith</td>
    <td>Senior VP</td>
</tr>
<tr data-user-id="2442">
    <td>John Doe</td>
    <td>HR Manager</td>
</tr>

在页面加载时,我要在与data-user-id匹配动态生成的用户ID列表的行上触发click事件.出于这个问题,我如何在data-user-id为4287的行上触发click事件?请记住,由于有数据表分页,因此该行可能不存在于DOM中-仅存在于Datatables变量中-因此,我需要一个利用Datatables API的解决方案.

On page load, I want to trigger the click event on rows with the data-user-id matching a list of dynamically generated user-id's. For the sake of this question, how would I trigger the click event on the row with a data-user-id of 4287? Keep in mind, because of Datatables pagination, the row may not exist in the DOM - only in the Datatables variables - so I need a solution that utilizes the Datatables API.

推荐答案

使用事件委托之类的

$("#user_table tbody").on('click', 'tr[data-user-id="4287"]', function () {
    // Series of actions here
}).click(); // trigger the click

这篇关于通过行的data属性使用jquery触发Datatables行上的click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆