|
Title: Adding tab tools dynamically in version 1.2.5 Post by: tslatt on December 08, 2011, 09:29:16 AM I'm using the latest version of easyUI, 1.2.5, which has the ability to add tiny tools to the tab itself. This is a very helpful addition. However, I can only get this to work if the tab is added within the html, not when the tab is added dynamically.
For example, this works: <div title="Tab1" tools="#p-tools">test</div> But this doesn't: $('#main-tab-bar').tabs('add',{ title:"Tab1", content: "test", tools: "#p-tools" }); How can the new tab tools feature be used on dynamically created tabs? Title: Re: Adding tab tools dynamically in version 1.2.5 Post by: stworthy on December 08, 2011, 06:37:09 PM When tools '#p-tools' has be used in 'Tab1' panel, it cannot be used in other panel again. Remove tools from 'Tab1' panel and below code will run fine.
$('#main-tab-bar').tabs('add',{ title:"Tab1", content: "test", tools: "#p-tools" }); Title: Re: Adding tab tools dynamically in version 1.2.5 Post by: tslatt on December 09, 2011, 07:34:19 AM I didn't mean to imply that I tried both methods at the same time. I've already tried the dynamic method without using the static method. It did not work. The div that contained the tab tools never got moved into the tab header. Do you have a working example of adding the mini tools to a tab that is created dynamically?
Title: Re: Adding tab tools dynamically in version 1.2.5 Post by: stworthy on December 11, 2011, 06:48:05 PM Below is the example for adding tab tools dynamically:
http://www.jeasyui.com/easyui/demo/tabs.html Title: Re: Adding tab tools dynamically in version 1.2.5 Post by: tslatt on December 14, 2011, 11:29:26 AM Thanks for the link to the example, but that example only shows adding a tab dynamically, while the mini tab tools are static on the page. I am also creating the div that holds the mini tab tools dynamically.
However, I did finally get it working. Hopefully my code can help someone else. Note: This code not only creates the tab and its mini tab tools dynamically, but it also adds a hidden unique id to the tab title, to get around the problem of using the tab title to identify tabs, when titles might not be unique in themselves. Code: tabTitle = tabName + "<strong>" + tabID + "<\/strong>"; //append a unique id to the title inside a strong tag, so that tab titles are unique. the css hides the <strong>. Title: Re: Adding tab tools dynamically in version 1.2.5 Post by: tslatt on December 14, 2011, 02:41:41 PM I found one more thing that is needed with this. When the tab is created, the mini tools are moved from the within "tabToolsDiv" and placed within the tab, leaving an empty div. Because of this, if I close one of my tabs and then re-add it later, there are now two divs on the page with the same id "tabTools". It tries to pull the mini tools from the first instance it finds, which is empty. Therefore the mini tools aren't added to the tab. To fix this, this line of code goes immediately after what I posted above:
$(tabTools).remove();//remove the empty div |