PDA

View Full Version : Simple doubts using Filter in Ext1



franklt69
1 Mar 2007, 1:50 PM
Hi I am testing the filter but I need some information about how to do more complex condition,
I have a column Flag, it can have ('0', '1', '2', '3') values

I set this filter and work ok
ds.filter('Flag', 1);//show all with flag in 1

but I need now show all where Flag <> 1 ( I mean I need show all record where Flag is different 1)

how I can do it?

kind regards
Frank

JeffHowden
1 Mar 2007, 2:00 PM
You have two options.

1) Pass a regex as the second argument instead of a value.

2) Use the filterBy() method passing it a function that'll be called for each record.

Personally, I think the first option is easier, though I'm not very strong with regexes. If I had to guess I'd say it'd be something like:


ds.filter('Flag', /[^123]/);

KimH
1 Mar 2007, 2:04 PM
Personally, I think the first option is easier, though I'm not very strong with regexes. If I had to guess I'd say it'd be something like:


ds.filter('Flag', /[^123]/);

My guess is this:


ds.filter('Flag', /[023]/);

;-)

JeffHowden
1 Mar 2007, 2:06 PM
Indeed. Good catch KimH. Alternatively, this would probably work too (and be faster):


ds.filter('Flag', /[^1]/);

;)

KimH
1 Mar 2007, 2:09 PM
I think you're right, Jeff. I didn't thought about the "inverse" method

franklt69
1 Mar 2007, 7:07 PM
thanks it work ok ds.filter('Flag', /[^1]/);

Is there any link where I can learn about built regular expression to ext filter?

kind regards
Frank

JeffHowden
1 Mar 2007, 7:12 PM
The regular expressions used with the filter() method aren't unique to Ext; they're just regular JavaScript regular expressions.

thejoker101
2 Mar 2007, 2:30 PM
A really good reference for regEx's is regular-expressions.info

Sidenote: Are URLs in posts disabled?

KimH
4 Mar 2007, 3:48 PM
USING: 1.0 alpha 2 rev. 6

I can't get ds.filter(...) to work at all. I've tried to use:

ds.filter('id', '<some value>');

What I need is some knowledge about how to do the following:

1) Based on a JSON result filter so a grid just showing records where 'id' is starting with '<some value>'.

2) When grid is loaded with the filtered content (see 1) above) I need a "filter" input text in the header-toolbar and when the user writes something I need to filter the allready-loaded-JSON-records by this value instead of the initial filter set when loading the JSON result.

Does anyone have an example?

Jack... after reading through the source, I was wondering why default filter for a string is "^" + string and not just a string so that it is possible to write a substring of a string that is not starting at the beginning?

jack.slocum
4 Mar 2007, 8:01 PM
> ds.filter('id', '<some value>');

Is id a field in your store or are you trying to filter by the record id? filter() only supports filtering by fields, to filter by the id is pretty easy (and faster) with filterBy:


var someId = 'foo';
ds.filterBy(function(r){
return r.id == someId;
});

> I was wondering why default filter for a string is "^" + string and not just a string

It was defined to be quick and easy for the most common filter type. It's still very simple to use filterBy for other ones as you see above.

KimH
5 Mar 2007, 12:30 AM
> ds.filter('id', '<some value>');

Is id a field in your store or are you trying to filter by the record id? filter() only supports filtering by fields, to filter by the id is pretty easy (and faster) with filterBy:


var someId = 'foo';
ds.filterBy(function(r){
return r.id == someId;
});
'id' is a field in my store... I guess I should have choosen another non-Ext-variable-name for this example :lol: Do you have an example in your own toolbox that shows how to do the two things I'm trying to?


> I was wondering why default filter for a string is "^" + string and not just a string

It was defined to be quick and easy for the most common filter type. It's still very simple to use filterBy for other ones as you see above.
Okay... :wink:

jack.slocum
6 Mar 2007, 2:37 AM
I would wait til the next rev. I fixed a few bugs related to filtering.

KimH
7 Mar 2007, 12:43 AM
I would wait til the next rev. I fixed a few bugs related to filtering.

Okay... I will... :) ............... ehhh.... any idea when a new rev is posted? :oops:

EDIT: Found the answer to "...any idea when a new rev is posted?" here: http://www.yui-ext.com/forum/viewtopic.php?p=15737#15737 :oops: