Cannot read property 'length' of undefined

Cannot read property 'length' of undefined

Black KasperBlack Kasper Posts: 11Questions: 2Answers: 0

hello

i have a table the table that i have populate with php , it has 8 (columns) with the 8 (rows) , but it gives me the error on console it says "
Uncaught TypeError: Cannot read property 'length' of undefined
at Ka (jquery.dataTables.min.js:23)
at HTMLTableRowElement.<anonymous> (jquery.dataTables.min.js:16)
at jquery-1.12.4.js:142
at Function.map (jquery-1.12.4.js:484)
at jQuery.fn.init.map (jquery-1.12.4.js:141)
at oa (jquery.dataTables.min.js:16)
at e (jquery.dataTables.min.js:92)
at HTMLTableElement.<anonymous> (jquery.dataTables.min.js:93)
at Function.each (jquery-1.12.4.js:370)
at jQuery.fn.init.each (jquery-1.12.4.js:137)
"

what's the problem ?

Answers

  • kthorngrenkthorngren Posts: 20,313Questions: 26Answers: 4,771
    edited June 2017

    My guess is the data returned from the server doesn't line up with the 8 columns defined. Its hard to say without seeing your code and the data. Do you get a pop up message with a link to a technote? If so, follow the steps to troubleshoot the issue.

    It could be that something in your Datatables init code is referencing a column number outside of the column defined.

    If not at least post a debug output:
    https://datatables.net/manual/tech-notes/10

    Kevin

  • Black KasperBlack Kasper Posts: 11Questions: 2Answers: 0
    edited June 2017

    this is my debug output

    http://debug.datatables.net/ocibuq

    and this is my code

    <table id="myTable" class="table table-fixed">
    
              <thead>
              <th>Student ID</th>
              <th>Student Name</th>
             
                 
                  <?php
                  $countmodel=0;
                  $JustForCountModule=0;
                  $counter=5;
                  $Count_Curves=0;
                  $Total_Module_Mark=0;
                  $Sum_Each_Module=0;
                  $Select1 = mysqli_query($con,"SELECT grades.ModelID,model.modelname,model.modelcode from grades INNER JOIN student ON grades.StudentID = student.StudentID INNER JOIN model ON grades.ModelID = model.ModelID Where DepartmentName='".$dep."' group by modelid");
                  while($Row = mysqli_fetch_array($Select1))
                  {         
                    $countmodel++;
                      $JustForCountModule++;
                    echo "<th >".$Row["modelname"]."</th>";
                    
                    
                  }
                  // Get Total Mark Of Module 
                  $Total_Module_Mark = 50 * $countmodel;
                 
                  $countmodel = $countmodel + 1;
                  
                  ?>
                  <th>Needed Marks</th>
              </tr>
              </thead><tbody>
                  <tr><?php
                $Select2 = mysqli_query($con,"SELECT student.StudentID,grades.Total1,student.StudentName,student.DepartmentID from grades INNER JOIN student ON grades.StudentID = student.StudentID INNER JOIN model ON grades.ModelID = model.modelid Where DepartmentID='".$depid."'");
                  while($Row2 = mysqli_fetch_array($Select2))
                  {
                    
                    $counter++;
                    
                    
                    $Count_Curves++;
                    if( $counter < $countmodel)
                    {   
                        
                       if($Row2["Total1"] > 50)
                       {
                            
                            echo "<td>".$Row2["Total1"]."</td>";
                                            
                       }    
                       else
                       {
                            echo "<td style='background-color:#bfbfbf;color:white;color:black;'>".$Row2["Total1"]."</td>";
                                $Sum_Each_Module = $Sum_Each_Module + (50 - $Row2["Total1"]);
                       }
                     
                       
                       
                    }
                    
                    else
                    {
                        if( $Row2["Total1"] < 50)
                        {
                        echo "<tr></tr>";   
                        echo "<td>".$Row2["StudentID"]."</td>";
                        echo "<td>".$Row2["StudentName"]."</td>";
                        echo "<td style='background-color:#bfbfbf;'>".$Row2["Total1"]."</td>";
                        $Sum_Each_Module = $Sum_Each_Module + (50 - $Row2["Total1"]);
                        
                        }
                        else
                        {
                            echo "<tr></tr>";   
                            echo "<td>".$Row2["StudentID"]."</td>";
                            echo "<td>".$Row2["StudentName"]."</td>";
                            echo "<td>".$Row2["Total1"]."</td>";
                            
                        }
                        $counter=1;     
                        
                    }
                    if($counter == $JustForCountModule)
                       {
                           
                           if ($Sum_Each_Module > 1)
                           {
                           echo "<td  style='background-color:#e9ffd3;'>".$Sum_Each_Module."</td>";
                           $Sum_Each_Module=0;
                           }
                           else
                           {
                            echo "<td>".$Sum_Each_Module."</td>";
                           }
                                         
                     }
                  } 
                 
                  ?>
                  
                  </tr>
                  </tbody>
              </table>
    

    and at the attachment i upload my above code output

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Do you actually have a "dataSrc" called "rows"?

  • allanallan Posts: 61,734Questions: 1Answers: 10,111 Site admin

    There isn't actually an option called just dataSrc so that shouldn't make any difference. There is ajax.dataSrc, but Ajax doesn't appear to be used here.

    @Black Kasper - Can you do a "view source" and send us the rendered HTML please?

    Allan

  • Black KasperBlack Kasper Posts: 11Questions: 2Answers: 0
    edited June 2017

    right i didn't retrieve data using ajax . i would be retrieve using ajax ?
    please look at the attachment

    ht.html 33.6K
  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    The attachment is not a "view source", which Allan asked for.

  • Black KasperBlack Kasper Posts: 11Questions: 2Answers: 0

    @tangerine , view source means right click on the page and click on View Page Source ... right or wrong ?

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Right.

  • Black KasperBlack Kasper Posts: 11Questions: 2Answers: 0

    so that's it bro . believe me

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394
    edited June 2017

    No, it is not. It is the HTML page, not the page source, but it's probably usable anyway.

  • kthorngrenkthorngren Posts: 20,313Questions: 26Answers: 4,771

    Looks like your HTML for the table is not quite right.

              <tbody>
                  <tr>
                  <tr></tr>
                    <td>CS17001</td>
                    <td>باخان عادل أحمد حمە</td>
                    <td>57.3</td>
                    <td style='background-color:#bfbfbf;color:white;color:black;'>38.4</td>
                    <td style='background-color:#bfbfbf;color:white;color:black;'>50</td>
                    <td>60.6</td>
                    <td>69.75</td><td  style='background-color:#e9ffd3;'>11.6</td>
                  <tr></tr>
    ...
                  <tr></tr>
                    <td>CS17094</td>
                    <td>ئەوین ڕزگار  احمد سعید</td><td style='background-color:#bfbfbf;'>33.33</td>
                    <td>59.6</td>
                    <td>67</td>
                    <td>57.6</td>
                    <td>65.5</td><td  style='background-color:#e9ffd3;'>16.67</td>            
    
                  </tr>
    
                  </tbody>
    

    Looks like you have an extra <tr> at the beginning followed by <tr></tr> which is followed by the row. The row should be between the <tr></tr>. And you have an extra </tr> at the end.

    I think Datatables is looking between the <tr></tr> tags for the columns and is not finding anything.

    Kevin

This discussion has been closed.