首页 文章

jQuery DataTables:在IE8中询问列的值是否错误

提问于
浏览
1

我使用jQuery数据表已经过了几天,我在IE8上测试我的代码时遇到了问题,在IE9上运行正常 .

下面是我在IE8中得到的错误的快照:
DataTable Warning msg on IE8

I go to the link mentioned in this message and i came to know that this error comes when datatables asking for a column value and is getting null or undefined value for that.

这是问题,你可以看到他要求第6列(基于0的编号)列值,而我只声明5列,我也发送它们的值 .

下面是数据表初始化的JQuery部分:

if (data != null)
            {
                $('#tdUsersTable').html('');
                /*DataTable Implementation*/
                var table = $('#tblUsers').dataTable({
                    "bFilter": true,
                    "bInfo": false,
                    "bDestroy": true,
                    "bwidth": '100%',
                    "sDom": 't',
                    "sPaginationType": "full_numbers",
                    "order": [[0, "asc"]],
                    "aaData": data,
                    "aoColumns": [
                            { "sTitle": "User ID" },
                            { "sTitle": "User Name" },
                            { "sTitle": "User Role" },
                            { "sTitle": "Company" },
                            { "sTitle": "Active" },
                        ],
                    "oLanguage":
                    {
                        "oPaginate":
                     {
                         "sFirst": "   ",
                         "sLast": "   ",
                         "sNext": "   ",
                         "sPrevious": "   "
                     }
                    }
                });
            }

我将我的数据列表转换为数组并返回JS作为JsonResult . 以下是该数据的快照:

enter image description here

以下是JS中收到的数据的屏幕截图:

enter image description here

Your suggestion are warmly welcome!

1 回答

  • 2

    令人惊讶的答案非常简单,当我开始知道它时我很震惊 . 由于 trailing comma ,上面的代码会引发错误,是的,这就是问题所在 .

    IE 9 是相当聪明的,当它看到最后一个逗号之后没有 title 它忽略它但是当它到达 IE 8 它解释说如果最后有一个 comma ,那么应该有一个列,如果它确实'我将尝试自己制作一个:)

    为了避免此错误,您只需删除 trailing comma ,即 Active 之后,如下所示:

    "aoColumns": [
                            { "sTitle": "User ID" },
                            { "sTitle": "User Name" },
                            { "sTitle": "User Role" },
                            { "sTitle": "Company" },
                            { "sTitle": "Active" }
                        ],
    

相关问题