【问题标题】:Cannot read property 'mData' of undefined for a simple table无法读取简单表的未定义属性“mData”
【发布时间】:2015-01-19 17:21:53
【问题描述】:

请指导我做错了什么!

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/

【问题讨论】:

    标签: javascript jquery datatables jquery-datatables


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-12
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 2015-07-19
      相关资源
      最近更新 更多