简体   繁体   中英

Jquery - table.row(tr) is undefined

I am trying to use datatables jQuery plugin , but having trouble and I can't figure out why is that happening.

I got an action column on my table:

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
}

Update - Table's 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>

Any suggestions? Please tell me if any info is missing.

尝试

$(this).parentNode.parentNode;

This is discussed in datatable forum: http://datatables.net/forums/discussion/11836/getting-data-on-click

I hope this helps:

$(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])
});

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