jQuery Datatable呈现功能不适用于多列

时间:2018-08-28 11:49:40

标签: jquery datatables render

我正在将jQuery Datatable用于服务器端处理,这是我的代码。只要在操作按钮中再添加一列,它就可以正常工作,它只会停止渲染。任何帮助将不胜感激。

 $("#table1").dataTable({

        "processing": true,
        "serverSide": true,
        "info": true,
        "lengthMenu": [[5, 35, 50, -1], [5, 35, 50, "All"]],
        "ajax": {
            "url": "/Customer/customers",
            "type": "POST"
        },
        "columns": [
            { "data": "displayName", "orderable": true },
            { "data": "email", "orderable": true },
            { "data": "state", "orderable": true },                
            {
                "data": "licenses", "orderable": true,
                "render": function (data, type, row) {
                    if (type === 'display') {
                        if (data > 0)
                            return '<i class="fa fa-check" aria-hidden="true"></i>';
                        else
                            return '<i class="fa fa-times" aria-hidden="true"></i>';
                    }
                    return data;
                }
            },
        ]           
    });       

这是我在列数组中的许可证之后添加的带有操作按钮的另一列。

            {
                "data": null, "orderable": false, "render": function (data, type, row) { return '<a href="' + data + '">Download</a>'; }
            },

有人可以告诉我这里出了什么问题吗?

1 个答案:

答案 0 :(得分:1)

在html页面中,如果您的列数少于或少于使用ajax呈现的列数,则会显示错误。正如您所说的,当再添加一列时它显示错误,我认为问题是html页面中的列较少。如果您确定列数,我认为它会起作用。