Javascript 从 ExtJS 中的商店中删除过滤器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7275099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 01:35:12  来源:igfitidea点击:

Removing a filter from a store in ExtJS

javascriptextjs4

提问by joemoe

I explicitly add a filter to a Ext.data.Storeusing the store.filter(string, string)method.

Ext.data.Store使用store.filter(string, string)方法显式地向 a 添加了一个过滤器。

However, I can not figure out how to remove filters from the store. So the filters always apply even after reloading using store.load(). The only workaround I see is to restart the entire web app.

但是,我不知道如何从商店中删除过滤器。因此,即使在使用store.load(). 我看到的唯一解决方法是重新启动整个 Web 应用程序。

How do I remove a filter from an Ext.data.Store?

如何从 中删除过滤器Ext.data.Store

回答by Molecular Man

In addition to Mchi's answer, I want to say that it is possible to remove specific filter (clearFilter()removes them all).
To do that, instead of using store.filter('property_to_filter','value')method, use:

除了 Mchi 的回答,我想说可以删除特定的过滤器(clearFilter()将它们全部删除)。
为此,不要使用store.filter('property_to_filter','value')方法,而是使用:

store.filters.add('filtersId', new Ext.util.Filter({
  property: 'property_to_filter',
  value: 'value'
}));
store.load();

to remove filter use:

删除过滤器使用:

store.filters.removeAtKey('filtersId');


Update (for > 4.2.0)

更新(适用于 > 4.2.0)

In 4.2.0 methods for adding/removing specific filter were added:

在 4.2.0 中添加了添加/删除特定过滤器的方法:

store.addFilter({
    id: 'filtersId',
    property: 'property_to_filter',
    value: 'value'
});

store.removeFilter('filtersId');

For more info check out docs: Ext.data.Store.addFilter, Ext.data.Store.removeFilter

有关更多信息,请查看文档:Ext.data.Store.addFilterExt.data.Store.removeFilter

回答by Mchl

You need to clearFilter()

你需要 clearFilter()

回答by Wam31

Edit:I just found out (browsing the API for something else) that it's even easier. There's a parameter (boolean) which, if true, doesn't reload the data when using remoteFilter...

编辑:我刚刚发现(浏览 API 以获取其他内容)它更容易。有一个参数(布尔值),如果为真,则在使用 remoteFilter 时不会重新加载数据...

So here goes :

所以这里是:

store.clearFilter(true);
store.filter(...);

Source: Store API > clearFilter

来源:Store API > clearFilter

I can't believe I struggled for so long with that. In every forum I looked, I saw clearFilter which wasn't useful for remote filtering, and all I had to do was to add "true"...

我不敢相信我为此挣扎了这么久。在我查看的每个论坛中,我都看到了对远程过滤没有用的 clearFilter,我所要做的就是添加“true”...

Original Post:

原帖:

"You need to clearFilter()"

“你需要clearFilter()

IMO, this is absolutely not satisfying. When using a server backend to get the data (as many would), with remoteSortand remoteFilter+ paging to manage large result sets, it's even useless.

IMO,这绝对不能令人满意。当使用服务器后端来获取数据(很多都会),使用remoteSortremoteFilter+ 分页来管理大型结果集时,它甚至是无用的。

Calling clearFilter()actually reloads the data before reapplying the filter. So 2 ajax requests are sent each time a filter is applied. This has bothered ma for a long time.

clearFilter()在重新应用过滤器之前,调用实际上是重新加载数据。因此,每次应用过滤器时都会发送 2 个 ajax 请求。这已经困扰了妈妈很久了。

All you have to do is actually :

实际上,您所要做的就是:

store.filters.clear(); // Which is what clearFilter() does just before reloading the data...
store.filter(...);