Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Problem saving state when adding new tabs to a TabPanel

  1. #1

    Default Problem saving state when adding new tabs to a TabPanel

    I'm just now learning ExtJS and am playing around with a couple of examples I've found.

    I have a window with a TabPanel on the right initially containing 4 tabs, on the left a LinksPanel with 3 links. When I click on a link in the LinksPanel it adds a new tab to the TabPanel.

    What I am trying to do is save the state of the TabPanel after new tabs have been added. I can get it to work when the state of the initial 4 tabs changes, but always lose the newly added tabs on a page reload.

    The code I am using is as follows:

    .
    .
    .
    Code:
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
    .
    .
    .
    Code:
    xtype: 'tabpanel',
    region: 'center',
    activeTab: 0,
    stateId: 'tabpanel',
    stateEvents: ['tabchange'],
    getState: function(){
                  return {
                            activeTab: this.items.indexOf(this.getActiveTab())
                  };
    },
    .
    .
    .
    Any idea if what I'm attempting is even possible? I can't find any examples doing this. Please be gentle, I'm new to programming, not just Ext

    Thanks
    Andrew
    Last edited by TrotskyIcepick; 24 Mar 2010 at 5:47 AM. Reason: Not sure I made myself clear in original post

  2. #2
    Ext User
    Join Date
    Feb 2009
    Location
    Brazil
    Posts
    21

    Default

    yeah... I have the same question....
    Last edited by Julio Betta; 30 Mar 2010 at 8:52 AM. Reason: dont need quote

  3. #3

    Default Hrmmmm

    I'm not 100% sure on how well this will work for you, but what if you stored a cookie (in the client) that had some info about the tabs ? Then you could query the cookie and if it's there, decide how to proceed.

    Otherwise, you might have to do some magic using server-side session storage (i.e. 'HttpSession' in Java servlets, etc.)

    -Ryan

  4. #4

    Default

    The code I'm already using stores info on the tab state in a cookie. The problem is storing information about the newly generated tabs....I can't quite figure that out. I think I obviously need to store some kind of state info when tabs are created but I don't know what that info should be

  5. #5

    Default Okay...

    Ah, I see now.

    Okay, I'm no genius when it comes to ExtJS either, haven't specifically done anything with cookies in particular, but what you probably want to do is something like [ go here http://www.extjs.com/deploy/dev/docs/ and search for 'CookieProvider' for the docs ]:

    Code:
    // example, change for your uses
    var  cp = new Ext.state.CookieProvider({
           path: "/cgi-bin/",
           expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
    
           domain: "extjs.com"
       });
    
    cp.on("statechange", function(this, key, value) {
        // this gets called every time the cookie's state changes
    });
    
    Ext.state.Manager.setProvider(cp);
    From looking at the docs, there are other methods you would then use, like cp.get(), and cp.set(). You would use these to check other cookie values related to the # of tabs displayed and what links they would be. For instance:

    (in your code that adds tabs when links are clicked)

    Code:
    cp.set("yourapp_tabs", cp.encodeValue(something));
    and then elsewhere: cp.decodeValue(cp.get("yourapp_tabs")) and then do something with it.

    I *think* that's the right track for you. Any gurus want to confirm/assist?

  6. #6
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    The OP only has half the solution.

    You have to implement applyState to DO something with the state you saved. Otherwise, what's to be done with it?

  7. #7
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    None of rbastic's code is necessary at all.

    Just getState and applyState, and a stateId, and setting the CookieProvider.

  8. #8

    Default Ahhhhh

    I see now. Any chance we can get some documentation or an additional sample in that demonstrates this sort of thing?

    The docs weren't immediately clear when I tried to grok them earlier.

  9. #9
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default


  10. #10
    Sencha User mschwartz's Avatar
    Join Date
    Nov 2008
    Location
    San Diego, Peoples' Republic of California
    Posts
    2,061

    Default

    Last time I tried using this, it saved state of components by Ext.id() generated IDs. Those change if you change your code, so Ext would try to restore state of who-knows-what from the cookies.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •