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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to Dynamically add/remove tabs

Thread ID:

Created:

Updated:

Platform:

Replies:

142422 Feb 2,2019 06:07 PM UTC Feb 7,2019 04:15 AM UTC JavaScript - EJ 2 5
loading
Tags: Tab
Travis
Asked On February 2, 2019 06:07 PM UTC

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');

Prince Oliver [Syncfusion]
Replied On 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 


Travis
Replied On 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?

Deepa Loganathan [Syncfusion]
Replied On 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. 


Travis
Replied On February 7, 2019 02:13 AM UTC

Thanks for the help

Deepa Loganathan [Syncfusion]
Replied On 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon