I'm using DataTable with TableTool plugin 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
$('.dataTables_wrapper').each( function() {
$(this).hide();
});
And I'll slideToggle() them when needed. The problem is: when the table are visible again, the TableTool buttons doesn't work anymore. If I leave out the $(this).hide(), things would work fine with the slideToggle() effect.
I've done some investigation and here what I think now: - the开发者_开发问答 TableTool add-on uses flash. Each button is actually a flash object. - When $(this).hide() is called, the flash content is not loaded yet. And somehow, this stops it from loading. I'm not sure if this is a correct browser behaviour but it's quite consistent across Chrome, FF and Opera.
Could somebody suggest a solution to this?
Thanks,
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 :-)
For reference this is also answered in the DataTables forum: I've just answered this question in the DataTables forum, where it was also posed: http://www.datatables.net/forums/discussion/5859 .
Allan
精彩评论