PDA

View Full Version : Property grid : dynamic items



ultramedia
15 Oct 2009, 8:21 PM
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...


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)

ultramedia
15 Oct 2009, 9:37 PM
Hey everyone,

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


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);
}
}
});

Condor
16 Oct 2009, 2:58 AM
I've made a feature request (http://www.extjs.com/forum/showthread.php?t=72709) 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:

Ext.override(Ext.grid.PropertyGrid, {
setPropertyName: function(property, name){
this.propertyNames[property] = name;
}
});

ultramedia
16 Oct 2009, 3:09 AM
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....

Zeebee
2 Dec 2009, 3:25 AM
Thx for this enhancement :) Just watch out using numbers in the label, the eval won't work.