Hybrid View
-
1 Apr 2008 4:12 PM #1
filtering a jsonstore
filtering a jsonstore
hi,
i have a grouping store that I'd like to filter by a particular field in the JSON data, but am not sure how the filtering mechanism works
here's my GroupingStore:
I am grouping by the status field, but that field is sometimes null. How would I filter out the nulls so that those rows don't appear in the grid? Do i do it on the GroupingStore or the JsonReader?Code:var store = new Ext.data.GroupingStore({ url: "/data/list.js", reader: new Ext.data.JsonReader({ root: "rows", totalProperty: 'results', fields:[ {name: 'title'}, {name: 'filename'}, {name: 'status'}, {name: 'type'}, {name: 'size'} ] }), sortInfo: { field: 'title', direction: "ASC" }, groupField: 'status' });
thanks for any tips!
-
1 Apr 2008 4:21 PM #2
just a quick follow-up. i saw that there is a filterBy method on GroupingStore, so i tried the following, expecting to see some output in the firebug console
i was expecting to see the arguments passed to filterBy in the firebug console, but didn't see any output. am i going down the right path?Code:var store = new Ext.data.GroupingStore({ url: "/data/list.js", reader: new Ext.data.JsonReader({ root: "rows", totalProperty: 'results', fields:[ {name: 'title'}, {name: 'filename'}, {name: 'status'}, {name: 'type'}, {name: 'size'} ] }), sortInfo: { field: 'title', direction: "ASC" }, groupField: 'status', filterBy: function(a,b){ console.log("a:" +a) console.log("b:" +b) } });
thanks
-
1 Apr 2008 10:58 PM #3
i figured this one out, after stumbling through a few mistakes, so I'm posting here for the archive in the hope that this will save someone some headache down the line

1) i erred and misread the API docs thinking the filterBy() was a config option, when it is actually a method
2) then i erred by calling filterBy() before store.load() was called
3) i then called store.filterBy() after store.load(), but forgot that store.load() is asynchronous, so filterBy() is called before the actual store is loaded
4) Finally calling filterBy() in the callback to store.load() got me to where I needed to be
here's the complete code
Code:var store = new Ext.data.GroupingStore({ url: "/data/list.js", reader: new Ext.data.JsonReader({ root: "rows", totalProperty: 'results', fields:[ {name: 'title'}, {name: 'filename'}, {name: 'status'}, {name: 'type'}, {name: 'size'} ] }), sortInfo: { field: 'title', direction: "ASC" }, groupField: 'status' }); //load the store store.load({ // the filterBy needs to happen in this callback since load() is asynchronous callback: function() { store.filterBy(function(record){ if (record.get("status") != "") { return true; } return false; }); } });
-
2 Nov 2012 7:51 AM #4
And your solution(4) works great for a plain json store without grouping! I didn't know that the filterBy() need to go go INSIDE the load(). It actually works in that location
.
Thanks very much for these appends!
dkahl


Reply With Quote