We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to Dynamically add/remove tabs

Hi

From Javascript I need to build tabs dynamically, however, I am having trouble with the syntax.  I looked at the online examples, as you can see below, but I get the error "TypeError: Cannot read property 'children' of undefined" on the addTab line.  What am I missing??

html:
<div class="stackblitz-container material">
        <div class="control-section">
            <div class="content-wrapper">
                <div id="Tab"></div>
            </div>
        </div>
    </div>


Javascript:
var tabObj = new ej.navigations.Tab({
    items: [
        {
            header: { 'text': 'Twitter' },
            content: '<span>Twitter</span></br><div><input id="intext" class="e-input"></div>'
        },
       {
           header: { 'text': 'Facebook' },
           content: 'Facebook '
       }
    ]
});

var item3 = { header: { text: 'Snapchat' }, content: 'Snapchat app' };
tabObj.addTab(item3, 2);
tabObj.appendTo('#Tab');

5 Replies

PO Prince Oliver Syncfusion Team February 4, 2019 10:46 AM UTC

Hi Travis, 

Thank you for using Syncfusion products. 

We have checked the shared code snippet, it seems that you are trying to add the items to the tab before the Tab object is assigned to element. In the Tabs dynamic content, we need to add items as an array of objects not only as objects and then use the addTab method. Please refer to the following code snippet. 

var tabObj = new ej.navigations.Tab({ 
    items: [ 
        { 
            header: { 'text': 'Twitter' }, 
            content: '<span>Twitter</span></br><div><input id="intext" class="e-input"></div>' 
        }, 
        { 
            header: { 'text': 'Facebook' }, 
            content: 'Facebook ' 
        } 
    ] 
}); 
//First assign to the element 
tabObj.appendTo('#Tab'); 
 
// give as array of objects 
var item3 = [{ header: { text: 'Snapchat' }, content: 'Snapchat app' }]; 
 
// then we can use the methods 
tabObj.addTab(item3, 2); 

We have attached a sample for your reference, please find the sample at the following location: https://stackblitz.com/edit/lcb5rz-q5sfgr  

Kindly refer to the following API link for further reference: https://ej2.syncfusion.com/javascript/documentation/api/tab/#addtab  

Please let us know if you need any further assistance on this. 

Regards, 
Prince 



TR Travis February 6, 2019 01:52 AM UTC

Ahh so simple.  Thanks

How do I change the color the selected text and underline in the tabs?  What are the css classes I need to modify the color of the font and underlines?


DL Deepa Loganathan Syncfusion Team February 6, 2019 05:59 AM UTC

Hi Travis,  
 
Thanks for the update. 
 
You could change the color of Text and high indicator by overriding the below styles in your application.  
 
   
.e-tab .e-tab-header .e-indicator { // To override the style of highlight indecator 
    background: #1639e3; 
    } 
 
    // To override the color of active Tab items' text 
    .e-tab .e-tab-header .e-toolbar-item.e-active .e-tab-text, .e-tab .e-tab-header             .e-toolbar-item.e-active .e-tab-icon, .e-tab .e-tab-header .e-toolbar-item.e-active         .e-tab-wrap:hover .e-tab-text, .e-tab .e-tab-header .e-toolbar-item.e-active                .e-tab-wrap:hover .e-tab-icon { 
        color: #1639e3; 
    } 
 
 
Please find the sample for your reference.  
 
 
If you would like to customize the existing theme common to all the controls, we suggest using our theme studio application.  Kindly check the below pages to explore more about Theme studio. 
 
 
 
 
Kindly get back to us in case of any further queries. 
 
Regards,  
Deepa L. 



TR Travis February 7, 2019 02:13 AM UTC

Thanks for the help


DL Deepa Loganathan Syncfusion Team February 7, 2019 04:15 AM UTC

Hi Travis,   
 
Most welcome. We hope the solution provided was helpful. 
 
Please let us know if you have any further concerns.  
 
Regards,  
Deepa L. 


Loader.
Live Chat Icon For mobile
Up arrow icon