PDA

View Full Version : Filtering a store using contains clause



webfriend13
7 Oct 2012, 10:03 PM
Hi All,

I want to filter my store based on 'UserID' field of the model. I am using following code and it is working fine if the userId comes as 'myDomain\\XYZUser'. Filter does not work if user belongs to another domain like 'newDomain\XYZUser'


MyStore.filter('UserID', 'myDomain\\UserName');


Problem: In my seach I want to ignore the domain and want to include the record if the value CONTAINS passed userName.

vietits
7 Oct 2012, 11:15 PM
You can use <store>.filterBy(). See more information at http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-method-filterBy.

webfriend13
8 Oct 2012, 12:06 AM
Hi Vietits,

I just used it & came here to update the answer and saw your post. Many thanks for replying.




myStore.filterBy(function (rec, id) {
return (rec.get("UserID") == "xDomain\\" + uid || rec.get("UserID") == "yDomain\\" + uid);
});


MyQuestion: Can we make it generic?? Just validating user name without taking into account the domain of the user. With the current code if the domain changes, i have to modify the code again.

webfriend13
8 Oct 2012, 3:13 AM
Following code will perform contains search for user id


mYStore.filterBy(function (rec, id) {
var userId = rec.get("UserID") || " ";
return (userId.indexOf(uid) != -1);
});