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

标签 javascript 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>

Datatables 表调试器结果:

http://debug.datatables.net/ogimac

JSFiddle:

http://jsfiddle.net/sajjansarkar/pqzkx1oj/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

关于javascript - 无法读取简单表的未定义属性 'mData',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28030236/

相关文章:

javascript - rows().data() 函数不返回数组

javascript - Excel 导出 - 对列的所有值求和

jQuery.waypoint - 方向未定义

php - jQuery setInterval 防止异步 ajax 调用

javascript - 内部 CSS 不适用于 JS

javascript - Transclude 未注入(inject)链接函数

javascript - 为什么脚本可以一行一行地运行,但不能作为一个整体运行?

来自检查数据表中的行的 RStudio Shiny 列表

javascript - 您可以从函数绑定(bind)中读取连接字符串吗?

javascript - 如何从 JavaScript 中的日期对象获取前一周的第一天?