TableTool problem when hiding dataTable_wrapper

TableTool problem when hiding dataTable_wrapper

lang2lang2 Posts: 5Questions: 0Answers: 0
edited July 2011 in DataTables 1.8
Hi,

I'm using TableTool for exporting CSV and clipboard and it works perfectly well... until I decided to make my page a bit fancy. So I have a few datatable on a page. On start up, I do
[code]
$('.dataTables_wrapper').each( function() {
$(this).hide();
});
[/code]

And I'll slideToggle() them when needed. The problem is: when the table are visible again, the TableTool button doesn't work anymore. If I leave out the $(this).hide(), things would work fine with the slideToggle() effect.

I'd appreciated if anybody can provide a solution to this.

Thanks,

Replies

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    Hi lang2,

    The trick here is to realise that when the elements are hidden during initialisation, they don't have any height or width - therefore the Flash buttons which are used for the file and clipboard interactions in TableTools don't have any any size (i.e. they are 0px x 0px), which you should be able to confirm with Firebug / Inspector.

    The solution to the issue lies with the TableTools API - basically what you need to do is when the table (and therefore the TableTools buttons) is made visible again, you need to resize the buttons so there is an area when the user can click on.

    The two functions you want are: fnResizeRequired and fnResizeButtons

    http://datatables.net/extras/tabletools/api#fnResizeRequired
    http://datatables.net/extras/tabletools/api#fnResizeButtons

    The first checks if the resize is needed, and the second will do the actual resize (you could call the second one every time, no harm in that, other than a few clock cycles).

    And hopefully that will do it :-)

    Regards,
    Allan
  • lang2lang2 Posts: 5Questions: 0Answers: 0
    That worked perfectly! Thank for your help.
This discussion has been closed.