[ 4 posts ]

Hammad

  • Username: aSmartLondoner
  • Joined: Tue May 26, 2009 8:27 am
  • Posts: 39
  • Location: London, UK
  • Twitter: hammadtariq
  • Offline
  • Profile

getting dataSrc to work each time a tab get selected

Post Posted: Fri Feb 05, 2010 9:41 am
+0-
Hello,
I have an application with two tabs in it, the two tabs are essentially the same in means of the html elements. I have JS functionality in the tabs which updates those html elements. Now the problem is, if you make both tabs active by selecting them, both will have same elements and same JS and those will not work for live data. What I am looking for, is there a way, you could simple reset the dataSrc so when a tab gets inactive, it destroy all of its elements and when you make it active again, it fetches the src again.

Thanks,

Caridy Patino

YUI Contributor

  • Username: caridy
  • Joined: Mon Dec 08, 2008 5:40 pm
  • Posts: 491
  • Location: Miami, FL
  • Twitter: caridy
  • GitHub: caridy
  • Gists: caridy
  • IRC: caridy
  • YUI Developer
  • Offline
  • Profile

Re: getting dataSrc to work each time a tab get selected

Post Posted: Fri Feb 05, 2010 12:37 pm
+0-
Hello Hammad,

You can listen for "beforeActiveTabChange" at the tabview level:

beforeActiveTabChange ( event )
Fires before the value for the configuration attribute 'activeTab' changes. Return false to cancel the attribute change.

Parameters:
event <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.
http://developer.yahoo.com/yui/docs/YAH ... eTabChange

This way, you can set the content of the oldValue tab to empty right before the content of the new tab gets set. Also, make sure that you set dataCache to false at the tab level.

Best Regards,
Caridy

Hammad

  • Username: aSmartLondoner
  • Joined: Tue May 26, 2009 8:27 am
  • Posts: 39
  • Location: London, UK
  • Twitter: hammadtariq
  • Offline
  • Profile

Re: getting dataSrc to work each time a tab get selected

Post Posted: Mon Feb 08, 2010 4:01 am
+0-
Thanks Caridy, You was once again of great help. I was using beforeActiveChange but was not setting cacheData to false.

Here is the piece of code if anyone else stumbles across this problem again:

Code:
tabView.on("beforeActiveTabChange", function(o) {
            if(tabView.get("activeTab").get("label") === "Tab1"){
               document.getElementById("myDataTable1").innerHTML = "";
            }else if(tabView.get("activeTab").get("label") === "Tab2"){
               document.getElementById("myDataTable2").innerHTML = "";
            }
         });


where myDataTable1 and myDataTable2 are the divs in which I enclose all of the HTML in the tabs.

Caridy Patino

YUI Contributor

  • Username: caridy
  • Joined: Mon Dec 08, 2008 5:40 pm
  • Posts: 491
  • Location: Miami, FL
  • Twitter: caridy
  • GitHub: caridy
  • Gists: caridy
  • IRC: caridy
  • YUI Developer
  • Offline
  • Profile

Re: getting dataSrc to work each time a tab get selected

Post Posted: Mon Feb 08, 2010 5:40 pm
+0-
Hey Hammad,

I'm glad to help. One more thing that come to my mind is: don't forget the clean up (purge) the content of the element (myDataTable1) or destroy the YUI DataTable before removing the content. This will help with the memory leaks in IE.

Best Regards,
Caridy
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum