PDA

View Full Version : Filters in sencha touch



emm
20 Jul 2011, 7:01 PM
Hey guys,
I am trying to user filters and was wondering if you encountered any issue like I did. Or I must be doing something wrong!
I have a view with a list linked to a store where I want to display only records where attribute can_communicate_to_current_user is set to false.
I tried different ways of doing this.

1/ Applying the filter to the store:

Ext.regStore('Bomb', {
model: 'User',
autoLoad: false,
proxy: {
type: 'ajax',
url: APP_DOMAIN_URL + '/users',
actionMethods: {
read: 'GET'
},
extraParams: {
within: 50
},
reader: {
type: 'json',
totalProperty: 'total',
root: 'data'
}
},
filters: [
{
property : 'can_communicate_to_current_user',
value: false
}
],
});
That returns a 500 error from the server as it doesn't like that we added parameters to the request:


_dc:1311216601992
within:5
limit:25
filter:[{"property":"can_communicate_to_current_user","value":"false"}]
Normaler this filer parameter is not sent.

I tried with specifying a filter function, like this:


filters: [
function (o,k){
return (o.data.relationship_status.accepted == false) ;
}
]

but I get the same error from server.
Then I was stuck so I tried to filter in the view

2/Filter in the list


items: [{
xtype: 'list',
store: 'Bomb',
filters: [
{
property : 'can_communicate_to_current_user',
value: false
}
],
....

But the list is not filtered at all!
I tried with a filter function as well but that didn't work neither.
Then I tried something ugly...

3/ The only thing that seems to work is by doing this:


items: [{
xtype: 'list',
store: 'Bomb',
prepareData: function(data){
return (data.can_communicate_to_current_user == false)? data:undefined;
},
....

But that leaves blank items in the list, which is not really nice to see for the end user...

Any hint on what I did wrong with filters?
Thank you guys!
Emmanuel

art.dev.ext
21 Jul 2011, 4:25 AM
1/ Try to set
filterParam:null
on your Proxy

If it does not work, check that store.filterOnLoad==true and store.remoteFilter == false

2/ Anyway and according to the documentation, there is not "filter" property on Ext.List

You can filter store after loaded event :
store.filter("prop","value") or store.filterBy(function)

emm
21 Jul 2011, 5:03 AM
:D
That fixed the issue!
Thank you Master of Filters

art.home.ext
16 Aug 2011, 1:00 PM
Filtering is definitely not my cup of tea...
I was spending my time in debugging it with sencha-touch-debug when you created this thread.
I would not have been able to give you the same response today
I've overshadowed it
Store configuration properties conflicts drive me crazy...