Jquery - table.row(tr) is undefined

Jquery - table.row(tr) is undefined

本文关键字:is undefined tr table row Jquery      更新时间:2023-09-26

我正在尝试使用datatablesjQuery插件,但遇到了问题,我不知道为什么会发生这种情况。

我的桌子上有一个动作栏:

table = $('#' + tableId).DataTable({
    processing: true,
    serverSide: true,
    ajax: dataUrl,
    deferRender: true,
    esponsive: true,
    pageLength: 15,
    pagingType: "full_numbers",
    stateSave: true,
    filter: true,
    language: {
        paginate: {
            next: " ",
            previous: " ",
            first: "First",
            last: "Last"
        }
    }
$(document).on('click', ".details-control2", function () {
    var tr = $(this).parent().parent(); // <-- finds the correct tr
    var row = table.row(tr);
    console.log(row); // <-- undefined, why??? 'table' is recognized correctly
}

更新-表格的HTML:

<tbody>
<tr id="row_0" role="row" class="odd">
    <td class="sorting_1"></td>
    <td><input type="image" src="/images/plus.png" class="details-control2"> </td>
    <td>rasplap.dll</td>
    <td></td>
    <td>WIN7X86</td>
    <td>DLL</td>
    <td>4/4/2015 3:45:45 PM</td>
    <td>4/4/2015 5:38:32 PM</td>
    <td>0</td>
</tr>
</tbody>

有什么建议吗?如果缺少任何信息,请告诉我。

尝试

$(this).parentNode.parentNode;

数据表论坛对此进行了讨论:http://datatables.net/forums/discussion/11836/getting-data-on-click

我希望这能有所帮助:

$(document).on('click', ".details-control2", function () {
    var row = $(this).closest('tr'),
        data = table._(row),
        id = data[0].id;  
    //do something with your id
    //Get the position of the current data from the node
    var aPos = table.fnGetPosition(id);//you many need to use ('#' + id)
    // Get the data array for this row
    var aData = table.fnGetData(id[0]);//you many need to use ('#' + id[0])
});