DataTables and Multi-Row Headed Tables
DataTables and Multi-Row Headed Tables
Hello,
Link to test case:
http://live.datatables.net/yohukika/1/edit
Debugger code (debug.datatables.net):
iwonaq
Error messages shown:
jquery-3.4.0.min.js:2 Uncaught TypeError: Cannot set properties of undefined (setting '_DT_CellIndex')
Description of problem:
I have a 3-row header table that pulls data from a mysql query. I use the following to initialize DataTables:
$( document ).ready(function() {
$('#tbl_daily_mining_rpt').DataTable( {
"paging": false,
"ordering": false,
"info": false,
"processing":false,
"searching": false,
"serverSide": false
});
});
I get error given above even when I remove all options/ settings from the initialization. I am using UserSpice 5.4.0 and my scripts are being loaded via CDN.
I can use DataTables with out any issues on other pages within my site but these are all simple tables with single row headers. I have validated the html for my table and can not find any issues with the table layout. My project is with our local intranet so I am unable to give a link to the site.
This question has an accepted answers - jump to answer
Answers
In your 3rd header row you have 39 columns but in the first row you have 40 columns. They need to match. See the Complex header and HTML requirements for more details.
Kevin
Hi Kevin,
The first <th> in row 1 has a rowspan="3". Does this not make 40 columns in row 3?
The Complex Header example state this:
You will need to have 40 unique
th
for this header row. Nocolspan
.Kevin
My apologies. Please bear with me as I have trouble understanding. I have edited my header as below. The table still has 3 rows, however, the one at the bottom now has 40 unique <th> tags and no colspan or rowspan tags. The same error still occurs.
Sorry I missed that the first column has
rowspan=3
. The header should be good.The problem is your first row has
rowspan
which isn't supported by Datatables in thetbody
. See the HTML docs I linked to earlier:Then the second row has 39 columns instead of 40. Datatables requires all rows have the same number of columns and that number matches the header.
I updated your example removing the rowspan in the first row and removing the others. Now the Datatable works:
http://live.datatables.net/yohukika/5/edit
Looks like you want to try grouping rows. See if the RowGroup extension will do what you want.
Kevin
Thanks Kevin.
Took me while but I finally managed to get it working.