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')
});
}
});
推荐阅读
-
DataTables提示:DataTables warning: table id=queueInfo_table - Requested unknown parameter 'type' for r
-
DataTables warning: table id=DataTables_Table_0 - Requested unknown paramete
-
DataTables warning: table id=dataTable - Requested unknown parameter 'acceptId' for row 0. For more
-
关于->"DataTables warning: table id=vmtable - Requested unknown parameter 'iP' for row 2, column 2"错误解
-
DataTables warning: table id=dataTable - Requested unknown parameter 'acceptId' for row 0. F...
-
DataTables warning (table id = 'data-table-1'): Requested unknown parameter '9' from the data source