【问题标题】:Why I cant access the texts of the hidden columns in this DataTable?为什么我无法访问此 DataTable 中隐藏列的文本?
【发布时间】:2020-08-13 11:53:43
【问题描述】:

问题

我有一个数据表,我正在尝试访问每一行中每个单元格的文本,以便打印文本并显示所有元素,包括隐藏的元素。

访问数据库的代码

     $("#myTable").on("click", ".edit_admin", function(e) {
                const $row = $(this).closest("tr");
                window.rowindex = $row;                
                const admin_phone = $row.find(".admin_phone").text().trim();
                const admin_email = $row.find(".admin_email").text().trim();
                const admin_location_name = $row.find(".admin_location_name").text().trim();
                const admin_location_id = $row.find(".admin_location_id").text().trim(); //hidden column
                const admin_id = $row.find(".admin_id").text().trim(); //hidden column
     });

问题信息

所有其他元素都可以访问,我可以打印它们的文本,但它不显示隐藏的任何内容,为什么?

我在初始化 DataTable 时隐藏了它们:

    ...
     {
       "targets": [3,4],
       "visible": false
     }
    ...

问题

我该如何解决这个问题?

【问题讨论】:

    标签: javascript html jquery datatable


    【解决方案1】:

    您可以使用colum-header 来使用DataTable 中的隐藏值,如下所示。

    $("#myTable").on("click", ".edit_admin", function(e) {
      const $row = $(this).closest("tr");
      const data = $('#myTable').DataTable().row($row).data();
      const admin_phone = data['colum-header']; // May be this is phone-number which is not shown in your code
      //hidden column
      const admin_id = data['colum-header-id']; // May be column header is ID , it's not shown in your code
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 2015-07-12
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      • 2021-03-27
      • 2021-09-21
      相关资源
      最近更新 更多