简单的表与colspan给出数据表的错误

时间:2018-02-21 21:54:53

标签: datatables

我有这个简单的html表

<table id="mytable">
    <thead>
        <tr>
            <th>Name</th>
            <th colspan="2">Actions</th>
        </tr>
        <tr>
            <th>Delete</th>
            <th>Update</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>MyName</td>
            <td onclick="delete()">X</td>
            <td onclick="update()">U</td>
        </tr>
    </tbody>
</table>
<script>
    $(document).ready(function(){
        $('#mytable').DataTable();
    });
</script>

如果我在浏览器上打开它,我会

"Cannot read property 'mData' of undefined".

我不知道问题出在哪里。我正在关注官方示例:https://datatables.net/examples/basic_init/complex_header.html

谢谢大家!

1 个答案:

答案 0 :(得分:1)

你的html有无与伦比的列数,请注意标题的第一行有colspan而第二行没有。

你能做的就是提供一个rowpan。

<thead>
    <tr>
        <th rowspan="2">Name</th>
        <th colspan="2">Actions</th>
    </tr>
    <tr>
        <th>Delete</th>
        <th>Update</th>
    </tr>
</thead>

这里是指向复杂标题的数据表示例的链接。 https://datatables.net/examples/basic_init/complex_header.html