Multiple FixedHeaders on the same page

Multiple FixedHeaders on the same page

RdeBoerRdeBoer Posts: 10Questions: 0Answers: 0
edited November 2013 in FixedHeader
Hello,
Thanks for this great package.

I was wondering whether there's a way to use FixedHeader on pages that contain multiple tables, so that the call $("table").dataTable() returns multiple objects?

I was hoping that something like this would work, but it doesn't:
[code]
var tables= $("table").dataTable();
new FixedHeader(tables);
[/code]
or in fact
[code]
var tables = $("table").dataTable();
for (var t in tables) {
new FixedHeader(tables[t]);
}
[/code]
What does work is;
[code]
var table1 = $("#id1").dataTable();
new FixedHeader(table1);
var table2 = $("#id2").dataTable();
new FixedHeader(table2);
[/code]
However the above is not a good solution for me as I'm using DataTables in a Drupal context where the tables on the page do not have id's or unique CSS classes, or the id's aren't known to my code.

Any suggestions?

Replies

  • RdeBoerRdeBoer Posts: 10Questions: 0Answers: 0
    Stupid me. This works beautifully:
    [code]
    var tables = $("table").dataTable();
    for (var t = 0; t < tables.length; t++) {
    new FixedHeader(tables[t]);
    }
    [/code]
  • RdeBoerRdeBoer Posts: 10Questions: 0Answers: 0
    However.... the same cannot be said for FixedColums. This does not work:
    [code]
    var tables = $("table").dataTable();
    for (var t = 0; t < tables.length; t++) {
    new FixedColumns(tables[t], { iLeftColumns: 1 });
    }
    [/code]

    Suggestions?
  • allanallan Posts: 63,643Questions: 1Answers: 10,492 Site admin
    Slight reduction for your FixedHeader code:

    [code]
    $("table.dataTable").dataTable().each( function () {
    new FixedHeader( this );
    }
    [/code]

    (I've added a class as well so it only picked up DataTables tables).

    FixedColumns however takes a DataTables object in its constructor (not sure why I did that - bit stupid on reflection...):

    [code]
    $("table.dataTable").dataTable().each( function () {
    new FixedHeader( $(this).dataTable() );
    }
    [/code]

    I'm going to spend a bit of time sorting out the plug-ins and make them all 1. sensible, and 2. confirmative, once 1.10 is in beta / released...

    Allan
This discussion has been closed.