简体   繁体   English

数据表(行详细信息):未被捕获的TypeError:无法读取未定义的属性'style'

[英]Datatables (Row Details): Uncaught TypeError: Cannot read property 'style' of undefined

im trying to implement the datatables row details 我正在尝试实现数据表行详细信息

this is my table that has an id of "user_datas" 这是我的ID为“ user_datas”的表

<table id="user_datas" class="table table-bordered table-striped" width="100%">
     <thead>
       <tr>
         <th>NAME</th>
         <th>SEX</th>
         <th>BIRTHDATE</th>
         <th>AGE</th>
       </tr>
     </thead>
  </table>

this is the code that comes from the datatable documentation which im trying to implement 这是我试图实现的数据表文档中的代码

function format ( d ) {
    return 'Name: '+d.name+'<br>'+
   'Gender: '+d.sex+'<br>'+
        'The child row can contain any data you wish, including links, images, inner tables etc.';
}

$(document).ready(function() {
    var dataTable = $('#user_datas').DataTable({
      "processing":true,
      "serverSide":true,
      "order":[],
      "ajax":{
        url:"../controller/fetch_senior_citizen.php",
        type:"POST"
      },

      "columns": [
          {
            "class":          "details-control",
            "orderable":      false,
            "data":           null,
            "defaultContent": ""
          },
          { "data": "name" },
          { "data": "sex" },
          { "data": "birthdate" },
          { "data": "age" }
      ],
        "order": [[1, 'asc']]
    });

     // Array to track the ids of the details displayed rows
    var detailRows = [];

    $('#user_datas tbody').on( 'click', 'tr td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = dataTable.row( tr );
        var idx = $.inArray( tr.attr('id'), detailRows );

        if ( row.child.isShown() ) {
            tr.removeClass( 'details' );
            row.child.hide();

            // Remove from the 'open' array
            detailRows.splice( idx, 1 );
        }
        else {
            tr.addClass( 'details' );
            row.child( format( row.data() ) ).show();

            // Add to the 'open' array
            if ( idx === -1 ) {
                detailRows.push( tr.attr('id') );
            }
        }
    } );

    // On each draw, loop over the `detailRows` array and show any child rows
    dataTable.on( 'draw', function () {
        $.each( detailRows, function ( i, id ) {
            $('#'+id+' td.details-control').trigger( 'click' );
        } );
    } );                    
});

and this is some of my code from fetch_senior_citizen.php 这是我来自fetch_senior_citizen.php的一些代码

foreach($result as $row)
{
    $name = clean($row["f_name"])." ".clean($row["m_name"])." ".clean($row["l_name"]);
    $sub_array = array();
    $sub_array["id"] = $row['id'];
    $sub_array["name"] = $name;
    $sub_array["sex"] = strtoupper($row["sex"]);
    $sub_array["birthdate"] = $row["birthdate"];
    $sub_array["age"] = $row["age"];
    $data[] = $sub_array;
}

$output = array(
    "draw"              =>  intval($_POST["draw"]),
    "recordsTotal"      =>  $filtered_rowsz,
    "recordsFiltered"   =>  get_total_all_records4(),
    "data"              =>  $data
);
echo json_encode($output, JSON_PRETTY_PRINT);

the error that im currently facing is Uncaught TypeError: Cannot read property 'style' of undefined but if i remove this code 我当前面临的错误是未捕获的TypeError:无法读取未定义的属性“样式”,但是如果我删除此代码

{
    "class": "details-control",
    "orderable": false,
    "data": null,
    "defaultContent": ""
}

Everythings work fine. 一切正常。 But my table doesnt have row details 但是我的表没有行详细信息

Problem solved! 问题解决了! i just forgot to put an empty th on thead 我只是忘了把空虚的东西

暂无
暂无

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

相关问题 DataTables子行-未捕获的TypeError:无法读取未定义的属性“ show” - DataTables Child Row - Uncaught TypeError: Cannot read property 'show' of undefined 未捕获的类型错误:无法读取未定义的属性“样式”? - Uncaught TypeError: Cannot read property 'style' of undefined? 未捕获的 TypeError 无法读取未定义的属性“样式” - Uncaught TypeError Cannot read property 'style' of undefined DataTables:Uncaught TypeError:无法读取未定义的属性“按钮” - DataTables: Uncaught TypeError: Cannot read property 'buttons' of undefined dataTables“Uncaught TypeError:无法读取未定义的属性&#39;nTr&#39;” - dataTables “Uncaught TypeError: Cannot read property 'nTr' of undefined” 数据表:未捕获的TypeError:无法读取未定义的属性&#39;parentNode&#39; - Datatables: Uncaught TypeError: Cannot read property 'parentNode' of undefined DataTables - 未捕获的TypeError:无法读取未定义的属性“长度” - DataTables - Uncaught TypeError: Cannot read property 'length' of undefined 数据表:未捕获的类型错误:无法读取未定义的属性“唯一” - DataTables: Uncaught TypeError: Cannot read property 'unique' of undefined DataTables:未捕获的TypeError:无法读取未定义的属性&#39;mData&#39; - DataTables: Uncaught TypeError: Cannot read property 'mData' of undefined 数据表 jquery - 未捕获的类型错误:无法读取未定义的属性“显示” - datatables jquery - Uncaught TypeError : CAnnot read property 'show' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM