DataTables requires tables to have a thead

DataTables requires tables to have a thead

RdeBoerRdeBoer Posts: 10Questions: 0Answers: 0
edited November 2013 in Bug reports
Thanks so much for this library!

I'm preparing a new Drupal module to integrate DataTables across any Drupal site. It works great already except that
DataTables does not seem to cope when there is no in the table, even when sorting is turned off.

Why not put the in? Well it's because some of the tables are generated by the Drupal "core" and I have no control over that.

With just the search-box (bFilter) on, and no sorting, the browser console will display this error:
"Uncaught TypeError: Cannot read property 'asSorting' of undefined" (jquery.dataTables.js, line #6709)

With both the search-box and sorting on some columns:
"Uncaught TypeError: Cannot call method 'fnSetData' of undefined" (jquery.dataTables.js, line #824)

Thanks so much for looking into this!

I'm using Datatables v1.9.4 and the test-table I've used is this one:



Access to update.php

CTools CSS Cache

Coder review
PHP_CodeSniffer not installed.



  • tangerinetangerine Posts: 3,341Questions: 35Answers: 394
    Valid HTML requires tables to have a . If Drupal generates invalid HTML, I would take it up with Drupal.
  • allanallan Posts: 61,060Questions: 1Answers: 9,956 Site admin
    DataTables requires valid HTML, with THEAD and TBODY elements in the table, as noted in the prerequisites: . Otherwise, there would be no way of know which rows you want in the header (since a header can have multiple rows).

    Unless Drupal can be modified, I'd suggest using a but of Javascript to modify the DOM, inserting the elements required to make the table valid.

This discussion has been closed.