如何过滤多个extjs网格列?
要过滤一个网格列,我们可以使用:
{
xtype: 'button',
text:'Search',
handler:function(){
store.clearFilter();
var searchValue = Ext.getCmp("textFieldId").getValue();
store.load().filter('GridFieldName', searchValue);
}
}
但是如何一次搜索多个字段,例如:
{
xtype: 'button',
text:'Search',
handler:function(){
store.clearFilter();
var searchValue = Ext.getCmp("textFieldId").getValue();
store.filter([
{property: "GridFieldName", value: searchValue},
{property: "GridFieldName1", value: searchValue}
]);
}
}
有什么想法吗?
编辑:
奇怪的是,在这两种情况下,只有单个搜索有效:
这有效:
store.filter([
{ property: "FirstName", value: searchValue }
]);
并且这有效:
var FirstNameFilter = new Ext.util.Filter({
property: "FirstName", value: searchValue
});
store.filter(FirstNameFilter);
但这不起作用:
store.filter([
{ property: "FirstName", value: searchValue },
{ property: "LastName", value: searchValue }
]);
或者这样做:
var filters = [
new Ext.util.Filter({
property: "FirstName", value: searchValue
}),
new Ext.util.Filter({
property: "LastName", value: searchValue
})
];
store.filter(filters);
To filter one grid column we can use:
{
xtype: 'button',
text:'Search',
handler:function(){
store.clearFilter();
var searchValue = Ext.getCmp("textFieldId").getValue();
store.load().filter('GridFieldName', searchValue);
}
}
but how to search multiple fields at once, something like:
{
xtype: 'button',
text:'Search',
handler:function(){
store.clearFilter();
var searchValue = Ext.getCmp("textFieldId").getValue();
store.filter([
{property: "GridFieldName", value: searchValue},
{property: "GridFieldName1", value: searchValue}
]);
}
}
any ideas?
EDIT:
The weird thing is that in both cases, only single search works:
This works:
store.filter([
{ property: "FirstName", value: searchValue }
]);
and this works:
var FirstNameFilter = new Ext.util.Filter({
property: "FirstName", value: searchValue
});
store.filter(FirstNameFilter);
but this does not:
store.filter([
{ property: "FirstName", value: searchValue },
{ property: "LastName", value: searchValue }
]);
or does this:
var filters = [
new Ext.util.Filter({
property: "FirstName", value: searchValue
}),
new Ext.util.Filter({
property: "LastName", value: searchValue
})
];
store.filter(filters);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(4)
尝试像这样创建 Ext.util.Filter 的实例:
或者,您可以使用自定义逻辑创建单个过滤器:
Try to create instances of
Ext.util.Filter
like this:Alternatively, you can create single filter with custom logic:
我在寻找一种使用 OR 逻辑过滤多列(实际上是所有列)的方法时发现了这篇文章。 (因此搜索子句匹配 A 列或匹配 B 列等)我最终使用自定义过滤器函数进行过滤,例如:
HTH
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:
HTH
这是我的代码,适用于 Pavel。
对于我的工作,通过
OR
逻辑搜索多列、不区分大小写、忽略位置。希望这有帮助。
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.
那应该有效。不是吗?据我了解,如果您按照所示应用过滤器,它应该按这两个标准进行过滤。
作为替代方案,您应该能够使用 setFilter 函数添加新过滤器。
如果您使用不带参数的 setFilter,它应该重新应用您之前定义的过滤器。仅当您调用clearFilter 时它们才会被删除。
That should work. Is it not? As I understand it if you apply filters as you have shown, it should filter by both criteria.
As an alternative you should be able to use the setFilter function to add new filters.
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.