DataTables is broken when using two rows of headers and a column in the top row only spans 1 column

DataTables is broken when using two rows of headers and a column in the top row only spans 1 column

ejeliotejeliot Posts: 5Questions: 0Answers: 0
edited August 2010 in Bug reports
DataTables doesn't appear to be working when I have two rows of headers and a column in the first row only spans one column below (colspan=1).

Here's some example markup:





Goals
Attempts
Threat <!-- this single column colspan seems to cause the problem -->


Name
Team
Stat 1
Stat 2
Stat 3
Stat 4
Stat 5
Stat 6
Stat 7
Stat 8
Stat 9
Stat 10
Stat 11


...

It looks like DataTables looks for colspan = 2 or greater to determine that the column header is a field that shouldn't be sortable when clicked on. Is there any way to have it ignore headers that have an effective colspan of 1? I tried adding colspan="1" but that didn't work.

The error I get is:

/js/dataTables-1.7/media/js/jquery.dataTables.js:5578DataTables warning: Unexpected number of TD elements. Expected 2436 and got 2262. DataTables does not support rowspan / colspan in the table body, and there must be one cell for each row/column combination.
/js/dataTables-1.7/media/js/jquery.dataTables.js:719TypeError: Result of expression 'sData' [undefined] is not an object.

I've checked that numbers of tds etc is correct.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I believe that the issue you are running into is that DataTables is expecting (and indeed will only cope with) one unique TH element per column. At the moment you have two for you thirteenth column which is causing the problem for DataTables... I would guess that you have about 174 rows in your table - is this right?

    This is most definitely something which on the list of future enhancements. Sorry I can't be of much more use at the moment!

    Regards,
    Allan
  • ejeliotejeliot Posts: 5Questions: 0Answers: 0
    Thanks for getting back to me so quickly. 174 sounds about right.

    How does it detect and exclude columns with colspan=2 or greater? I was wondering if I could extend that condition to columns that are explicitly set to colspan=1 to get around the limitation.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The function in question which does this detection is _fnGetUniqueThs() in DataTables. It's been a little while since I was in that part of the code, so I can't remember off the top of my head how easy (or not) it will be to make the modification. I suspect that it will probably need to be rewritten... Basically DataTables tries to build up a map of TH elements which are unique to a single column - at the moment it doesn't detect when there is more than one TH element which only applies to a single column - treating them as individual columns - hence the problem...

    Regards,
    Allan
  • ejeliotejeliot Posts: 5Questions: 0Answers: 0
    Thanks for the pointer. I think I've managed to fix the problem by tweaking the function you mention. I've changed this block of code:

    if ( !iColspan || iColspan===0 )
    {
    iColumnShifted = fnShiftCol( aLayout, i, iColumn );
    aLayout[i][iColumnShifted] = (nTds[j].nodeName.toUpperCase()=="TD") ? TDELEM : nTds[j];
    if ( iRowspan || iRowspan===0 )
    {
    for ( k=1 ; k
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Thanks for the update - that's useful information. Should make it easier to have this working without needed the col/row span specified in the next version.

    Allan
This discussion has been closed.