How to filter multiple extjs grid columns?

徘徊边缘 提交于 2019-12-04 04:08:48

Try to create instances of Ext.util.Filter like this:

var filters = [
 new Ext.util.Filter({
  property: "GridFieldName", value: searchValue
 }),
 new Ext.util.Filter({
  property: "GridFieldName1", value: searchValue
 })
];
store.filter(filters);

Alternatively, you can create single filter with custom logic:

var filters = [
     new Ext.util.Filter({
      filterFn: function(item){
         return item.get('GridFieldName') == searchValue && item.get('GridFieldName1') == searchValue;
      }
     })
];
store.filter(filters);

I found this post while searching for a way to filter on multiple columns (actually ALL columns) with OR logic. (so the search-clause matches column A OR matches column B etc.) I ended up filtering with a custom filterfunction like:

...
var regex = RegExp('Insert searchclause here', 'i');
store.filter(new Ext.util.Filter({
    filterFn: function (object) {
        var match = false;
        Ext.Object.each(object.data, function (property, value) {
            match = match || regex.test(String(value));
        });
        return match;
      }
}));

HTH

    store.clearFilter();
    var searchValue = Ext.getCmp("textFieldId").getValue();
    if (!!searchValue) {
        var filters = [
             new Ext.util.Filter({
                 filterFn: function (item) {
                     return item.get('FirstName').toLowerCase().indexOf(searchValue.toLowerCase()) > -1                                 
                         || item.get('LastName').toLowerCase().indexOf(searchValue.toLowerCase()) > -1;
                 }
             })
        ];
        store.filter(filters);
    }

This is my code which apply from Pavel.
For my work which search Multi-column, Non-case sensitive, Ignore position by OR logic.

Hope this help.

That should work. Is it not? As I understand it if you apply filters as you have shown, it should filter by both criteria.

store.filter([
   {property: "GridFieldName", value: searchValue},
   {property: "GridFieldName1", value: searchValue}
]);

As an alternative you should be able to use the setFilter function to add new filters.

store.setFilter("GridFieldName",  searchValue)
store.setFilter("GridFieldName1",  searchValue)

If you use setFilter with no arguments it should just reapply the filters you have previously defined. They are only removed if you call clearFilter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!