Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Got this working. As @Sergey said I need to use 'shown' event. I gave ids to each tab to identify specific tab and load content. Here is the code</p> <pre><code>&lt;?php $this-&gt;widget('bootstrap.widgets.TbTabs', array( 'id' =&gt; 'mytabs', 'type' =&gt; 'tabs', 'tabs' =&gt; array( array('id' =&gt; 'tab1', 'label' =&gt; 'Tab 1', 'content' =&gt; $this-&gt;renderPartial('tab1', null, true), 'active' =&gt; true), array('id' =&gt; 'tab2', 'label' =&gt; 'Tab 2', 'content' =&gt; 'loading ....'), array('id' =&gt; 'tab3', 'label' =&gt; 'Tab 3', 'content' =&gt; 'loading ....'), ), 'events'=&gt;array('shown'=&gt;'js:loadContent') ) );?&gt; </code></pre> <p>We have 3 tabs, the content will be loaded using loadContent javascript function.</p> <pre><code>&lt;script type="text/javascript"&gt; function loadContent(e){ var tabId = e.target.getAttribute("href"); var ctUrl = ''; if(tabId == '#tab1') { ctUrl = 'url to get tab 1 content'; } else if(tabId == '#tab2') { ctUrl = 'url to get tab 2 content'; } else if(tabId == '#tab3') { ctUrl = 'url to get tab 3 content'; } if(ctUrl != '') { $.ajax({ url : ctUrl, type : 'POST', dataType : 'html', cache : false, success : function(html) { jQuery(tabId).html(html); }, error:function(){ alert('Request failed'); } }); } preventDefault(); return false; } </code></pre> <p></p> <p>Here we get the target, that should be the anchor element of the tab that we clicked, get the href value which should be the id that we configured. Decide the url based on this id, load content and update the div's. The id of div's are the same as href.</p> <p><strong>I haven't found way to load content of the initial active tab, there should be way to fire loadContent function, for now I have used renderPartial to get the content instead</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload