无法读取属性' mData'未定义的简单表格

时间:2015-01-19 17:21:53

标签: javascript jquery datatables jquery-datatables

请指导我做错了什么!

使用Javascript:

<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<script>
    $(function() {

        $('#example').dataTable({
            "scrollY" : 800,
            "scrollX" : true,
            "paging" : false,
            "ordering" : true,
            //"order": [[ 3, "desc" ]],
            "info" : true,
            "columns": [{
                "orderDataType": "dom-text-numeric",
                "orderDataType": "dom-text-numeric",
                "orderDataType": "dom-text-numeric",
                "orderDataType": "dom-text-numeric",
                "orderDataType": "dom-text-numeric",
                "orderDataType": "dom-text-numeric"
            }]
        });
    });
</script>

HTML:

<table id="example" style="border-collapse:collapse;" border="1">
        <thead>         
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>

        <tbody>


            <tr>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>
            <tr>
                <td>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$170,750</td>
            </tr>
       </tbody>
    </table>

数据表表调试器结果:

http://debug.datatables.net/ogimac

的jsfiddle:

http://jsfiddle.net/sajjansarkar/pqzkx1oj/1/

1 个答案:

答案 0 :(得分:1)

<script>
    $(function() {

        $('#example').dataTable({
            "scrollY" : 800,
            "scrollX" : true,
            "paging" : false,
            "ordering" : true,
            //"order": [[ 3, "desc" ]],
            "info" : true,
            "columns": [
                {"orderDataType": "dom-text-numeric"},
                {"orderDataType": "dom-text-numeric"},
                {"orderDataType": "dom-text-numeric"},
                {"orderDataType": "dom-text-numeric"},
                {"orderDataType": "dom-text-numeric"},
                {"orderDataType": "dom-text-numeric"}
            ]
        });
    });
</script>

每个orderDataType都需要在自己的对象中。 https://datatables.net/reference/option/columns.orderDataType