DataTables / FixedHeader

Fix the header, footer, left or right columns of a table in place, to always show them when scrolling
http://www.datatables.net/
Other
75 stars 83 forks source link

TypeError: dt is undefined (when using without datatable) #28

Closed char101 closed 10 years ago

char101 commented 10 years ago

Hi,

I was using this code to initialize FixedHeader

$('table.table-fixed-header').each(function() {
    new FixedHeader(this);
});

And got that error, which comes from these lines

var dt = $.fn.dataTable.Api ?
        new $.fn.dataTable.Api( mTable ).settings()[0] :
        mTable.fnSettings();

    dt._oPluginFixedHeader = this;

    /* Let's do it */
    this.fnInit( dt, oInit );

I was using datatable and fixedheader from the master branch.

Is my initialization code wrong or is this a bug?

DataTables commented 10 years ago

Can you link to a test case showing the issue please. I don't immediately see anything wrong, but there obviously is something somewhere, so I'd need to dig deeper.

char101 commented 10 years ago

This is enough to reproduce the error

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<table id="t1">
    <thead>
        <tr><th>Header</th></tr>
    </thead>
    <tbody>
        <tr><td>Body</td></tr>
    </tbody>
</table>
<script src="https://github.com/DataTables/DataTables/raw/master/media/js/jquery.js"></script>
<script src="https://github.com/DataTables/DataTables/raw/master/media/js/jquery.dataTables.js"></script>
<script src="https://github.com/DataTables/FixedHeader/raw/master/js/dataTables.fixedHeader.js"></script>
<script>
new FixedHeader(document.getElementById('t1'));
</script>
</body>
</html>
char101 commented 10 years ago

I believe the problem is that

new $.fn.dataTable.Api( mTable ).settings()

is an empty array, but I could not trace to where settings() is defined, so I can't find the cause.

DataTables commented 10 years ago

Ah I see - sorry, I had missed the fact that you were using FixedHeader without DataTables. That is no longer supported in the latest major release of FixedHeader. From the release notes:

Removed: Removed the ability to operate on a plain HTML table - this is specific a DataTables extension now

It probably is possible to modify FixedHeader to operate without DataTables again, but it wasn't something I wanted to support myself.

char101 commented 10 years ago

I see, I was reading the comment in the source code

 * Inputs:   mixed:mTable - target table
 *                     1. DataTable object - when using FixedHeader with DataTables, or
 *                     2. HTML table node - when using FixedHeader without DataTables

so I thought that it was still supported.

DataTables commented 10 years ago

That's the bug!

DataTables commented 10 years ago

Sorry about that. The FixedHeader (and the extensions for DataTables generally) badly need to have their documentation updated in the same way DataTables is currently getting. That's the long term goal for this year...

char101 commented 10 years ago

Thanks for the explanation (and fix) :thumbsup: