View Full Version : How can I query a store?

14 Feb 2012, 2:03 PM
In ext3 I could do something like this:

var aRecords = store.query('FIELD_TYPE', 'field');

In ext4 I have only store.queryBy, which I don't really like to use.

Do you know any good alternative to store.query from ext3?


14 Feb 2012, 2:18 PM
You will need to use queryBy.

29 May 2012, 5:24 AM
If we could open a bug about dropped functionality from Ext JS 3.x to 4.x that would be a good case.

The converter/migration framework provided by Sencha ignore this dropped API,. and when we look at the implementation in 3.4 it delegate to createFilterFn, which still exist in Ext JS 4.x but it's a private method, see http://docs.sencha.com/ext-js/3-4/source/Store.html#Ext-data-Store-method-query.

In other words, the cost of still supporting the old function seems to be very low.

29 May 2012, 6:38 AM
I ended up writing "backward" compatibility functions.
For this case:

//ext3 compatibility
Ext.override(Ext.data.Store, {

* Queries the store by the specified field and value
queryExact : function(field, value){
return this.queryBy(function(rec) {
return rec.get(field) == value;

* Returns all records in the store
queryAll : function(field, value){
return this.queryBy(function(rec) {
return true;

* Get the Record with the specified id.
* @param {String} id The id of the Record to find.
* @return {Ext.data.Model} The Record with the passed id. Returns null if not found.
getByInternalId: function(id) {
return (this.snapshot || this.data).findBy(function(record) {
return record.internalId === id;
});//ext3 compatibility