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");
        $(tabName).html(html);
        tabObj.option("selectedItemIndex", tabObj.items.length - 1);
    }

How can I do this in JS2 tab control?

Thanks!
Bernard.

3 Replies

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

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. 
 
Regards, 
Karthi 



BJ Bernard Jurlina May 18, 2019 06:43 AM UTC

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.

Thanks!
Bernard.


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

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


Regards, 
Nevitha 


Loader.
Live Chat Icon For mobile
Up arrow icon