jQuery DataTables:未捕获的类型错误:无法读取未定义的属性“mData”。

时间:2022-08-24 14:56:45

Why I'm getting error

为什么我得到的错误呢

Uncaught TypeError: Cannot read property 'mData' of undefined

未捕获的类型错误:无法读取未定义的属性'mData'。

I respect the DataTables requirements (and I also read another topics about my error and I respect every answer and solution). Please help me.

我尊重DataTables需求(我还阅读了关于我的错误的另一个主题,我尊重每个答案和解决方案)。请帮助我。

Here is my php code:

这是我的php代码:

<table class="table table-striped table-bordered table-hover" id="sample_1">
        <thead>
            <tr>
                <th class="table-checkbox">
                    <input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"/>
                </th>
                <th>
                     Utilizator
                </th>
                <th>
                     Nume complet
                </th>
                <th>
                     Clasa
                </th>
                <th>
                     Functia
                </th>
                <th>
                     E-Mail
                </th>
                <th>
                     Ultima logare
                </th>
            </tr>
        </thead>
        <tbody>
            <?
               foreach($data["users"] as $student)
               {
            ?>
            <tr class="odd gradeX">
                <td>
                    <input type="checkbox" class="checkboxes" value="1"/>
                </td>
                <td>
                     <? echo $student["username"]; ?>
                </td>
                <td>
                     <? echo " ".$student["last_name"]." ".$student["first_name"].""; ?>
                </td>
                <td>
                     <? echo getclass($student["class"]); ?>
                </td>
                <td>
                     <?
                     $functie = 0;
                     if($student["role"] == 1)
                     {
                         $functie = 1;
                         echo "Administrator site";
                     }
                     if($student["fctsc"])
                     {
                         $functie = 1;
                         echo "Director";
                     }
                     if($student["diriginte"])
                     {
                         $functie = 1;
                         echo "Diriginte";
                     }
                     if($student["profesor"])
                     {
                         $functie = 1;
                         echo "Profesor";
                     }
                     if($functie == 0)
                         echo "Elev";
                     ?>
                </td>
                <td>
                    <a href="mailto:<? echo $student["email"]; ?>">
                        <? echo $student["email"]; ?>
                    </a>
                </td>
                <td class="center">
                     <? echo $student["lastlogin"]; ?>
                </td>
            </tr>
            <?
               }
            ?>
        </tbody>
    </table>

2 个解决方案

#1


0  

check weather or not all the php echo's are actually outputting something that is not 'NULL' on all rows as DataTables will treat any cell with just NULL as content as non existant and this can also cause that error.
try avoiding direct php output to html table.

检查天气,或者不是所有的php echo都输出了一些不是“空”的东西,因为DataTables将处理任何只包含NULL的单元格,因为内容是不存在的,这也会导致错误。尝试避免将php直接输出到html表。

#2


0  

Usually this error occurs for two reasons:

通常出现这种错误有两个原因:

  • Missing table header.
  • 丢失的表标题。
  • Number of td elements in the table body differs from number of th elements in the table header.
  • 表体中td元素的数量与表头中的th元素的数量不同。

However your HTML code seems to have correct number of columns, see this example.

但是,您的HTML代码似乎有正确的列数,请看这个例子。

See jQuery DataTables: Common JavaScript console errors - TypeError: Cannot read property ‘mData’ of undefined for more information.

参见jQuery DataTables:常见的JavaScript控制台错误——TypeError:不能读取未定义的属性“mData”,以获取更多信息。

#1


0  

check weather or not all the php echo's are actually outputting something that is not 'NULL' on all rows as DataTables will treat any cell with just NULL as content as non existant and this can also cause that error.
try avoiding direct php output to html table.

检查天气,或者不是所有的php echo都输出了一些不是“空”的东西,因为DataTables将处理任何只包含NULL的单元格,因为内容是不存在的,这也会导致错误。尝试避免将php直接输出到html表。

#2


0  

Usually this error occurs for two reasons:

通常出现这种错误有两个原因:

  • Missing table header.
  • 丢失的表标题。
  • Number of td elements in the table body differs from number of th elements in the table header.
  • 表体中td元素的数量与表头中的th元素的数量不同。

However your HTML code seems to have correct number of columns, see this example.

但是,您的HTML代码似乎有正确的列数,请看这个例子。

See jQuery DataTables: Common JavaScript console errors - TypeError: Cannot read property ‘mData’ of undefined for more information.

参见jQuery DataTables:常见的JavaScript控制台错误——TypeError:不能读取未定义的属性“mData”,以获取更多信息。