Datatables TableTools multiple tables on the same page

 ̄綄美尐妖づ 提交于 2019-12-05 06:25:16

The problem is that there is an <embed> element with undefined width and height, because table should be visible during initialization.

I solved it via simple CSS rule

.DTTT_button embed {
    width: 50px;
    height: 24px;
}

change sizes according to your situation.

No need any functions and other extra coding.

Nicola Peluchetti

If you are hiding / showing tables, you must call fnResizeButtons(). Also make sure to have at least datatables version 1.8. this issue is surely related to the flash plugin that is not working correctly

Check your sSwfPath and make sure the Flash file actually exists there. Also note you are using a relative path. Try using an absolute path to ensure you get the right location.

--- Edit ---

This does not appear to be an uncommon problem. The following thread mentions a number of solutions to the "multiple tables with TableTools problem."

http://datatables.net/forums/discussion/3963/tabletools-on-multiple-tables/p1

Table must be visible during the initialization.

If not, just call fnResizeButtons on display like that (2 options):

    $("#tabs").tabs({
                activate : function(event, ui)
                {
                    // Version 1.
                    $('table', ui.panel).each(function()
                    {
                        var oTableTools = TableTools.fnGetInstance(this);

                        if (oTableTools && oTableTools.fnResizeRequired())
                        {
                            oTableTools.fnResizeButtons();
                        }
                    });

                    // or version 2.
                    var tableInstances = TableTools.fnGetMasters(), instances = tableInstances.length;

                    while (instances--)
                    {
                        var dataTable = tableInstances[instances];
                        if (dataTable.fnResizeRequired())
                        {
                            dataTable.fnResizeButtons();
                        }
                    }
                }
            });

I created an account just to say that Kayz1's answer worked perfectly for me. (I didn't have enough rep to comment on his thread)

I had a problem very similar to OP. My problem stemmed from the fact that the tables were not visible during initialization. This was due to jqueryUI Tabs. The fix was to call the code that Kayz1 listed above. I put mine in the Tabs definition, however it could exist elsewhere.

Here is my exact definition of tabs.

            $("#tabs").tabs({
            show: function (event, ui) {
                var table = $.fn.dataTable.fnTables(true);
                if (table.length > 0) {
                    $(table).dataTable().fnAdjustColumnSizing();
                }                
            },
            activate: function (event, ui) {
                var tableInstances = TableTools.fnGetMasters(), instances = tableInstances.length;

                while (instances--) {
                    var dataTable = tableInstances[instances];
                    if (dataTable.fnResizeRequired()) {
                        dataTable.fnResizeButtons();
                    }
                }
            }
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!