JQuery DataTables: Uncaught TypeError: Cannot read property 'mData' from undefined

Why am I getting an error

Uncaught TypeError: Unable to read property 'mData' from undefined

I respect the requirements of DataTables (and also read another topic about my mistake, and I respect every answer and solution). Please help me.

Here is my PHP code:

<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> 
+3
source share
2 answers

check the weather or not all php echoes actually output something that is not "NULL" for all rows, since DataTables will only process any cell with NULL, since the content does not exist, and this may also cause this error. try to avoid direct php output to html table.

0
source

This error usually occurs for two reasons:

  • The table header is missing.
  • The number of td elements in the table structure is different from the number of th elements in the table header.

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

See jQuery DataTables: Common JavaScript Console Errors - TypeError: Cannot read the mData undefined property for more information.

0
source

Source: https://habr.com/ru/post/987641/


All Articles