PDA

View Full Version : How to set default values for Ext components?



abraxxa
8 Jun 2009, 2:29 AM
The tutorials only tell how to create your own components based on the ExtJS ones but not how to modifiy the defaults of ExtJS components which is often enough.

I tried the following different approaches in my app.js but none of them worked:


Ext.apply(Ext.data.HttpProxy, {
disableCaching:false
});

Ext.data.HttpProxy.disableCaching = false;

Ext.data.HttpProxy.apply({disableCaching:false});

Animal
8 Jun 2009, 2:34 AM
Ext.data.HttpProxy.prototype.disableCaching = false;

abraxxa
8 Jun 2009, 2:37 AM
Thanks for the ultra-quick response Animal!

I tried in my Ext.onready function and also before it but the http requests still have the _dc=randomnumber params applied.

Animal
8 Jun 2009, 2:40 AM
It's not a config of HttpProxy, so it won't have an effect.

It's a config of Ext.data.Connection

abraxxa
8 Jun 2009, 2:45 AM
That did it!

This way of setting defaults should be added to your Tutorial: http://extjs.com/learn/Tutorial:Creating_new_UI_controls

Should I edit the tutorial it and add some lines and you review it?

Animal
8 Jun 2009, 2:48 AM
I don't think it's really a part of that.

It's just basic class manipulation. If there's a tutorial somewhere about classes, the prototype is probably mentioned.

abraxxa
8 Jun 2009, 3:17 AM
To sum up if I want to change a config option I have to call Ext.[Component].prototype.option = value;?
If I want to set the new restful option for all my JsonStore's can I set it with Ext.data.JsonStore.prototype.restful = true; although it's inherited from Ext.data.Store?

Animal
8 Jun 2009, 4:00 AM
Yes, that's part of Javascript.

Constructors have prototypes which contain shared properties.

Usually these are functions - that's how we get member functions shared among all instances.

But it's also possible to put default values of properties in there. It's just a shared object used to resolve property references if a named property is not in the instance.

Plenty of Javascript tutorials will cover the prototype.

abraxxa
8 Jun 2009, 4:31 AM
Thanks, I wasn't aware of that and already found some reading on google about prototypes.

I just tried to override the paramNames of the Store but failed.
How is this different from the restful parameter?


Ext.data.Store.prototype.paramNames = {
start:'list_start',
limit:'list_count',
sort:'list_sort',
dir:'list_dir'
};

In the extjs code I can see that Store doesn't inherit from anything else and sets the paramNames this way:


this.paramNames = {
"start" : "start",
"limit" : "limit",
"sort" : "sort",
"dir" : "dir"
};

while restful is applied with Ext.extend:


Ext.extend(Ext.data.Store, Ext.util.Observable, {
restful: false,
}

Animal
8 Jun 2009, 4:39 AM
IMHO, Store should default them through the prototype, not explicitly setting them.

Ext.extend sest properties in the prototype (of course)

abraxxa
8 Jun 2009, 5:05 AM
Does this mean it's a bug?

Animal
8 Jun 2009, 6:05 AM
No.

abraxxa
8 Jun 2009, 6:08 AM
IMHO, Store should default them through the prototype, not explicitly setting them.

Ext.extend sest properties in the prototype (of course)

Is my code wrong, cause it doesn't work?


Ext.data.Store.prototype.paramNames = {
start:'list_start',
limit:'list_count',
sort:'list_sort',
dir:'list_dir'
};

Animal
8 Jun 2009, 6:09 AM
That code in the constructor overrides it.

That's why I posted http://extjs.com/forum/showthread.php?t=70658

abraxxa
8 Jun 2009, 6:17 AM
Awesome, thanks!

I've subscribed to the thread to not miss follow ups.