jQuery dataTable错误无法读取未定义的属性"mData" [英] jQuery dataTable error Cannot read property 'mData' of undefined

查看:89
本文介绍了jQuery dataTable错误无法读取未定义的属性"mData"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下dataTable,其中有6列.

I have following dataTable which has 6 columns.

渲染表格后,我正在初始化 .DataTable().但是出现错误:

After rendering the table I am initializing .DataTable(). But getting the error:

未定义TypeError的'mData':无法读取未定义的属性'mData'

'mData' of undefined TypeError: Cannot read property 'mData' of undefined

正如在几篇文章中所提到的,我已经添加了tfoot但仍然存在错误.

As mentioned in few of the posts , I have added tfoot but still have the error.

$(document).ready(function() {
    $('#pTable').DataTable();
});

<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>

<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

<table id="pTable" class="display" style="width:100%">
    <thead>
        <tr>
            <th>Status</th>
            <th>Name</th>
            <th>NOK</th>
            <th>Phone</th>
            <th>IsEnabled</th>
            <th>Add/Edit</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="text-muted" data-bind="text: ID, visible: false" style="display: none;">288f60e3-0d8f-4a4a-92f9-4f4eeb737909</td>
            <td><span class="label label-accent">Active</span></td>
            <td class="text-muted" data-bind="text: NAME">Buddy1</td>
            <td class="text-muted" data-bind="text: NOK">SomeOne</td>
            <td class="text-muted" data-bind="text: SYMPTOMS">12354475541</td>
            <td class="text-muted">
                <div class="pretty p-round p-fill p-icon">
                    <input type="checkbox" data-bind="value: ISENABLED, checked: ISENABLED, event: { change: $parent.togglePatients}" value="true">
                    <div class="state p-primary">
                        <i class="icon fa fa-check"></i>
                        <label data-bind="text: ISENABLED">true</label>
                    </div>
                </div>
            </td>
            <td class="text-muted">
                <div class="btn-group pull-right">
                    <button data-bind="click: $parent.showPatients" type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#PatientsModal">
                                                    <i class="fa fa-edit"></i> Edit
                                                </button>
                </div>
            </td>
        </tr>
        <tr>

            <td class="text-muted" data-bind="text: ID, visible: false" style="display: none;">ae2dc252-4940-455e-a528-766f3d7d8fe9</td>
            <td><span class="label label-accent">Active</span></td>
            <td class="text-muted" data-bind="text: NAME">Buddy2</td>
            <td class="text-muted" data-bind="text: NOK">SomeOne Else</td>
            <td class="text-muted" data-bind="text: SYMPTOMS">0564654654734</td>
            <td class="text-muted">
                <div class="pretty p-round p-fill p-icon">
                    <input type="checkbox" data-bind="value: ISENABLED, checked: ISENABLED, event: { change: $parent.togglePatients}" value="false">
                    <div class="state p-primary">
                        <i class="icon fa fa-check"></i>
                        <label data-bind="text: ISENABLED">false</label>
                    </div>
                </div>
            </td>
            <td class="text-muted">
                <div class="btn-group pull-right">
                    <button data-bind="click: $parent.showPatients" type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#PatientsModal">
                                                    <i class="fa fa-edit"></i> Edit
                                                </button>
                </div>
            </td>

        </tr>

    </tbody>
    <tfoot>
        <tr>
            <th>Status</th>
            <th>Name</th>
            <th>Patients</th>
            <th>Phone</th>
            <th>IsEnabled</th>
            <th>Add/Edit</th>
        </tr>
    </tfoot>
</table>

推荐答案

您有6个 ,但两行中都有7个 td . th 的数量必须与 td 的数量匹配.添加一个隐藏的 th 修复了该问题

You had 6 ths but had 7 tds in both of the rows. The number of th must match with the number of td. Adding a hidden th fixed it

$(document).ready(function() {
    $('#pTable').DataTable();
});

<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>

<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

<table id="pTable" class="display" style="width:100%">
    <thead>
        <tr>
            <th style="display:none"></th>
            <th>Status</th>
            <th>Name</th>
            <th>NOK</th>
            <th>Phone</th>
            <th>IsEnabled</th>
            <th>Add/Edit</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="text-muted" data-bind="text: ID, visible: false" style="display: none;">288f60e3-0d8f-4a4a-92f9-4f4eeb737909</td>
            <td><span class="label label-accent">Active</span></td>
            <td class="text-muted" data-bind="text: NAME">Buddy1</td>
            <td class="text-muted" data-bind="text: NOK">SomeOne</td>
            <td class="text-muted" data-bind="text: SYMPTOMS">12354475541</td>
            <td class="text-muted">
                <div class="pretty p-round p-fill p-icon">
                    <input type="checkbox" data-bind="value: ISENABLED, checked: ISENABLED, event: { change: $parent.togglePatients}" value="true">
                    <div class="state p-primary">
                        <i class="icon fa fa-check"></i>
                        <label data-bind="text: ISENABLED">true</label>
                    </div>
                </div>
            </td>
            <td class="text-muted">
                <div class="btn-group pull-right">
                    <button data-bind="click: $parent.showPatients" type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#PatientsModal">
                                                    <i class="fa fa-edit"></i> Edit
                                                </button>
                </div>
            </td>
        </tr>
        <tr>

            <td class="text-muted" data-bind="text: ID, visible: false" style="display: none;">ae2dc252-4940-455e-a528-766f3d7d8fe9</td>
            <td><span class="label label-accent">Active</span></td>
            <td class="text-muted" data-bind="text: NAME">Buddy2</td>
            <td class="text-muted" data-bind="text: NOK">SomeOne Else</td>
            <td class="text-muted" data-bind="text: SYMPTOMS">0564654654734</td>
            <td class="text-muted">
                <div class="pretty p-round p-fill p-icon">
                    <input type="checkbox" data-bind="value: ISENABLED, checked: ISENABLED, event: { change: $parent.togglePatients}" value="false">
                    <div class="state p-primary">
                        <i class="icon fa fa-check"></i>
                        <label data-bind="text: ISENABLED">false</label>
                    </div>
                </div>
            </td>
            <td class="text-muted">
                <div class="btn-group pull-right">
                    <button data-bind="click: $parent.showPatients" type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#PatientsModal">
                                                    <i class="fa fa-edit"></i> Edit
                                                </button>
                </div>
            </td>

        </tr>

    </tbody>
    <tfoot>
        <tr>
            <th>Status</th>
            <th>Name</th>
            <th>Patients</th>
            <th>Phone</th>
            <th>IsEnabled</th>
            <th>Add/Edit</th>
        </tr>
    </tfoot>
</table>

这篇关于jQuery dataTable错误无法读取未定义的属性"mData"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆