Results 1 to 6 of 6

Thread: Conditionally hide/show widget in widgetcolumn on render

  1. #1
    Sencha Premium Member
    Join Date
    Dec 2010
    Posts
    24

    Default Answered: Conditionally hide/show widget in widgetcolumn on render

    Hi,

    I have been trying to figure out how to do this. I have a simple grid with a simple button in the widgetcolumn. I would like it to be hidden or displayed based on some conditions when the store is loaded into the grid.

    My widget column is simply
    Code:
    columns: [....., {
       xtype: 'widgetcolumn',
       widget: {
          xtype: 'button',
          text: 'Hello',
          handler: function(btn){
              var rec = btn.getWidgetRecord();
          },
          hidden: true|false, // so how do I make it hidden or shown?
          listeners: {
                afterrender: function(btn){
                     btn.getWidgetRecord(); // returns null so there's nothing I can do here.
                }
          }
       }
    }]
    Is there any workaround or hack I can do to achieve this?

    Thank you

  2. Use the onWidgetAttach method. It's missed being documented (and fixed, will be in the next release) however it is part of the public API:

    Code:
    Ext.onReady(function() {
        new Ext.grid.Panel({
            renderTo: document.body,
            width: 400,
            height: 200,
            store: {
                fields: ['name', 'score'],
                data: [{
                    name: 'Foo',
                    score: 80
                }, {
                    name: 'Bar',
                    score: 30
                }, {
                    name: 'Baz',
                    score: 55
                }]
            },
            columns: [{
                flex: 1,
                text: 'Name',
                dataIndex: 'name'
            }, {
                xtype: 'widgetcolumn',
                width: 100,
                widget: {
                    xtype: 'button',
                    text: 'Pass'
                },
                onWidgetAttach: function(column, widget, record) {
                    widget.setVisible(record.get('score') > 50);
                }
            }]
        });
    });

  3. #2
    Sencha Premium User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258
    Answers
    759

    Default

    Use the onWidgetAttach method. It's missed being documented (and fixed, will be in the next release) however it is part of the public API:

    Code:
    Ext.onReady(function() {
        new Ext.grid.Panel({
            renderTo: document.body,
            width: 400,
            height: 200,
            store: {
                fields: ['name', 'score'],
                data: [{
                    name: 'Foo',
                    score: 80
                }, {
                    name: 'Bar',
                    score: 30
                }, {
                    name: 'Baz',
                    score: 55
                }]
            },
            columns: [{
                flex: 1,
                text: 'Name',
                dataIndex: 'name'
            }, {
                xtype: 'widgetcolumn',
                width: 100,
                widget: {
                    xtype: 'button',
                    text: 'Pass'
                },
                onWidgetAttach: function(column, widget, record) {
                    widget.setVisible(record.get('score') > 50);
                }
            }]
        });
    });

  4. #3
    Sencha Premium Member
    Join Date
    Dec 2010
    Posts
    24

    Default Thanks

    you're almost wrong but got it solved with that config. Thanks a lot.

    Should be
    Code:
    onWidgetAttach(widget, record)

  5. #4
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Hillsborough, NC
    Posts
    429
    Answers
    3

    Default

    What if I do not want to add the widget based upon a field in the record?

    Is there a way to cancel adding the widget? Or do I just hide it?

    For example, I have a tree panel and only want the widgets on leafs.

  6. #5
    Sencha User
    Join Date
    Oct 2014
    Location
    New York
    Posts
    1

    Default

    Quote Originally Posted by worthlutz View Post
    What if I do not want to add the widget based upon a field in the record?
    Can someone answer this for me as well? Many thanks in advance...

  7. #6
    Sencha User
    Join Date
    Sep 2011
    Posts
    17

    Default

    This doesnt seem to work for me at all, the widget variable has no function setVisible, nor a visible field

Posting Permissions

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