TypeError: oTable is undefined

TypeError: oTable is undefined

pcpacino2141pcpacino2141 Posts: 11Questions: 5Answers: 0

I am using Datatables and Yadcf for filtering results. I actually have it set up on Drupal 8 but then created a plain html site so that I can post it and get help. The Datatable and Yadcf filters all work fine. But if I go to any page on my site that does not have a table with the class name from my datatable init and my variable oTable, I get TypeError: oTable is undefined. I have Drupal site with many pages. We are allowing Editors to copy and past Datatables within the Ckeditor. So a Datatable can be on any page. I was told I need to load datatables.js and jquery.dataTables.yadcf.js only on pages that contain a Datatable. If I remove yadcf.init section from my code the error goes away. I am thinking my syntax is wrong? I want to have over 40 different Datatables configurations. So I will have var oTable1,oTable2,oTable3, etc.; Example here A page that has a Datatable and no errors Example here A page that does not have a Datatable an has the error. View the console log and you will see the error.

Answers

  • pcpacino2141pcpacino2141 Posts: 11Questions: 5Answers: 0

    I was able to make the error go away by first checking if the table class exists then running the datatable and yadcf init. Now Datatable and yadcf init only run if the table class name exists on the page. The example is here. https://codepen.io/leisureman/pen/VqaWNo

This discussion has been closed.