简体   繁体   English

获取行数据的功能仅在数据表中的响应模式下有效

[英]Function to get row data works only in responsive mode in Datatables

When I click on the image in Reponsive mode, it will return the row data in console. 当我在响应模式下单击图像时,它将在控制台中返回行数据。 But in normal view I get Undefined error. 但是在正常情况下,我得到未定义错误。

         var table =  $('.dataTable').DataTable({
                "responsive": true,                                   
                "columnDefs": [{
                    "targets": 4,
                    "data": null,
                    "render": function (data, type, full, meta) {
                        if (type === 'display') {
                            data = "<a href='#' width='30px' class='editMe' data='" + full[0] + "'><img src='/images/edit.png' width='30px' /></a>";
                        }
                        return data;
                    }
                } ,

                {
                       "targets": 0,
                       "visible": false,
                       "searchable": false
                }]
           });


           $('.dataTable').on('click', '.editMe', function () {

               console.log(table.row(this).data());

           });

Use the code below instead: 使用以下代码代替:

$('.dataTable').on('click', '.editMe', function () {
    var $row = $(this).closest('tr');
    if($row.hasClass('child')){ $row = $row.prev(); }
    console.log(table.row($row).data());
});

See this example for code and demonstration. 有关代码和演示,请参见此示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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