DataTables warning: table id=DataTables_Table_0 - Requested unknown paramete

在使用JQuery DataTable插件在前台进行数据展示时,弹出“DataTables warning: table id=DataTables_Table_0 - Requested unknown parameter '1' for row 0. For more information about this error, please see           http://datatables.net/tn/4”的提示消息。

文章来源:https://blog.csdn.net/u010084781/article/details/40827383

id是table的id,parameter是dataTables请求的参数 

根据{parameter}中parameter的数值类型可将错误因主要分两大类

1.当parameter为Integer类型时:

(1)在<tbody>元素中使用了DataTables不支持的colspan或者rowspan。

(2)用了columns或者columnDefs时指定多了column,也就是说多余html元素中的<th>元素个数。

(3)表格的单元不满足 #cells = #columns * #rows

第一种情况中,Datatables是支持colspan和rowspan的,所以一般不会错吧...

一般常见的就是第二种情况,看看是不是在columns或者columnDefs中是不是写多了{}

2.当parameter为String类型时:

(1)后台返回的json数据中指定的变量不存在

(2)指定的变量值为null

对于第一种情况就是检查“sName”或者“mDataProg”元素中是否拼错变量的名称

对于第二种情况可以使用defaultContent赋予默认值解决。


我的项目中,当取回的数据为0时,th仍参与排序,但tbody中的数据为空,所以出错。因此只需在返回数据不为空时再初始化插件即可。

/**
   * Data Table
   * 
   * @description Traversing all th in thead, if th has 'orderable' class, it's column can be orderd.
   * @requires jquery.dataTables.js
   * @requires dataTables.bootstrap.js
   * @param {bool} searching - Allows the search abilities to be enabled or disabled.
   * @example
   * <table class="table-datatables" data-searching="false">
         <thead>
            <tr>
               <th class="orderable">Delivery Region</th>
               <th class="orderable">Type</th>
               <th>Actions</th>
            </tr>
          </thead>
             <tbody>
                <tr>
                   <td></td>
                   <td></td>
                   <td></td>
                </tr>
             </tbody>
     </table>     
*/
$('.table-datatables').each(function () {
    var $this = $(this),
        columns = [];

    // Traversing all th in thead, if th has 'orderable' class, it's column can be orderd.
    if (!$this.find('.no-items')) {
        $this.find('thead th').each(function () {
            columns.push({ 'orderable': $(this).hasClass('orderable') });
        });

        $this.dataTable({
            columns: columns,
            dom: "f<t>",
            info: false,
            pageLength: Number.MAX_VALUE,
            paging: false,
            order: [],
            searching: $this.data('searching')
        });
    }
});



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值