How to use fnTables correctly?

How to use fnTables correctly?

MikeSMikeS Posts: 113Questions: 1Answers: 0
edited May 2012 in General
The code example in the documentation for fnTables states:

var table = $.fn.dataTable.fnTables(true);
if ( table.length > 0 ) {
$(table).dataTable().fnAdjustColumnSizing();
}

I don't know javascript/jQuery well enough to tell if this code is supposed to adjust the column sizes for *ALL* datatables on my page. Is it supposed to? If so, I'm only seeing it happen if I have a *single* datatable displayed. If I put multiple datatables on my page, it only adjusts one table and not the rest. As for which one it decides to work on, I can't predict.

How do I call fnAdjustColumnSizing() on ALL of my displayed datatables?

TIA,
Mike

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > Is it supposed to?

    Currently no - however that might change with 1.10 if I can make the API backwards compatible. Certainly performing actions on all tables will be much easier with 1.10.

    You could change the if line to an each to loop over the table - $(table).each( function () { ...

    Allan
  • MikeSMikeS Posts: 113Questions: 1Answers: 0
    Thanks for the "instant" reply. WOW.

    Your comment to perform actions on all tables would be a very nice addition imo. Even if you don't do so in version 1.10, your suggestion to loop over each table sounds like a minor change that even I could attempt.

    Thanks again.

    Mike
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Letus know how you get on with it - I'm sure other's will benefit!

    My current thinking with the DataTables API is that you would do something like this in 1.10:

    [code]
    var tables = $.fn.dataTable.fnTables(true);
    $(tables).dataTables(-1).fnAdjustColumnSizing();
    [/code]

    Note the negative number, that indicates that the API method should apply to all DataTables the selector finds - if you used a whole number (0+) it would pick out just that one. The default at the moment is to use '0' (can be changed by using iApiIndex). 'true' could also be used rather than -1.

    As a bit of a "test subject" :-) - what do you think of this approach?

    Thanks,
    Allan
This discussion has been closed.