[CLOSED] Dynamically adding

  1. #1

    [CLOSED] Dynamically adding


    I'm trying to dynamically add items to a panel using my controller (it needs to happen when I push a button).

    I've got it adding to the panel in the code, but it doesn't appear on screen once the result is returned.

    Here's some code:

    public ActionResult LoadStyles()
        List<vw_ClothingStyles> styles = (from x in db.vw_ClothingStyles
                                          select x).ToList();
        Panel mainStylesPanel = X.GetCmp<Panel>("StyleRowPanel");
        foreach (vw_ClothingStyles style in styles)
            Panel panel = new Panel()
                FactoryAlias = "StyleCardPanel"
        return this.Direct();
    I can also give you the code for my main panel if needed :)
    Last edited by fabricio.murta; Oct 25, 2019 at 9:41 PM.
  2. #2
    Hello @cslocus!

    Please refer to this example for proper dynamic components adding:
    - XRender > Basic > Add Items

    You may also be interested in dynamic partial rendering, a technique that scales up the complexity of the code, yet helps in reusage:
    - Dynamic Partial Rendering > Add Tab example in MVC Examples Explorer

    Basically, you should not, from the rendered component, add an item to it. You should, from the item you want, add it to the rendered panel. This logic may sound strange at first, but it changes how scripts are actually called and built when the response is sent.

    While the first approach works during initial page load (where the components' configuration objects are being populated, before page rendering), the second approach ("add it to") is appropriate to change already rendered components, taking advantage of pontual update of the component (instead of re-rendering the whole component).

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3

    I've decided to use a dataview and instead store my data inside the tpl, as I'm not sure I was clear enough in my original question in order for you to understand the specs.

    Please close the thread :)
  4. #4
    Hello! And thanks for the feedback!

    Okay, closing; and yes, I thought of "dynamically adding components" and not "items". I hope the solution with dataview works well for you; it is very flexible.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Adding a new MenuItem dynamically
    By vadym.f in forum 3.x Premium Help
    Replies: 4
    Last Post: Aug 13, 2015, 12:42 PM
  2. [CLOSED] dynamically adding columns to gridpanel
    By sharmav1 in forum 2.x Premium Help
    Replies: 3
    Last Post: Jun 27, 2015, 10:41 PM
  3. slow dynamically adding a TabPanel
    By d3graph in forum 2.x Help
    Replies: 0
    Last Post: Dec 04, 2014, 6:50 AM
  4. Adding a GroupTabPanel Dynamically
    By Sesshoumaru in forum 2.x Help
    Replies: 4
    Last Post: Oct 04, 2012, 7:35 PM
  5. adding tabs dynamically
    By n_s_adhikari@rediffmail.com in forum 1.x Help
    Replies: 3
    Last Post: Nov 16, 2009, 8:29 AM

Posting Permissions