1. #1
    Sencha User
    Join Date
    Jun 2010
    Posts
    36
    Vote Rating
    0
    Hakkert is on a distinguished road

      0  

    Default Answered: MVC change view from one to another in the controller

    Answered: MVC change view from one to another in the controller


    Hi

    I have a controller with two views. In one of the views a have a button with a click listener. On that click i want to change the view from one to the other. Whats the best way to do this?

    I already have the click listener in place so the only thing i need to know is how to switch views.

  2. Changing the view depends on your layout.

    It would be the same as adding/removing or showing/hiding parts of any widget in the framework. Card layouts would call setActiveItem(), whereas Fit layouts might have to completely destroy their children items.

    Assuming your application is simply a viewport displaying some panel, your controller would simply ask the viewport to hide/remove the existing view, and show/add the new view. Calling doLayout() might need to happen as well, depending on your setup.

  3. #2
    Sencha - Services Team arthurakay's Avatar
    Join Date
    Sep 2008
    Location
    Antioch, IL
    Posts
    1,346
    Answers
    60
    Vote Rating
    32
    arthurakay is a jewel in the rough arthurakay is a jewel in the rough arthurakay is a jewel in the rough

      0  

    Default


    Changing the view depends on your layout.

    It would be the same as adding/removing or showing/hiding parts of any widget in the framework. Card layouts would call setActiveItem(), whereas Fit layouts might have to completely destroy their children items.

    Assuming your application is simply a viewport displaying some panel, your controller would simply ask the viewport to hide/remove the existing view, and show/add the new view. Calling doLayout() might need to happen as well, depending on your setup.
    Arthur Kay
    Developer Relations Manager, Sencha Inc.

    Twitter | Sencha Chicago User Group

  4. #3
    Sencha User
    Join Date
    Jun 2010
    Posts
    36
    Vote Rating
    0
    Hakkert is on a distinguished road

      0  

    Default


    Maybe you can help.

    Code:
    var master = Ext.ComponentManager.get('idMasterView');
            var centerPanel = Ext.ComponentManager.get('idCenterPanel');
    
    
            var newCenterPanel = Ext.widget('mainCenterTabPanelView');
            newCenterPanel.id = 'idCenterPanel';
            newCenterPanel.name = 'idCenterPanel';
            newCenterPanel.region = 'center';
    
    
            newCenterPanel.isVisible(true);
            
            master.add(newCenterPanel);
    
    
            centerPanel.hide();
            newCenterPanel.show();
            master.doLayout();
    The centerPanel hides but the new panel doesn't show. I'm not sure why this is. Anyone an idea?

  5. #4
    Sencha - Services Team arthurakay's Avatar
    Join Date
    Sep 2008
    Location
    Antioch, IL
    Posts
    1,346
    Answers
    60
    Vote Rating
    32
    arthurakay is a jewel in the rough arthurakay is a jewel in the rough arthurakay is a jewel in the rough

      0  

    Default


    I'm guessing you're using a border layout... which doesn't allow you to add/remove children after it's been created.

    However, you can add/remove children on the component already existing in the "center" panel. Does that make sense?

    In other words, a container with "border" layout might have a panel in it's "center" region. Add/remove children to the panel... not the parent.
    Arthur Kay
    Developer Relations Manager, Sencha Inc.

    Twitter | Sencha Chicago User Group

Thread Participants: 1