报错如图:
解决方法见官网:https://datatables.net/manual/tech-notes/4
摘要如下:
When {parameter}
is an integer, DataTables is looking for data from an array. This is usually the case when using DOM sourced data (i.e. the data for the table is read automatically from the document). In this circumstance the requested data doesn't exist in source array - likely because the array isn't long enough. This can occur if:
colspan
or rowspan
in the tbody
of the table, which is not supported by DataTables.columns
or columnDefs
you have specified more columns than there are in the HTML#cells = #columns * #rows
(i.e. there are more columns defined in the header than in the table body, or vice-versa).在我的代码里就是这种情况,参数为Integer 类型。还有参数为:String 、 function 类型的见官网解决方法。
解决方法摘要如下 :
Resolution
The key to resolving this error, is to ensure that DataTables has all of the data that is required. Specifically, check the following:
colspan
and rowspan
have not been used in the tbody
of the table.#cells = #columns * #rows
is satisfied.columns
ensure that you have specified exactly the number of columns that are present in the HTML for the table.columns.render
or columns.data
ensure that they are returning a value (no return in Javascript is the same as returning undefined
which will result in this error).null
or undefined
datanull
and undefined
values in a data source absolutely are valid and very often useful. DataTables warns about the use of them by default, as the majority of the time they are not intended for display - for example, rather than showing null in the table, you might want to show Not yet set, or simply an empty string (empty cell). For this, DataTables has a columns.defaultContent
option.
With columns.defaultContent
set, any null
or undefined
value will be replaced with the value specified. No warning will be shown in this circumstances.
官网解决 例子:https://datatables.net/reference/option/columns.defaultContent
摘要如下:
这个例子对于我这种情况(参数为Integer 且为 null )的解决方法就是给该值设置 默认值。 如图在代码中加上 " defaultContent " : " " 就OK了。默认值的具体内容可以自由设置。