Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to filter a extjs store with an exact match

I am using a filter for a store. The problem is that I want to return an exact match.

For example:

If I am filtering for aa-1 in a grid it will show aa-1 and aa-1*** but if I want only see everything with aa-1.

I use this to filter:

listeners: {
    itemclick: function() {
        var data = grid.getSelectionModel().selected.items[0].data;
        store.clearFilter();
        store.filter('productsCat', data.productsCat);
    }
}

What do I have to do to do an exact match?

like image 719
Rick Weller Avatar asked Nov 29 '22 02:11

Rick Weller


2 Answers

For ExtJS 4, you can simply use exactMatch and caseSensitive config options:

store.filter({
  property: fieldName,
  value: fieldValue,
  exactMatch: true,
  caseSensitive: true
})
like image 178
Farish Avatar answered Dec 04 '22 03:12

Farish


You could use a regular expression in the filter to perhaps ensure that the comparison value was the end of the phrase.

Either that, or use the filterBy() method to define a comparison function, e.g.:

store.filterBy(this, function(rec, id) {
    if(rec.get('thefieldtocompare') === "what you want to compare against") {
        return true;
    }
    else {
        return false;
    }
});
like image 43
dougajmcdonald Avatar answered Dec 04 '22 03:12

dougajmcdonald