View Full Version : Rest / AJAX proxy and using remoteFilter

20 Aug 2012, 7:56 PM
Hey guys, I'm new to Ext, as I'm working on a Sencha 2 app at the moment.

I'm having a hell of a time trying to do what should be quite simple IMHO. I'm hitting a REST API, using a slightly modified REST/AJAX proxy. This proxy supports loading of data using an "is_archived" param, to which I can either pass "true" or "false".

I have a view that I'd like to show archived/unarchived items in a list. My first idea was to use the "remoteFilter" property of my store, and try to call store.filter('is_archived', false) ...

That didn't turn out well as it was constructing URLs like this:


...when what I really want is an URL like this:


What am I doing wrong?

21 Aug 2012, 2:44 PM
What does your model/proxy/store look like?


21 Aug 2012, 4:22 PM
Hey Scott, thanks for the response.

Does it really matter what my code looks like? Assume it's basic, simple proxy/model/store configuration. All I'm asking is how to pass arbitrary parameters to a remote REST API. Why is this so difficult to do?

It seems that Sencha/Ext make a lot of assumptions about remote APIs which will be downright wrong for 99% of the services out there. For instance, when I hit any of my API endpoints, it automatically tacks on &page=1&start=0&limit=25 ...

21 Aug 2012, 4:49 PM
Nevermind...I found it. Looks like using the 'proxy' config on my store, and 'extraParams' inside that is going to be the ticket.

Now I have 2 stores setup ...one for "open" projects, one for "archived" projects.

An example for anyone who googles this:

Ext.define('MyApp.store.ProjectsArchived', {
extend: 'MyApp.store.Projects',
requires: ['MyApp.proxy.Rest', 'MyApp.store.Projects'],
config: {
proxy: {
extraParams: { is_archived: true }
filters: [{ property: 'is_archived', value: true }]

23 Aug 2012, 8:48 AM
If you can guarantee that there will always be only one filter property then an easy way to do this is to override 'encodeFilters' on the proxy.

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.proxy.Server-method-encodeFilters (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.data.proxy.Server-method-encodeFilters)