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

Add item in javascript

In Syncfusion ASP.NET MVC jquery based I created new tab in tab control like this:

var tabObj = $("#tab1").data("ejTab");
    if (tabObj.model != null) {
        var tabName = "#tab" + (tabObj.items.length + 1).toString();
        tabObj.addItem(tabName, "Ispis");
        tabObj.option("selectedItemIndex", tabObj.items.length - 1);

How can I do this in JS2 tab control?


3 Replies

KK Karthigeyan Krishnamurthi Syncfusion Team May 15, 2019 04:44 AM

Hi Bernard,  
Greetings from Syncfusion. 
We have prepared the below sample to add item on button click for your reference. 
document.getElementById('addbtn').onclick = function (e) { 
  var title = 'New Tab'; 
  var content = 'Added new tab'; 
  // Required tab item object formed by using textbox inputs 
  var item = { header: { text: title }, content: content }; 
  totalItems = document.querySelectorAll('#Tab .e-toolbar-item').length; 
  // Item object and the index argument passed into the addTab method to add a new tab 
  tabObj.addTab([item], totalItems - 1); 
  tabObj.selectedItem = totalItems - 1; 
Above sample is for your reference and the same can be achieved in Core. 

BJ Bernard Jurlina May 18, 2019 01:43 AM

Hi Karthi,

thanks, it's working. But, when I add new tab from code and populate it with some html and I want to close that new tab, I cannot change
selectedItem back to first.

The scenario is like this.
First, click on the button creates new tab and loads html inside.

Then I want to close that tab...but...

the tab is closed, and selected tab is not the first one.

I tried with onTabRemoved and onTabRemoving, but the results are the same. It will not select back the first tab.

That's the first problem. The second is that I want to disable closing the first tab. I tried with first if statement in method onTabRemoving,
but the tab closes anyway.


NR Nevitha Ravi Syncfusion Team May 20, 2019 04:38 AM

Hi Bernard, 

Thanks for your update. 

We have checked the reported scenario ‘after closing the new tab, first tab is not selected’ at our end and were unable to reproduce the problem. We have shared the video demo for the same which can be downloaded from the following link. 
Please video demo if the issue persist still, try to reproduce it in a sample or else share your code snippet to check further. 

To disable the closing of tab, refer the following sample link. 

  tabObj.enableTab(0, false); 


Live Chat Icon For mobile
Up arrow icon