【问题标题】:jQuery.Deferred exception: Cannot set property '_DT_CellIndex' of undefined TypeError: Cannot set property '_DT_CellIndex' of undefinedjQuery.Deferred 异常:无法设置未定义的属性“_DT_CellIndex”类型错误:无法设置未定义的属性“_DT_CellIndex”
【发布时间】:2019-10-14 19:16:55
【问题描述】:

我在数据表中遇到了这个错误。我已正确包含所有头文件,但不知道为什么会发生此错误。

jQuery.Deferred 异常:无法设置属性“_DT_CellIndex” 未定义类型错误:无法设置未定义的属性“_DT_CellIndex”

我尝试了一些解决方案,例如没有空行、相同数量的标题和列等,但这里没有任何效果。请帮忙。

<div class="row">
   <div class="col-md-12">
      <table class="table table-striped table-hover datatable">
         <thead>
            <tr>
               <th>Target</th>
               <th>Goal</th>
               <th>Target Status</th> 
               <th>Date</th>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td>Demo Target</td>
               <td>Some Goal</td>
               <td>Some Status</td>
               <td>Some Date</td>
            </tr>
         </tbody>
      </table>
   </div>
</div>

这是我的 js 代码-

   $(document).ready(function(){
   $.extend( $.fn.dataTable.defaults, {
       autoWidth: false,
       dom: '<"datatable-header"fBl><"datatable-scroll-wrap"t><"datatable-footer"ip>',
       language: {
           search: '<span>Filter:</span> _INPUT_', 
           searchPlaceholder: 'Search...',
           lengthMenu: '<span>Show:</span> _MENU_',
           paginate: { 'first': 'First', 'last': 'Last', 'next': $('html').attr('dir') == 'rtl' ? '&larr;' : '&rarr;', 'previous': $('html').attr('dir') == 'rtl' ? '&rarr;' : '&larr;' }
       }
   });

   var table = $('.datatable').DataTable({
       buttons: {            
           buttons: [
               {
                   extend: 'copyHtml5',
                   className: 'btn btn-light',
                   exportOptions: {
                       columns: [ 0, ":visible" ]
                   }
               },
               {
                   extend: 'excelHtml5',
                   className: 'btn btn-light',
                   exportOptions: {
                       columns: [ 0, ":visible" ]
                   }
               },
               {
                   extend: 'pdfHtml5',
                   className: 'btn btn-light',
                   exportOptions: {
                       columns: [ 0, ":visible" ]
                   }
               },
               {
                   extend: 'colvis',
                   text: '<i class="icon-three-bars"></i>',
                   className: 'btn bg-blue btn-icon dropdown-toggle'
               }
           ]
       },
       "aaSorting": []
   });

【问题讨论】:

  • 为了让我们能够更好的为您提供帮助,我们还需要在您的js代码中看到数据表的初始化。
  • @Alex 初始化数据表已更新。提前致谢。

标签: html datatable


【解决方案1】:

我认为您的代码没有问题,它对我来说运行良好。我会检查您的 html 是否有重复项,即在另一个位置使用 .datatable 类并使用 id 来启动它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-23
    • 2018-09-18
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    • 2017-02-19
    • 2020-10-21
    相关资源
    最近更新 更多