Access TabPanel's Tabs in Controller.

  1. #1

    Access TabPanel's Tabs in Controller.

    Hello.

    I have a View with a TabPanel in a CSHTML file.

     
    X.TabPanel()
          .ID("TabPanel1")
          .Region(Region.Center)
          .Plugins(X.TabScrollerMenu().PageSize(100))

    I need to acces to the tabs to close someone or different operations when i click on a Button.

    The Controller code is like:


            public ActionResult onClick(string tabName)
            {
    
                TabPanel tabPanel= this.GetCmp<TabPanel>("TabPanel1");
                foreach(AbstractComponent tab in tabPanel.Items)
                {
    
                }
                return this.Direct();
            }
    But tabPanel.Ítems count is 0.

    Why? I have 5 tabs opened.

    If i write
    tabPanel.CloseTab(0, CloseAction.Destroy);
    i can close the first tab.
    But why the count is 0 and i can't do the for?

    Any Idea?
  2. #2
    The client-side State of your TabPanel is not persisted back to the server.
    Geoffrey McGill
    Founder
  3. #3
    Ok.


    Then, how i can send a list with the id's of the opened tabs from the view to the server (Controller)?

    Or it is not posible.

    somethink like? Really i don't know.
     
     X.Button()
     .Text("Update tabs")
     .DirectEvents(de => {
                         de.Click.Url = Url.Action("Button_Click");
                         de.Click.EventMask.ShowMask = true;
                         de.Click.ExtraParams.Add(TabPanel1.Items.Select(f=>f.text)));
                         }
     )
  4. #4
    Hello @sishco!

    That's exactly what you need to do. Pass the changes on client-side thru extra params. You might want to further review the answer I provided you here: http://forums.ext.net/showthread.php...548#post277548. It is really helpful to understand the concept of the ASPX page life cycle and how to effectively get the data you need when calling postback or ajax methods.

    EDIT: you may want to pass a list of IDs, as long as that's all you need to know of the tabs. Remember you can't get the rest of the information of the tab in code behind just by having its ID, but you can always queue JavaScript commands to run once the direct method has finished (and those commands could then apply changes to the tabs added client-side. Code behind only knows the page the way it was when first created/loaded.
    Last edited by fabricio.murta; Mar 10, 2016 at 7:36 PM.
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Ok.

    I found an example with a "MultiSelect", who send to the controller the selected Ã*tems.

    Multiselect code in CSHTML

    X.MultiSelect()
    .ID("MultiSelect3")
    .CustomConfig(c => c.Add(new ConfigItem("submitText", "false", ParameterMode.Raw)))
    .Items(
         X.ListItem().Text("Item 1").Value("1"),
         X.ListItem().Text("Item 2").Value("2"),
         X.ListItem().Text("Item 3").Value("3"),
         X.ListItem().Text("Item 4").Value("4"),
         X.ListItem().Text("Item 5").Value("5")
    )
    .SelectedItems(
          X.ListItem().Value("1"),
          X.ListItem().Value("3"),
          X.ListItem().Value("5")
    )
    The button code:

    X.Button()
     .Text("Submit")
    .DirectEvents(de => {
          de.Click.Action = "SubmitSelection1";
          de.Click.ExtraParams.Add(new Parameter("items", "App.MultiSelect3.getSubmitArray()", ParameterMode.Raw));
     })
    and the action code in the controller:

    List<ListItem> items = JSON.Deserialize<List<ListItem>>(Request.Params["items"]);

    Multiselect class has a ¿metod? called getSubmitArray (where is the documentation of the available methods for each component?).
    I am searching into http://docs-devel.sencha.com/extjs/6.0/ and i don't find this method, for example.

    I need to know the possible methods who i can use for each component. And i need a method for the Tabpanel who give me a list of the opened tabs.

    Any idea?

    Tanks.
  6. #6
    Hello @sishco!

    Can you point the link to the exact example you found, or the location you seen the example? Probably this function was custom-made for this purpose.

    If you look at this example: Submit MultiSelect Values.

    You can see all it does is bind the full response array as the argument to be sent thru the direct method.
    Fabrício Murta
    Developer & Support Expert
  7. #7
    Finally, i used a script on the page:


    X.Button()
    .Text("Submit")
    .DirectEvents(de => {
          de.Click.Action = "SubmitSelection1";
          de.Click.ExtraParams.Add(new Parameter("pestanasMarcadas", "getTabs", ParameterMode.Raw));
    
     })
    and the script:

    <script>
            var getTabs = function () {
                var output = App.TabPanel1;
    
                var userArray = new Array();
    
                for (i = 0; i < output.items.items.length; i++) {
                    userArray[i] = { 'Id': output.items.items[i].id, 'position': i, 'text': output.items.items[i].title };
                }
                var serializedUsers = JSON.stringify(userArray);
                return serializedUsers;
    
            };
     </script>
    On the controller:
             public class Pestana
            {
                public string Id;
                public string position;
                public string text;
            }
    
            public ActionResult onClick()
            {
                List<Pestana> pestanasMarcadas = JSON.Deserialize<List<Pestana>>(Request.Params["pestanasMarcadas"]);
                ......
             }
    Thanks for all.

Similar Threads

  1. [CLOSED] TabPanel tabs activating differently if remove tabs
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Mar 15, 2013, 3:41 PM
  2. Add tabs to the tabpanel
    By Vaishali in forum 1.x Help
    Replies: 1
    Last Post: Oct 04, 2012, 11:23 AM
  3. [CLOSED] [RAZOR] How to access ext.net controls from controller method
    By gets_gui in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Sep 13, 2012, 8:12 AM
  4. How to close all tabs in TabPanel
    By ozayExt in forum 1.x Help
    Replies: 3
    Last Post: Apr 27, 2012, 11:48 AM
  5. [CLOSED] How to access/reload store in razor views/controller
    By machinableed in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 02, 2012, 1:38 PM

Posting Permissions