Select to view content in your preferred language

Tabcontainer change on button click

6503
4
Jump to solution
08-28-2014 09:30 AM
IbrahimHussein
Deactivated User

<div data-dojo-type="dijit.layout.TabContainer">

     <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="title:'Legend'">

          

     </div>  

       <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="title:'Search results'">

    </div>

  </div>

<div data-dojo-type="dijit.layout.TabContainer">

     <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="title:'Legend'">

         

     </div> 

       <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="title:'Search results'">

    </div>

  </div>

Hey guys, im trying to figure out how to switch between the tabs from a button (rather than pressing on the tab itself) is there a way to do this?

edit - answer: give the div of the tabcontainer and the tab itself an id tag

<id="tabconID" div data-dojo-type="dijit.layout.TabContainer">

for tab itself: <div id="tab1Name" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="title:'Search results'"></div></div>

then in your javascript section do

//declare tab
            var tc = registry.byId("tabconID");

//use to select tab

tc.selectChild(registry.byId("tab1Name"));

0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

Here's a revised version of your fiddle showing the new tab.  One place I often check when trying to figure out how to do something with one of dojo's widgets is the dojo nightly tests. Visit the TabContainer Demo and  you'll see that it shows how to do things like add a tab, rename tabs and place the tabs in various locations. 

These tests are available for many of dojo's widgets and are often invaluable when trying to learn how to use them.

View solution in original post

0 Kudos
4 Replies
KellyHutchins
Esri Frequent Contributor

You can use the selectChild method to select the tab. There's an example and some more info in the dojo doc for the dijit/layout/TabContainer — The Dojo Toolkit - Reference Guide .

require(["dijit/registry", "dijit/layout/ContentPane"], function(registry, ContentPane){

   var tabs = registry.byId("myTabContainer");

   var pane = new ContentPane({ title:"Remote Content", href:"remote.html" });

   tabs.addChild(pane);

   tabs.selectChild(pane);

});

0 Kudos
IbrahimHussein
Deactivated User

Thanks that got me in the right direction. Only thing that doesn't work for me is when I add a new tab programmatically, the content doesn't appear. I get a blank button (if there is no tabContainer in the function declaration) and a blank select field if there is a tabContainer in the function declaration.

See here: jsfiddle

0 Kudos
KellyHutchins
Esri Frequent Contributor

Here's a revised version of your fiddle showing the new tab.  One place I often check when trying to figure out how to do something with one of dojo's widgets is the dojo nightly tests. Visit the TabContainer Demo and  you'll see that it shows how to do things like add a tab, rename tabs and place the tabs in various locations. 

These tests are available for many of dojo's widgets and are often invaluable when trying to learn how to use them.

0 Kudos
IbrahimHussein
Deactivated User

Thanks, will check out.

0 Kudos