DataTables: Cannot read property style of undefined

前端 未结 11 642
时光取名叫无心
时光取名叫无心 2020-12-23 15:42

I am getting this error with the following:

jquery.dataTables.js:4089 Uncaught TypeError: Cannot read property \'style\' of undefined(…)
_fnCalculateColumnWi         


        
相关标签:
11条回答
  • 2020-12-23 16:16

    The solution is pretty simple.

      <table id="TASK_LIST_GRID" class="table table-striped table-bordered table-hover dataTable no-footer" width="100%" role="grid" aria-describedby="TASK_LIST_GRID_info">
      <thead>
        <tr role="row">
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Solution</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Status</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Category</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Type</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Due Date</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Create Date</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Owner</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Comments</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Mnemonic</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Domain</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Approve</th>
          <th class="sorting" tabindex="0" aria-controls="TASK_LIST_GRID" rowspan="1" colspan="1">Dismiss</th>
        </tr>
      </thead>
      <tbody></tbody>
    </table>

                    TASKLISTGRID = $("#TASK_LIST_GRID").DataTable({
                        data : response,
                        columns : columns.AdoptionTaskInfo.columns,
                        paging: true
                    });
                    
                    //Note: columns : columns.AdoptionTaskInfo.columns has at least a column not definded in the <thead>

    Note: columns : columns.AdoptionTaskInfo.columns has at least a column not defined in the table head

    0 讨论(0)
  • 2020-12-23 16:18

    most of the time it happens when the table header count and data cel count is not matched

    0 讨论(0)
  • 2020-12-23 16:24

    I resolved this error, by replacing the src attribute with https://code.jquery.com/jquery-3.5.1.min.js, the problem is caused by the slim version of JQuery.

    0 讨论(0)
  • 2020-12-23 16:25

    It can also happen when drawing a new (other) table. I solved this by first removing the previous table:

    $("#prod_tabel_ph").remove();

    0 讨论(0)
  • 2020-12-23 16:28

    The problem is that the number of <th> tags need to match the number of columns in the configuration (the array with the key "columns"). If there are fewer <th> tags than columns specified, you get this slightly cryptical error message.

    (the correct answer is already present as a comment but I'm repeating it as an answer so it's easier to find - I didn't see the comments)

    0 讨论(0)
提交回复
热议问题