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:
[code]


Head1
Head2
Head3


Info
Drupal
7.23


OK
Access to update.php
Whatever...


OK
CTools CSS Cache
Exists


Warning
Coder review
PHP_CodeSniffer not installed.


[/code]

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Valid HTML requires tables to have a . If Drupal generates invalid HTML, I would take it up with Drupal.
  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    DataTables requires valid HTML, with THEAD and TBODY elements in the table, as noted in the prerequisites: http://datatables.net/usage/#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.

    Allan
This discussion has been closed.