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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add item in javascript

Thread ID:





144616 May 14,2019 07:17 PM UTC May 20,2019 09:38 AM UTC ASP.NET Core - EJ 2 3
Tags: Tabs
Bernard Jurlina
Asked On May 14, 2019 07:17 PM UTC

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?


Karthigeyan Krishnamurthi [Syncfusion]
Replied On 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. 

Bernard Jurlina
Replied On 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.


Nevitha Ravi [Syncfusion]
Replied On 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); 



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