1. #1
    Ext User
    Join Date
    Aug 2009
    Posts
    18
    Vote Rating
    0
    ultramedia is on a distinguished road

      0  

    Default Property grid : dynamic items

    Property grid : dynamic items


    Hey everyone,

    I'm doing a thing at the moment where I would prefer to add properties to a property grid after creation (long story). I found an excellent thread for doing it in Ext 2 (thanks to condor) but had to tweak it (slightly) to get it going in Ext 3.

    Turns out it just needed propStore to be removed from Condors original script to be Ext 3 friendly. Seems to be working fine now so I thought I'd share in case it was useful to anyone else...

    Code:
        Ext.override(Ext.grid.PropertyGrid, {
            setProperty: function(property, value){
                this.source[property] = value;
                var r = this.store.getById(property);
                if(r){
                    // update property
                    r.set('value', value);
                }else{
                    // add property
                    this.store.add(new Ext.grid.PropertyRecord({name: property, value: value}, property));
                }
            },
            removeProperty: function(property){
                delete this.source[property];
                var r = this.store.getById(property);
                if(r){
                    // remove property
                    this.store.remove(r);
                }
            }
        });
    (apologies if this has already been done, I looked but I couldn't find it anywhere)

  2. #2
    Ext User
    Join Date
    Aug 2009
    Posts
    18
    Vote Rating
    0
    ultramedia is on a distinguished road

      0  

    Default


    Hey everyone,

    Slight update, this lets you label the property differently from its id in the property grid :

    Code:
        Ext.override(Ext.grid.PropertyGrid, {
            setProperty: function(property, label, value){
                eval('this.propertyNames.'+property+'="'+label+'"');
                this.source[property] = value;
                var r = this.store.getById(property);
                if(r){
                    // update property
                    r.set('value', value);
                }else{
                    // add property
                    this.store.add(new Ext.grid.PropertyRecord({name: property, value: value}, property));
                }
            },
            removeProperty: function(property){
                delete this.source[property];
                var r = this.store.getById(property);
                if(r){
                    // remove property
                    this.store.remove(r);
                }
            }
        });

  3. #3
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    94
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    I've made a feature request for some PropertyGrid enhancements (including this one).

    @ultramedia: Don't you know that 'eval' is evil (at least according to jslint)?
    And you don't even need it in this case:
    Code:
    Ext.override(Ext.grid.PropertyGrid, {
      setPropertyName: function(property, name){
        this.propertyNames[property] = name;
      }
    });

  4. #4
    Ext User
    Join Date
    Aug 2009
    Posts
    18
    Vote Rating
    0
    ultramedia is on a distinguished road

      0  

    Default


    That's DR evil. I didn't spend six years in evil medical school to be call mister thank you very much...

    But seriously though, thanks for that Condor, it's much better like that

    *edit* urk, yeah now that I look at it, mine was nasty ugly. Ah well....

  5. #5
    Sencha User Zeebee's Avatar
    Join Date
    Nov 2009
    Location
    zaventem
    Posts
    53
    Vote Rating
    0
    Zeebee is on a distinguished road

      0  

    Thumbs up


    Thx for this enhancement Just watch out using numbers in the label, the eval won't work.

Thread Participants: 2