Ext.NET
5.3.0
.NET Component Framework for Enterprise Level Apps
|
AjaxProxy is one of the most widely-used ways of getting data into your application. It uses AJAX requests to load data from the server, usually to be placed into a Store. Let's take a look at a typical setup. Here we're going to set up a Store that has an AjaxProxy. To prepare, we'll also set up a Model:Ext.regModel('User', { fields: ['id', 'name', 'email'] });//The Store contains the AjaxProxy as an inline configuration var store = new Ext.data.Store({ model: 'User', proxy: { type: 'ajax', url : 'users.json' } });store.load(); Our example is going to load user data into a Store, so we start off by defining a Model with the fields that we expect the server to return. Next we set up the Store itself, along with a proxy configuration. This configuration was automatically turned into an Ext.data.proxy.Ajax instance, with the url we specified being passed into AjaxProxy's constructor. It's as if we'd done this:new Ext.data.proxy.Ajax({ url: 'users.json', model: 'User', reader: 'json' }); A couple of extra configurations appeared here - model and reader. These are set by default when we create the proxy via the Store - the Store already knows about the Model, and Proxy's default Reader is JsonReader.Now when we call store.load(), the AjaxProxy springs into action, making a request to the url we configured ('users.json' in this case). As we're performing a read, it sends a GET request to that url (see actionMethods to customize this - by default any kind of read will be sent as a GET request and any kind of write will be sent as a POST request).LimitationsAjaxProxy cannot be used to retrieve data from other domains. If your application is running on http://domainA.com it cannot load data from http://domainB.com because browsers have a built-in security policy that prohibits domains talking to each other via AJAX.If you need to read data from another domain and can't set up a proxy server (some software that runs on your own domain's web server and transparently forwards requests to http://domainB.com, making it look like they actually came from http://domainA.com), you can use Ext.data.proxy.JsonP and a technique known as JSON-P (JSON with Padding), which can help you get around the problem so long as the server on http://domainB.com is set up to support JSON-P responses. See JsonPProxy's introduction docs for more details.Readers and WritersAjaxProxy can be configured to use any type of Reader to decode the server's response. If no Reader is supplied, AjaxProxy will default to using a JsonReader. Reader configuration can be passed in as a simple object, which the Proxy automatically turns into a Reader instance:var proxy = new Ext.data.proxy.Ajax({ model: 'User', reader: { type: 'xml', root: 'users' } });proxy.getReader(); //returns an XmlReader instance based on the config we supplied Url generationAjaxProxy automatically inserts any sorting, filtering, paging and grouping options into the url it generates for each request. These are controlled with the following configuration options:pageParam - controls how the page number is sent to the server (see also startParam and limitParam) sortParam - controls how sort information is sent to the server groupParam - controls how grouping information is sent to the server filterParam - controls how filter information is sent to the server Each request sent by AjaxProxy is described by an Operation. To see how we can customize the generated urls, let's say we're loading the Proxy with the following Operation:var operation = new Ext.data.Operation({ action: 'read', page : 2 }); Now we'll issue the request for this Operation by calling read:var proxy = new Ext.data.proxy.Ajax({ url: '/users' });proxy.read(operation); //GET /users?page=2 Easy enough - the Proxy just copied the page property from the Operation. We can customize how this page data is sent to the server:var proxy = new Ext.data.proxy.Ajax({ url: '/users', pagePage: 'pageNumber' });proxy.read(operation); //GET /users?pageNumber=2 Alternatively, our Operation could have been configured to send start and limit parameters instead of page:var operation = new Ext.data.Operation({ action: 'read', start : 50, limit : 25 });var proxy = new Ext.data.proxy.Ajax({ url: '/users' });proxy.read(operation); //GET /users?start=50&limit=25 Again we can customize this url:var proxy = new Ext.data.proxy.Ajax({ url: '/users', startParam: 'startIndex', limitParam: 'limitIndex' });proxy.read(operation); //GET /users?startIndex=50&limitIndex=25 AjaxProxy will also send sort and filter information to the server. Let's take a look at how this looks with a more expressive Operation object:var operation = new Ext.data.Operation({ action: 'read', sorters: [ new Ext.util.Sorter({ property : 'name', direction: 'ASC' }), new Ext.util.Sorter({ property : 'age', direction: 'DESC' }) ], filters: [ new Ext.util.Filter({ property: 'eyeColor', value : 'brown' }) ] }); This is the type of object that is generated internally when loading a Store with sorters and filters defined. By default the AjaxProxy will JSON encode the sorters and filters, resulting in something like this (note that the url is escaped before sending the request, but is left unescaped here for clarity):var proxy = new Ext.data.proxy.Ajax({ url: '/users' });proxy.read(operation); //GET /users?sort=[{"property":"name","direction":"ASC"},{"property":"age","direction":"DESC"}]&filter=[{"property":"eyeColor","value":"brown"}] We can again customize how this is created by supplying a few configuration options. Let's say our server is set up to receive sorting information is a format like "sortBy=name#ASC,age#DESC". We can configure AjaxProxy to provide that format like this:var proxy = new Ext.data.proxy.Ajax({ url: '/users', sortParam: 'sortBy', filterParam: 'filterBy',//our custom implementation of sorter encoding - turns our sorters into "name#ASC,age#DESC" encodeSorters: function(sorters) { var length = sorters.length, sortStrs = [], sorter, i;for (i = 0; i < length; i++) { sorter = sorters[i];sortStrs[i] = sorter.property + '#' + sorter.direction }return sortStrs.join(","); } });proxy.read(operation); //GET /users?sortBy=name::ASC,age::DESC&filterBy=[{"property":"eyeColor","value":"brown"}]We can also provide a custom encodeFilters function to encode our filters. More...
Classes | |
class | Builder |
class | Config |
Public Member Functions | |
AjaxProxy () | |
AjaxProxy.Builder | ToBuilder () |
override IControlBuilder | ToNativeBuilder () |
AjaxProxy (Config config) | |
Public Member Functions inherited from Ext.Net.BaseItem | |
virtual bool | HasExplicitValue (string name) |
void | EnsureDataBind () |
virtual void | Call (string name) |
virtual void | Call (string name, params object[] args) |
virtual void | AddScript (string script) |
virtual void | AddScript (string script, params object[] args) |
virtual bool | IsEmptyObject () |
T | Apply< T > (IApply config) |
BaseItem | Apply (object config) |
virtual void | LoadViewState (object state) |
virtual object | SaveViewState () |
virtual void | TrackViewState () |
void | SetDirty () |
virtual void | DataBind () |
Static Public Member Functions | |
static implicit | operator AjaxProxy (AjaxProxy.Config config) |
Properties | |
override string | InstanceOf [get] |
override string | Type [get] |
Alias More... | |
virtual ParameterCollection?? | Headers [get] |
Any headers to add to the Ajax request. Defaults to undefined. More... | |
virtual bool | Json [get, set] |
Send params as JSON object More... | |
virtual bool | Xml [get, set] |
Send params as XML object More... | |
virtual CRUDMethods?? | ActionMethods [get] |
Mapping of action name to HTTP request method. In the basic AjaxProxy these are set to 'GET' for 'read' actions and 'POST' for 'create', 'update' and 'destroy' actions. The Ext.data.proxy.Rest maps these to the correct RESTful methods. More... | |
virtual string | ActionMethodsProxy [get] |
virtual JFunction | GetMethod [get] |
Returns the HTTP method name for a given request. By default this returns based on a lookup on actionMethods. Parameters request : Ext.data.Request The request object Returns The HTTP method to use (should be one of 'GET', 'POST', 'PUT' or 'DELETE') More... | |
virtual string | Password [get, set] |
Most oData feeds require basic HTTP authentication. This configuration allows you to specify the password. More... | |
virtual bool | UseDefaultXhrHeader [get, set] |
Set this to false to not send the default Xhr header (X-Requested-With) with every request. This should be set to false when making CORS (cross-domain) requests. Defaults to true. More... | |
virtual string | Username [get, set] |
Most oData feeds require basic HTTP authentication. This configuration allows you to specify the username. More... | |
virtual bool | WithCredentials [get, set] |
This configuration is sometimes necessary when using cross-origin resource sharing. Defaults to false. More... | |
override ConfigOptionsCollection | ConfigOptions [get] |
Properties inherited from Ext.Net.ServerProxy | |
override string | InstanceOf [get] |
virtual CRUDUrls?? | API [get] |
Specific urls to call on CRUD action methods "read", "create", "update" and "destroy". The url is built based upon the action being executed [load|create|save|destroy] using the commensurate api property, or if undefined default to the configured Ext.data.Store.url. If the specific URL for a given CRUD action is undefined, the CRUD action request will be directed to the configured url. More... | |
virtual string | CacheString [get, set] |
The name of the cache param added to the url when using noCache (defaults to "_dc") More... | |
virtual string | DirectionParam [get, set] |
The name of the direction parameter to send in a request. This is only used when simpleSortMode is set to true. Defaults to 'dir'. More... | |
virtual ParameterCollection?? | ExtraParams [get] |
Extra parameters that will be included on every request. Individual requests with params of the same name will override these params when they are in conflict. More... | |
virtual string | FilterParam [get, set] |
The name of the 'filter' parameter to send in a request. Defaults to 'filter'. Set this to undefined if you don't want to send a filter parameter More... | |
virtual string | GroupParam [get, set] |
The name of the 'group' parameter to send in a request. Defaults to 'group'. Set this to undefined if you don't want to send a group parameter More... | |
virtual string | GroupDirectionParam [get, set] |
The name of the direction parameter to send in a request. This is only used when simpleGroupMode is set to true. Defaults to 'groupDir'. More... | |
virtual string | IDParam [get, set] |
The name of the parameter which carries the id of the entity being operated upon. Defaults to: "id" More... | |
virtual string | LimitParam [get, set] |
The name of the 'limit' parameter to send in a request. Defaults to 'limit'. Set this to undefined if you don't want to send a limit parameter More... | |
virtual bool | NoCache [get, set] |
Defaults to true. Disable caching by adding a unique parameter name to the request. Set to false to allow caching. Defaults to true. More... | |
virtual bool | AppendAction [get, set] |
virtual string | PageParam [get, set] |
The name of the 'page' parameter to send in a request. Defaults to 'page'. Set this to undefined if you don't want to send a page parameter More... | |
virtual ReaderCollection?? | Reader [get] |
The Ext.data.reader.Reader to use to decode the server's response. This can either be a Reader instance, a config object or just a valid Reader type name (e.g. 'json', 'xml'). More... | |
virtual bool | SimpleSortMode [get, set] |
Enabling simpleSortMode in conjunction with remoteSort will only send one sort property and a direction when a remote sort is requested. The directionParam and sortParam will be sent with the property name and either 'ASC' or 'DESC'. Defaults to: false More... | |
virtual bool | SimpleGroupMode [get, set] |
Enabling simpleGroupMode in conjunction with remoteGroup will only send one group property and a direction when a remote group is requested. The groupDirectionParam and groupParam will be sent with the property name and either 'ASC' or 'DESC'. Defaults to: false More... | |
virtual string | SortParam [get, set] |
The name of the 'sort' parameter to send in a request. Defaults to 'sort'. Set this to undefined if you don't want to send a sort parameter More... | |
virtual string | StartParam [get, set] |
The name of the 'start' parameter to send in a request. Defaults to 'start'. Set this to undefined if you don't want to send a start parameter More... | |
virtual int | Timeout [get, set] |
The number of milliseconds to wait for a response. Defaults to 30000 milliseconds (30 seconds). More... | |
virtual string | Url [get, set] |
The default URL to be used for requests to the server. More... | |
virtual string | UrlProxy [get] |
virtual string | StartParamProxy [get] |
virtual string | LimitParamProxy [get] |
virtual WriterCollection?? | Writer [get] |
The Ext.data.writer.Writer to use to encode any request sent to the server. This can either be a Writer instance, a config object or just a valid Writer type name (e.g. 'json', 'xml'). More... | |
ProxyListeners?? | Listeners [get] |
Client-side JavaScript Event Handlers More... | |
virtual JFunction | BuildUrl [get] |
Generates a url based on a given Ext.data.Request object. By default, ServerProxy's buildUrl will add the cache-buster param to the end of the url. Subclasses may need to perform additional modifications to the url. Parameters request : Ext.data.Request The request object Returns The url More... | |
override ConfigOptionsCollection | ConfigOptions [get] |
Properties inherited from Ext.Net.AbstractProxy | |
override string | InstanceOf [get] |
abstract string | Type [get] |
Alias More... | |
virtual bool | BatchActions [get, set] |
True to batch actions of a particular type when synchronizing the store. Defaults to true. More... | |
virtual string | BatchOrder [get, set] |
Comma-separated ordering 'create', 'update' and 'destroy' actions when batching. Override this to set a different order for the batched CRUD actions to be executed in. Defaults to 'create,update,destroy' More... | |
string | PropertyName [get] |
override ConfigOptionsCollection | ConfigOptions [get] |
Properties inherited from Ext.Net.BaseItem | |
virtual string | InstanceOf [get] |
ItemState | State [get] |
virtual DefaultValueMode | DefaultValueMode [get, set] |
virtual bool | DesignMode [get] |
bool | AutoDataBind [get, set] |
ResourceManager | ResourceManager [get] |
virtual Control | Owner [get, set] |
The Owner Control for this Listener. More... | |
virtual bool | IsDefault [get] |
Does this object currently represent it's default state. More... | |
bool | IsTrackingViewState [get] |
EventHandlerList | Events [get] |
EventHandler | DataBinding |
Control?? | BindingContainer [get] |
virtual ConfigItemCollection?? | CustomConfig [get] |
Collection of custom js config More... | |
virtual ConfigOptionsCollection | ConfigOptions [get] |
virtual ConfigOptionsExtraction | ConfigOptionsExtraction [get] |
System.Web.Mvc.HtmlHelper?? | HtmlHelper [get, set] |
Properties inherited from Ext.Net.IXObject | |
ConfigOptionsCollection | ConfigOptions [get] |
ConfigOptionsExtraction | ConfigOptionsExtraction [get] |
DefaultValueMode | DefaultValueMode [get, set] |
Properties inherited from Ext.Net.IAlias | |
string | PropertyName [get] |
Additional Inherited Members | |
Protected Member Functions inherited from Ext.Net.BaseItem | |
BaseItem (Control owner) | |
BaseItem () | |
virtual void | OwnerUpdate (Control owner) |
virtual void | OnDataBinding (EventArgs e) |
AjaxProxy is one of the most widely-used ways of getting data into your application. It uses AJAX requests to load data from the server, usually to be placed into a Store. Let's take a look at a typical setup. Here we're going to set up a Store that has an AjaxProxy. To prepare, we'll also set up a Model:
Ext.regModel('User', { fields: ['id', 'name', 'email'] });
//The Store contains the AjaxProxy as an inline configuration var store = new Ext.data.Store({ model: 'User', proxy: { type: 'ajax', url : 'users.json' } });
store.load(); Our example is going to load user data into a Store, so we start off by defining a Model with the fields that we expect the server to return. Next we set up the Store itself, along with a proxy configuration. This configuration was automatically turned into an Ext.data.proxy.Ajax instance, with the url we specified being passed into AjaxProxy's constructor. It's as if we'd done this:
new Ext.data.proxy.Ajax({ url: 'users.json', model: 'User', reader: 'json' }); A couple of extra configurations appeared here - model and reader. These are set by default when we create the proxy via the Store - the Store already knows about the Model, and Proxy's default Reader is JsonReader.
Now when we call store.load(), the AjaxProxy springs into action, making a request to the url we configured ('users.json' in this case). As we're performing a read, it sends a GET request to that url (see actionMethods to customize this - by default any kind of read will be sent as a GET request and any kind of write will be sent as a POST request).
Limitations
AjaxProxy cannot be used to retrieve data from other domains. If your application is running on http://domainA.com it cannot load data from http://domainB.com because browsers have a built-in security policy that prohibits domains talking to each other via AJAX.
If you need to read data from another domain and can't set up a proxy server (some software that runs on your own domain's web server and transparently forwards requests to http://domainB.com, making it look like they actually came from http://domainA.com), you can use Ext.data.proxy.JsonP and a technique known as JSON-P (JSON with Padding), which can help you get around the problem so long as the server on http://domainB.com is set up to support JSON-P responses. See JsonPProxy's introduction docs for more details.
Readers and Writers
AjaxProxy can be configured to use any type of Reader to decode the server's response. If no Reader is supplied, AjaxProxy will default to using a JsonReader. Reader configuration can be passed in as a simple object, which the Proxy automatically turns into a Reader instance:
var proxy = new Ext.data.proxy.Ajax({ model: 'User', reader: { type: 'xml', root: 'users' } });
proxy.getReader(); //returns an XmlReader instance based on the config we supplied Url generation
AjaxProxy automatically inserts any sorting, filtering, paging and grouping options into the url it generates for each request. These are controlled with the following configuration options:
pageParam - controls how the page number is sent to the server (see also startParam and limitParam) sortParam - controls how sort information is sent to the server groupParam - controls how grouping information is sent to the server filterParam - controls how filter information is sent to the server Each request sent by AjaxProxy is described by an Operation. To see how we can customize the generated urls, let's say we're loading the Proxy with the following Operation:
var operation = new Ext.data.Operation({ action: 'read', page : 2 }); Now we'll issue the request for this Operation by calling read:
var proxy = new Ext.data.proxy.Ajax({ url: '/users' });
proxy.read(operation); //GET /users?page=2 Easy enough - the Proxy just copied the page property from the Operation. We can customize how this page data is sent to the server:
var proxy = new Ext.data.proxy.Ajax({ url: '/users', pagePage: 'pageNumber' });
proxy.read(operation); //GET /users?pageNumber=2 Alternatively, our Operation could have been configured to send start and limit parameters instead of page:
var operation = new Ext.data.Operation({ action: 'read', start : 50, limit : 25 });
var proxy = new Ext.data.proxy.Ajax({ url: '/users' });
proxy.read(operation); //GET /users?start=50&limit=25 Again we can customize this url:
var proxy = new Ext.data.proxy.Ajax({ url: '/users', startParam: 'startIndex', limitParam: 'limitIndex' });
proxy.read(operation); //GET /users?startIndex=50&limitIndex=25 AjaxProxy will also send sort and filter information to the server. Let's take a look at how this looks with a more expressive Operation object:
var operation = new Ext.data.Operation({ action: 'read', sorters: [ new Ext.util.Sorter({ property : 'name', direction: 'ASC' }), new Ext.util.Sorter({ property : 'age', direction: 'DESC' }) ], filters: [ new Ext.util.Filter({ property: 'eyeColor', value : 'brown' }) ] }); This is the type of object that is generated internally when loading a Store with sorters and filters defined. By default the AjaxProxy will JSON encode the sorters and filters, resulting in something like this (note that the url is escaped before sending the request, but is left unescaped here for clarity):
var proxy = new Ext.data.proxy.Ajax({ url: '/users' });
proxy.read(operation); //GET /users?sort=[{"property":"name","direction":"ASC"},{"property":"age","direction":"DESC"}]&filter=[{"property":"eyeColor","value":"brown"}] We can again customize how this is created by supplying a few configuration options. Let's say our server is set up to receive sorting information is a format like "sortBy=name#ASC,age#DESC". We can configure AjaxProxy to provide that format like this:
var proxy = new Ext.data.proxy.Ajax({ url: '/users', sortParam: 'sortBy', filterParam: 'filterBy',
//our custom implementation of sorter encoding - turns our sorters into "name#ASC,age#DESC" encodeSorters: function(sorters) { var length = sorters.length, sortStrs = [], sorter, i;
for (i = 0; i < length; i++) { sorter = sorters[i];
sortStrs[i] = sorter.property + '#' + sorter.direction }
return sortStrs.join(","); } });
proxy.read(operation); //GET /users?sortBy=name::ASC,age::DESC&filterBy=[{"property":"eyeColor","value":"brown"}]
We can also provide a custom encodeFilters function to encode our filters.
|
inline |
|
inline |
|
inlinestatic |
|
inline |
|
inlinevirtual |
Reimplemented from Ext.Net.BaseItem.
Reimplemented in Ext.Net.RestProxy, and Ext.Net.ODataProxy.
|
get |
Mapping of action name to HTTP request method. In the basic AjaxProxy these are set to 'GET' for 'read' actions and 'POST' for 'create', 'update' and 'destroy' actions. The Ext.data.proxy.Rest maps these to the correct RESTful methods.
|
getprotected |
|
get |
|
get |
Returns the HTTP method name for a given request. By default this returns based on a lookup on actionMethods. Parameters request : Ext.data.Request The request object Returns The HTTP method to use (should be one of 'GET', 'POST', 'PUT' or 'DELETE')
|
get |
Any headers to add to the Ajax request. Defaults to undefined.
|
get |
|
getset |
Send params as JSON object
|
getset |
Most oData feeds require basic HTTP authentication. This configuration allows you to specify the password.
|
getprotected |
Alias
|
getset |
Set this to false to not send the default Xhr header (X-Requested-With) with every request. This should be set to false when making CORS (cross-domain) requests. Defaults to true.
|
getset |
Most oData feeds require basic HTTP authentication. This configuration allows you to specify the username.
|
getset |
This configuration is sometimes necessary when using cross-origin resource sharing. Defaults to false.
|
getset |
Send params as XML object