javascript 使用 filterBy() 应用过滤器时从 ExtJs 存储中清除过滤器的最快方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19767817/
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-10-27 16:43:56  来源:igfitidea点击:

Fastest way to clear filter from ExtJs store when filter is applied by using filterBy()

javascriptextjsextjs4.1extjs-stores

提问by SharpCoder

I am using ExtJS 4.1. I am using stores's clearFilter()to remove the filter from the store. I am applying filter to the store by using filterBymethod. I am filtering all the records where name is not Ronaldo.

我正在使用 ExtJS 4.1。我正在使用商店clearFilter()从商店中删除过滤器。我正在使用filterBy方法将过滤器应用于商店。我正在过滤姓名不是罗纳尔多的所有记录。

After clearing the filter, I load a view which contains a grid (attached to store). But when I load the grid, I can still see that filter is not cleared. The store is local store. I have not applied any grouping on the store. Store is only using one model.

清除过滤器后,我加载一个包含网格(附加到存储)的视图。但是当我加载网格时,我仍然可以看到过滤器没有被清除。这家商店是当地的商店。我没有在商店应用任何分组。商店只使用一种型号。

myStore.filterBy(function (record) {
    if (record.get('Name') != 'Ronaldo') {
        return true;
    }
});

While all this is working fine, but when I clear the filter by using clearFilter(), it is taking some time. Is there any faster\better\correct way to clear the filter on a store when filter is applied by using filterBy()?

虽然所有这些工作正常,但是当我使用 清除过滤器时clearFilter(),需要一些时间。当使用过滤器应用过滤器时,是否有任何更快\更好\正确的方法来清除商店上的过滤器filterBy()

回答by matt

When you use clearFilter()it doesn't make a difference if you used filterBy()or filter()or the filters were configured on the store.

当您使用clearFilter()它时,如果您使用filterBy()filter()或过滤器是在商店中配置的,则没有任何区别。

Here's what happens when you clear the filters:

清除过滤器时会发生以下情况:

  1. the collection of filters on the store is cleared
  2. the filtered data is replaced with the original (unfiltered) data which was stored in a snapshot
  3. the "datachanged" and "refresh" events are fired on the store
  1. 商店上的过滤器集合已清除
  2. 过滤后的数据将替换为存储在快照中的原始(未过滤)数据
  3. "datachanged" 和 "refresh" 事件在 store 上触发

Note that you can suppress the events to be fired by using clearFilter(true)which may be useful if you want to filter the store again after clearing the existing filters.

请注意,clearFilter(true)如果您想在清除现有过滤器后再次过滤存储,您可以使用which来抑制要触发的事件。

If clearing the store's filters performs slowly then it is probably related to the layout process (on your grid or whatever you're using the store with) which is triggered by step 3.

如果清除商店的过滤器执行缓慢,那么它可能与第 3 步触发的布局过程(在您的网格或您使用商店的任何地方)有关。

Also refer to the docsor the source code.

另请参阅文档源代码

回答by neodimasz

heres my best answer, to clear the filterBy function :

继承人我最好的答案,清除 filterBy 功能:

 myStore.filterBy(function (record) {
                return true;
        });

i just did it, hope its helping

我刚刚做到了,希望它有帮助

回答by Shahbaz

Just call a:

只需调用一个:

myStore.reload();

whenever you want to remove a filter set using filterBy.

每当您想使用 filterBy 删除过滤器集时。