首页 > 解决方案 > 添加复选框列显示错误:“为第 0 行,第 0 列请求未知参数‘0’”

问题描述

我需要添加一个新列以显示一个复选框以进行进一步的表操作,并且我不断收到“第 0 行第 0 列的请求的未知参数 '0'”。</p>

以前,数据表的代码是这样的(并且没有错误):

    tabla = $('#table').DataTable({
            /** Default Configuration, it is read from a file but i'll show some of the values in case it is needed for a better understanding of the problem  **/
            destroy: true,
            pagingType : "full_numbers",
            paging : true,
            lengthChange : true,
            lengthMenu : /*Array*/,
            pageLength : 25,
            serverSide : true,
            ordering : false,
            searching : true,
            processing : true,
            deferRender : true,
            fnDrawCallback : configDefectoDatatables.fnDrawCallback,
            /** AJAX **/
            ajax : {
                beforeSend: beforeSend,
                url : urlAjax,
                type : "POST",
                timeout : 50000,
                error : errorNotificationFunction
            },
            /** Column Definition **/
            columns : [ {
                class : "idClass",
                data : "id",
                defaultContent : "",
                targets : 0
            }, {
                class : "requestClass",
                data : "request",
                defaultContent : "",
                targets : 1
            },
           /**Some other columns with the same format **/
           {...}]

我的尝试是在其他 HTML 文件之前创建一个新<th>的,并将以下列添加为新的“0”(并将另一列的目标向上移动一个位置)

这确实在每一行上显示了复选框,并启用了多选功能,但它仍然显示提到的错误

{
    orderable: false,
    className: 'select-checkbox',
    targets:   0
}

而且,所需的选择属性如下

select: {
            style:    'multi',
            selector: 'td:first-child'
        }

我正在尝试一些随机的废话,发现添加 adata : null会使错误消失,但添加了一个新问题(它显示了一个[Object object]和顶部的复选框)

{
    orderable: false,
    data : null,
    className: 'select-checkbox',
    targets:   0
}

我知道由于我缺乏技术知识,这可能(并且可能会)是一个简单的问题,但我自己没有得到任何解决方案。

标签: javascriptdatatables

解决方案


好的,所以,这可能不是最好的解决方案,但只需像这样设置列即可修复错误

{
    data : null,
    defaultContent : "",
    className : 'select-checkbox',
    targets : 0
}

推荐阅读