PDA

View Full Version : How to restorestate for tabpanels?



qiuyl
2 Dec 2006, 12:49 AM
It looks the tabpanel does not support restoreState (as BorderLayout). It would be very helpful if activated tab could be restored when visitor refreshes a page or comes back.

jack.slocum
2 Dec 2006, 5:07 AM
It would be pretty easy to implement:


var tabs = new YAHOO.ext.TabPanel(...);
tabs.add(...);

var state = YAHOO.ext.state.Manager;
tabs.on('tabchange', function(tp, tab){
state.set(tp.el.id+'-active', tab.id);
});
tabs.activate(state.get(tp.el.id+'-active', 'your-default-tab-id'));

frega
2 Dec 2006, 9:12 AM
Hi,
i think there is a little typo in the code:

tabs.activate(state.get(tp.el.id+'-active', 'your-default-tab-id'));
it should read:

tabs.activate(state.get(tabs.el.id+'-active', 'your-default-tab-id'));
I stuggled initially because I forgot to initialise the State Manager before using it for the tabs (as the fine manual suggest).
Something like this does the trick (place it somewhere before the tabs.on(...) line).

YAHOO.ext.state.Manager.setProvider(new YAHOO.ext.state.CookieProvider());

PS. Really, really great stuff, Jack! Just to chime in ... :)

jack.slocum
2 Dec 2006, 9:29 AM
The tp is correct. tp is a local variable passed as the first argument to the function. It's faster to use the local variable. Your way would work as well.

bikutoru
24 Jun 2008, 12:40 PM
It looks the tabpanel does not support restoreState (as BorderLayout). It would be very helpful if activated tab could be restored when visitor refreshes a page or comes back.
Can we use something like:

Object = Ext.extend(Object, {

restoreState: function(){
throw ({
msg: 'restoreState doesnot implements by ' + typeof(this)
});
},
saveSate: function(){
throw ({
msg: 'saveSate doesnot implements by ' + typeof(this)
});
}
});
Panel = Ext.extend(TabPanel, {
restoreState: function(){ /*special restore logic for TabPanel*/
},
saveSate: function(){/*special save logic for TabPanel*/
}
});I'm new in Ext, will be above code extend each objects that inherit TabPanel(even xtype:'tabpanel')?
What is YAHOO.ext ? To use YAHOO.ext have to be used third part libs?