未捕获的TypeError:无法读取未定义的属性"aDataSort"

Abd*_*nan 8 javascript jquery jquery-datatables

我正在进行分页,我正在使用DataTables插件,在某些表上它可以正常工作,但在某些表上它会出错:

未捕获的TypeError:无法读取未定义的属性"aDataSort"

我的页面脚本如下:

$(document).ready(function() {
     $('.datatable').dataTable( {
        "scrollY":        "200px",
        "scrollCollapse": true,
        "info":           true,
        "paging":         true
    } );
} );
Run Code Online (Sandbox Code Playgroud)

// HTML代码

<table class="table table-striped table-bordered datatable">
   <thead>
        <tr>
          <th><?php echo lang('date_label')?></th>
          <th><?php echo lang('paid_label')?></th>
          <th><?php echo lang('comments_label');?></th>
        </tr>
   </thead>
   <tbody>
      <?php foreach ($payments as $pay): ?>
      <tr>
        <td><?php echo dateformat($pay['time_stamp'], TRUE);?></td>
        <td><?php echo format_price($pay['amount']);?></td>
        <td><?php echo $pay['note'];?></td>
      </tr>
      <?php endforeach?>
   </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

不知道问题是怎么来的,我知道这是非常常见的错误,但我搜索并发现没有任何支持我的问题.
有谁知道解决方案?

Nik*_* M. 9

在您的代码中使用类似下面的内容来禁用排序DataTables(改编自我使用最新的项目DataTables)

$(document).ready(function() {
     $('.datatable').dataTable( {
        'bSort': false,
        'aoColumns': [ 
              { sWidth: "45%", bSearchable: false, bSortable: false }, 
              { sWidth: "45%", bSearchable: false, bSortable: false }, 
              { sWidth: "10%", bSearchable: false, bSortable: false } 
        ],
        "scrollY":        "200px",
        "scrollCollapse": true,
        "info":           true,
        "paging":         true
    } );
} );
Run Code Online (Sandbox Code Playgroud)

aoColumns阵列描述了每一列和其宽度sortable的属性,根据需要调整为自己的表(数字的)列.


pgc*_*can 5

我遇到了同样的问题,后来在columnDefs下的“ targets”属性中发现了键入错误。参见以下示例,

下面的错误代码,

{
 "name": "firstName",
 "target": [1],
 "visible": false
}
Run Code Online (Sandbox Code Playgroud)

更正-目标中缺少's':(

{
 "name": "firstName",
 "targets": [1],
 "visible": false
}
Run Code Online (Sandbox Code Playgroud)

当某些原因导致未初始化列时,看起来会发生此错误。我检查了在这种情况下未触发事件'preInit.dt'。

希望这对某人有帮助。