datatable,获取隐藏单元格的值

时间:2022-08-24 11:42:09

I have a DataTables Table, and I want to be able to get the value of the first td, when the tr is clicked on. I have set the visibility of this td to false.

我有一个DataTables表,我希望能够得到第一个td的值,当tr被点击的时候。我将这个td的可见性设置为false。

Edit: because the two answers so far are assuming I can click on the cell I want. I cannot click on the cell I need the value of.

编辑:因为到目前为止这两个答案都是假设我可以点击我想要的单元格。我不能单击我需要的单元格值。

$(document).ready(function() {

    var table = $('#example').DataTable({ 
        select: false,
        "columnDefs": [{
            className: "ID", 
            "targets":[0],
            "visible": false,
            "searchable":false
        }]
    });//End of create main table



    $('#example tbody').on( 'click', 'tr', function () {

        cellValue =     //code to get the cell value 
        console.log(cellValue);

    });

});

I have seen a lot of examples using the older DataTables method, fnGetColumnData, but am not sure how to implement the newer cell.data().

我已经看到了许多使用旧的datables方法fnGetColumnData的示例,但是我不确定如何实现新的cell.data()。

Can anyone help me out?

有人能帮帮我吗?

1 个解决方案

#1


3  

To achieve expected result and get hidden column data by using row(this).data()

要实现预期的结果并通过使用row(this).data()获取隐藏的列数据

  $('#example tbody').on( 'click', 'tr', function () {
     alert(table.row( this ).data()[0]); 
  });

http://codepen.io/nagasai/pen/kXyazm

http://codepen.io/nagasai/pen/kXyazm

Above mentioned code will return complete row data both hidden and visible data and mention the position of the hidden column position

上面提到的代码将返回完整的行数据,包括隐藏的和可见的数据,并提到隐藏列的位置

#1


3  

To achieve expected result and get hidden column data by using row(this).data()

要实现预期的结果并通过使用row(this).data()获取隐藏的列数据

  $('#example tbody').on( 'click', 'tr', function () {
     alert(table.row( this ).data()[0]); 
  });

http://codepen.io/nagasai/pen/kXyazm

http://codepen.io/nagasai/pen/kXyazm

Above mentioned code will return complete row data both hidden and visible data and mention the position of the hidden column position

上面提到的代码将返回完整的行数据,包括隐藏的和可见的数据,并提到隐藏列的位置