In extjs4.1:
There are many way for store filtering . Some of code i give here
Filtering by single field:
Alternatively, if filters are configured with an
Filtering by single field:
To filter after the grid is loaded use the filterBy function.
=============================================
Defaults to:
Reverts to a view of the Record cache with no filtering applied.
There is difference between clearFilter() and filters.clear(). the boolean parameter of clearFilter() does Not prevent the store to be refreshed for e.g in a Grid, as you can see in the Documentation clearFilters(true) clears silently, means datachanged event doesn't fire. So if you want clearing your filters without refreshing the whole data and reloading the grid, as Davis said store.filters.clear() is the right way.
================================
For example if you filter a store a couple of times with the line
When store is filtered, most of the methods for accessing store data will be working only within the set of filtered records. Two notable exceptions are queryBy and getById.
queryBy( fn, [scope] )
fn : Function
The function to be called. It will be passed the following parameters:
==============================
There are many way for store filtering . Some of code i give here
Filtering by single field:
store.filter('eyeColor', 'Brown');
Alternatively, if filters are configured with an
id
, then existing filters store may be replacedby new filters having the same id
.Filtering by single field:
store.filter("email", /\.com$/);
Using multiple filters:store.filter([
{property: "email", value: /\.com$/},
{filterFn: function(item) { return item.get("age") > 10; }}
]);
Using Ext.util.Filter instances instead of config objects (note that we need to specify the root config option in this case):store.filter([
Ext.create('Ext.util.Filter', {
property: "email", value: /\.com$/, root: 'data'}),
Ext.create('Ext.util.Filter', {
filterFn: function(item) {
return item.get("age") > 10;
},
root: 'data'})
]);
When store is filtered, most of the methods for accessing store data will be working only within the set of filtered records. Two notable exceptions are queryBy and getById.
====================================
Filtering and sorting after the Store has been instantiated is
also easy.
you can write this code in store when store is create
filters: [{ property: 'firstName', value: /Ed/ }]
============================================
filters : Object[]/Function[]Array of Filters for this store. Can also be passed array of functions which will be used as the filterFn config for filters:
filters: [
function(item) {
return item.internalId > 0;
} ]
To filter after the grid is loaded use the filterBy function.
=============================================
filterOnLoad : BooleanIf true, any filters attached to this Store will be run after loading data, before the datachanged event is fired. Defaults to true, ignored if remoteFilter is true
Defaults to:
true
=======================================
clearFilter( [suppressEvent] )1Reverts to a view of the Record cache with no filtering applied.
- suppressEvent : Boolean (optional)If
true
the filter is cleared silently.
For a locally filtered Store, this means that the filter collection is cleared without firing the datachanged event.
For a remotely filtered Store, this means that the filter collection is cleared, but the store is not reloaded from the server.
That doesn't have the same result as store.clearFilter
. If you don't want to load the data again use store.clearFilter(true)
There is difference between clearFilter() and filters.clear(). the boolean parameter of clearFilter() does Not prevent the store to be refreshed for e.g in a Grid, as you can see in the Documentation clearFilters(true) clears silently, means datachanged event doesn't fire. So if you want clearing your filters without refreshing the whole data and reloading the grid, as Davis said store.filters.clear() is the right way.
================================
For example if you filter a store a couple of times with the line
store.filter([{property: "email", value: "mail"}])
the Store.filters collection will contain several instances of the same filter. Maybe this is desired in some cases? But I actually expected the filter property value (ie "email" in the case above) to be the "id" or key for the underlying MixedCollection, so when filtering again with the same property, it would replace the old filter value. As a workaround you could usestore.filter([{id: "email", property: "email", value: "mail"}])
when filtering again.
==========================
IMO this is a bug, Ext.data.AbstractStore#filters should be created this way in Ext.data.AbstractStore#constructor:me.filters = Ext.create('Ext.util.MixedCollection', false,function (o) { return o.property; });
=======================
store.clearFilter();
store.filter([
Ext.create('Ext.util.Filter', {filterFn: function(item) {
item.get('geraete_bez')
}})
]);
========================
filterBy( fn, [scope] )1
Filters by a function. The specified function will be called for each Record in this Store. If the function returns true
the Record is included, otherwise it is filtered out.When store is filtered, most of the methods for accessing store data will be working only within the set of filtered records. Two notable exceptions are queryBy and getById.
filterBy: function(fn, scope) { var me = this; me.snapshot = me.snapshot || me.data.clone(); me.data = me.queryBy(fn, scope || me); me.fireEvent('datachanged', me); me.fireEvent('refresh', me); },
=========================
queryBy( fn, [scope] )
Query all the cached records in this Store using a filtering function. The specified function will be called with each record in this Store. If the function returns
This method is not effected by filtering, it will always look from all records inside the store no matter if filter is applied or not.
true
the record is included in the results.This method is not effected by filtering, it will always look from all records inside the store no matter if filter is applied or not.
fn : Function
The function to be called. It will be passed the following parameters:
==============================
find( fieldName, value, [startIndex], [anyMatch], [caseSensitive], [exactMatch] ) : number- fieldName : StringThe name of the Record field to test.
- value : String/RegExpEither a string that the field value should begin with, or a RegExp to test against the field.
- startIndex : Number (optional)The index to start searching at
Defaults to:0
- anyMatch : Boolean (optional)True to match any part of the string, not just the beginning
Defaults to:false
- caseSensitive : Boolean (optional)True for case sensitive comparison
Defaults to:false
- exactMatch : Boolean (optional)True to force exact match (^ and $ characters added to the regex).
Defaults to:false
Returns
- NumberThe matched index or -1
=========
findBy( fn, [scope], [startIndex] ) : Number1
Find the index of the first matching Record in this Store by a function. If the function returnstrue
it is considered a match.
When store is filtered, finds records only within filter.
===============
findExact( fieldName, value, [startIndex] ) : NumberFinds the index of the first matching Record in this store by a specific field value. ...findRecord( fieldName, value, [startIndex], [anyMatch], [caseSensitive], [exactMatch] ) :Finds the first matching Record in this store by a specific field value. ...
Comments
Post a Comment