Results 1 to 2 of 2

Thread: Conditional configuration for Components

  1. #1
    Sencha User
    Join Date
    Oct 2012
    Vote Rating

    Default Conditional configuration for Components


    I'm creating this thread to talk about conditional configuration for components.

    Even if in someway it breaks a bit the MVC style, I think being able to do something like:

    xtype: 'label',
    if (case) {text: 'MycaseText'}
    else {text: 'MycaseText'}

    would be freaking awesome!

    The reason is:

    When you build your UI, you end up with a big stack of components, all of them in a specific order and in specific containers.

    It may happen sometimes that you have restrictions modifying your component needs.

    I will take my case: User restrictions

    An administrator can update, but not a basic User for example. Of course it is simple to hide some button, but when it comes to: not have a specific column in a grid, not have the editcell plugin of the grid, change a component type for that user etc....

    It become quite difficult to have components using xtype in one another, and we finish creating most of them before with the conditions, and in the end a lot of copy of the same code with few changes.

    Now let's see what you thinks, and if some of you have some tricks or good ideas

  2. #2
    Sencha User existdissolve's Avatar
    Join Date
    Jan 2010
    Vote Rating


    For your first example, you could easily do that anyway with a ternary operator.

    PHP Code:
    text: case=='something' 'MycaseText' 'Some other text'

    More more intricate stuff, what I've done before is to do conditional stuff in initComponent. For example, with grid columns, sometimes I'll do this:

    PHP Code:
    Ext.define('MyGrid', {
    title'My Grid',
    initComponent: function() {
    me this
    columns = [],
    somevalue ) {
    column = { ... };
    columns.pushcolumn );
    column = { ... };
    columns.pushcolumn );
    Ext.applyIf(me, {
    me.callParentarguments )

    Of course, in the case of really specific grid configurations, it's probably a lot easier to build the correct config outside of the grid definition, and then just reconfigure it with the correct one.

Tags for this Thread

Posting Permissions

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