Uncaught TypeError: Cannot read properties of undefined

Uncaught TypeError: Cannot read properties of undefined

BradleyO07BradleyO07 Posts: 13Questions: 10Answers: 0

I have this piece of code that is working fine but I am getting this error within my Developer Tools tab.
Can anyone explain to me why this error is showing and what I can do to fix it?

Below is where the error is existing:

initComplete: function () {
          
            //This draws the option for the table
            this.api().columns([0,1,2,3,4,7,8,11,12,16]).every( function (index) {
                      var column = this;
                      var select = $('<select><option value=""></option></select>')
                          .appendTo($(column.header()).parent().parent().children('tr').eq(1).children('th').eq(index).empty() )
                          .on( 'change', function () {
                              var val = $.fn.dataTable.util.escapeRegex(
                                  $(this).val()
                              );
      
                              column
                                  .search( val ? '^'+val+'$' : '', true, false )
                                  .draw();
                          } );
      
                      column.data().unique().sort().each( function ( d, j ) {
                        if (d != "" && d != null){
                          select.append( '<option value="' + d + '">' + d + '</option>' );
                        }
                      } );
                } ); 
          }

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,338Questions: 26Answers: 4,954
    Answer ✓

    There is nothing obvious in the code snippet. Wonder if its a different part of the code. Errors like that can occur if the number of HTML columns doesn't match what is defined in Datatables. To help debug we will need to see the problem. Please post a link to your page or a test case replicating the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • BradleyO07BradleyO07 Posts: 13Questions: 10Answers: 0

    @kthorngren you were right about the columns number, I only had 6 columns and not 7 as per what my code was thinking.

Sign In or Register to comment.