-
18 Feb 2012 10:25 AM #1
Unanswered: filterBy not working..
Unanswered: filterBy not working..
So I'm trying to filter a store before a list loads
if I use:
The store is filtered and only the first record shows. When I use:Code:beforeRender: function() { this.store = myApp.stores.myStore; myApp.stores.myStore.load(); myApp.stores.myStore.filter('id',1) },
No filtering happens I just get all the records.Code:beforeRender: function() { this.store = myApp.stores.myStore; myApp.stores.myStore.load(); myApp.stores.myStore.filterBy(function(record, id){ if (id == 2) { return true } else { return false } }); },
The goal is to filter the store by an array of id's but I haven't gotten there because I can't seem to get filterBy to work. Can anyone seem anything I might be doing wrong?
EDIT:
I just added some breakpoints to the .js file and it appears if I break on the actual filter call the breakpoint is called. If I put a breakpoint inside that function it is completely ignored. Which makes me feel like the function is just not being called.Last edited by jonathansimmons; 18 Feb 2012 at 10:33 AM. Reason: added info
-
19 Feb 2012 7:07 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 435
- Answers
- 3113
I have used filterBy with no issues. You can optimize your code by doing:
Code:myApp.stores.myStore.filterBy(function(record, id){ return id === 2; });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
19 Feb 2012 8:16 AM #3
still not working...
still not working...
Yea I knew the code wasn't the prettiest but it was straight forward and I knew it would fire properly. Even still optimizing the code with your example doesn't work.
I just don't know whats wrong. Would would filter work but not filterBy?
I'm doing this in the beforerender listener on the list, after assigning the list store and loading it. Is there a better way to go about this? I assumed it was fine because it worked with filter but now I just don't know.
-
19 Feb 2012 4:03 PM #4
frustrated.
frustrated.
So I'm just frustrated. I must be doing something wrong I just wish I could see what.
To troubleshoot I created the following sample page in my app. Which in short just creates a model and stor with json data inline and filters it before the list is shown.
This works fine. The store is filter for contacts with ID of 1, 2 or 3.Code:Ext.regModel('Contact', { fields: ['id', 'lastName'] }); var store = new Ext.data.JsonStore({ model : 'Contact', sorters: 'lastName', getGroupString : function(record) { return record.get('lastName')[0]; }, data: [ {id: 1, lastName: 'Maintz'}, {id: 2, lastName: 'Dougan'}, {id: 3, lastName: 'Spencer'}, {id: 4, lastName: 'Avins'}, {id: 5, lastName: 'Conran'}, {id: 6, lastName: 'Kaneda'}, {id: 7, lastName: 'Mullany'}, {id: 8, lastName: 'Elias'}, {id: 9, lastName: 'Robinson'}, {id: 10, lastName: 'Maintz'}, {id: 12, lastName: 'Dougan'}, {id: 13, lastName: 'Spencer'}, {id: 14, lastName: 'Avins'}, {id: 15, lastName: 'Conran'}, {id: 16, lastName: 'Kaneda'}, {id: 17, lastName: 'Mullany'}, {id: 18, lastName: 'Elias'}, {id: 19, lastName: 'Robinson'} ] }); store.filterBy(function(record, id){ test = [1,2,3]; // console.log(record.get('id')) if (test.indexOf(record.get('id')) != -1) { console.log("true") console.log(record.get('id')) return true; } else { console.log("false") return false; } }); var list = new Ext.List({ fullscreen: true, scroll: true, itemTpl : '{id} {lastName}', grouped : true, indexBar: true, store: store }); myApp.views.myView = Ext.extend(Ext.Panel, { fullscreen: true, id: 'Contacts', iconCls: 'blank', title: "Contacts", scroll: "vertical", items: [list], html: "Contacts", listeners: { activate: function() { } } });
This simple just will not work where I need it to in the beforerender on a list. My big issue is that it truly appears to not even being doing the filterBy function. I say this as I've simple just run
and that never gets logged.Code:this.store.filterBy(function(record, id){ console.log('filterBy function called'); });
Everything else inside of the beforerender event works fine. So why would this not be run? Added breaks to the .js file confirms this as if I add a break to the line for the filterBy function itself it stops for the break but if I add it to any line inside the filterBy the break is never hit.
does anyone, ANYONE have any thoughts?
-
24 Apr 2012 1:41 AM #5
Have you ever solved this problem? I just hit the same issue and looking for solutions.
-
24 Apr 2012 7:16 AM #6
Hey zmagyar. I actually never did get this working. Shortly after this I moved to using Sencha Touch 2 which in my opinion has a bit of a learning curve. However I've been nothing but pleased with it and have not run into any issues like the code above.
Sorry that is not a beter answer.
-
24 Apr 2012 7:40 AM #7Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 435
- Answers
- 3113
When the filterBy executes, are we sure the store is loaded?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
24 Apr 2012 10:05 AM #8
Adding a console.log indicates the store itself is loaded (dumping the store the data member is fully populated) but the log placed inside the filterBy function never fires.
-
24 Apr 2012 10:22 AM #9Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 435
- Answers
- 3113
Do you do
or something likeCode:console.log(store.data);
Code:console.log(store.getCount());
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
24 Apr 2012 10:50 AM #10
Just
then browsing the dumped object.Code:console.log(store);


Reply With Quote