Table in Hidden Tab

If you’d like to tune table created by our Data Table plugin into a tab, which is hidden by default, we need to aware you, that table needs to be rendered on the page from the very beginning to be output correctly, but as a tab is hidden by default, we need to create a detailed tutorial with an example, to make sure everything will be working fine.

Step 1. Add ID of table as an attribute to tab header.

Step 2. Add a small script with a callback on click on your tab headers – right to a page with tabs or into any javascript file of your theme which is loaded on the page with tabs. The callback should:

  • get the table id from tab header
  • get table object using the function getTableInstanceById(tableId) (this function is placed in global window.supsystic.Tables object)
  • call the function fnAdjustColumnSizing(false) of table object to refresh table after showing tab content.

Please note, that it is almost impossible to  calculate the positioning and size of the table correctly (and other elements as well) in the hidden elements by default.

Sometimes it causes the issues. For example – you have 100% table width, but in process of building a table, in a hidden element (tab) – its width will be 100% of the width of this hidden element. So,  when it’s hidden – its width is 0. Because of this, the table can be display not correct. At that point – when you open the table on the page (in the new tab) – it have to be updated.

The update must be bound to the code of opening tab. Because the code can be different for different tabs on the page – we can not foresee all of them.

An example below shows a code, that would be used for a case, where we have tab container with id “tabsList” and 3 tabs with header with class “tabItem”. Then, our callback will be looking like that:

 

 

Categories
Latest Articles
Get plugins bundle today and save over 80%