Number of td-tags in tfoot has to match tbody. Disregarding [colspan]

Number of td-tags in tfoot has to match tbody. Disregarding [colspan]

hydrospannershydrospanners Posts: 1Questions: 0Answers: 0

Bug or possible feature request:
I always end my tables with a tfoot-tag with a td-tag that has colspan="99" or something high enough to never be a problem.
It's usually a style/design decision to do this as i want all my tables to look the same, disregarding if they actually have content in tfoot or not.
I get an error here:
// Cache the footer cells. Note that we only take the cells from the first
// row in the footer. If there is more than one row the user wants to
// interact with, they need to use the table().foot() method. Note also this
// allows cells to be used for multiple columns using colspan
if ( tfoot !== null ) {
var cells = oSettings.aoFooter[0];

        for ( i=0, ien=cells.length ; i<ien ; i++ ) {
            column = columns[i];
            column.nTf = cells[i].cell;

            if ( column.sClass ) {
                $(column.nTf).addClass( column.sClass );
            }
        }
    }

The problem seems to be column = columns[i]; and then column.nTf = cells[i].cell; since column is null because there is more cells than columns.

I suggest you replace: ien = cells.length with ien = columns.length in the for-loop declaration

Love DataTables! Best tool i've come across in a long time! Well done!

Replies

  • allanallan Posts: 63,760Questions: 1Answers: 10,510 Site admin

    I always end my tables with a tfoot-tag with a td-tag that has colspan="99" or something high enough to never be a problem

    That's not valid HTML though.

    Try running the following HTML through the W3C validator:

    <!doctype html>
    <html>
      <head>
        <title>Test</title>
      </head>
      <body>
    
    <table>
      <tbody>
        <tr>
          <td></td>
        </tr>
      </tbody>
      <tfoot>
        <tr>
          <td colspan="99"></td>
        </tr>
      </tfoot>
    </table>
    
      </body>
    </html>
    

    I can see why you've done that, but DataTables assumes valid HTML. Anything else would just be a nightmare to support (perhaps an easy fix for this one, but not for many others).

    Love DataTables! Best tool i've come across in a long time! Well done!

    Thank you! Really delighted to hear that you are enjoying using it (minus the colspan!).

    Allan

This discussion has been closed.