I'm using an Angular UI Grid in my app. I set enableFiltering
to true
in the options which made some filter boxes show up above my columns. This is great, but the filters don't work exactly as desired.
我在我的应用程序中使用Angular UI Grid。我在选项中将enableFiltering设置为true,这使得一些过滤器框显示在我的列上方。这很好,但过滤器不能完全按照要求工作。
If a cell contains the text "I like pizza" and I type "I like", that cell's row is shown as a match. I would also think that if I type "pizza", the "I like pizza" cell/row should show up, but that's not the case.
如果单元格包含文本“我喜欢披萨”并且我键入“我喜欢”,则该单元格的行显示为匹配。我也认为如果我输入“披萨”,“我喜欢披萨”的单元格/行应该出现,但事实并非如此。
How can I get the filters to allow searching anywhere in the text, not just from the beginning?
如何让过滤器允许在文本中的任何位置进行搜索,而不仅仅是从头开始?
2 个解决方案
#1
5
You can use filter: {condition: uiGridConstants.filter.CONTAINS}
in the column definition to allow that column to search anywhere in the text.
您可以在列定义中使用filter:{condition:uiGridConstants.filter.CONTAINS}以允许该列搜索文本中的任何位置。
Here's a sample column definition with this in place:
这是一个示例列定义,其中包含:
columnDefs: [
// default
{ field: 'name',
filter: {condition: uiGridConstants.filter.CONTAINS} },
...
#2
1
You can pass a custom filter object that takes a condition
property, which can be a function that takes searchTerm
and cellValue
. Will display if the function returns true
. Plunkr
您可以传递一个带有条件属性的自定义过滤器对象,该属性可以是一个带有searchTerm和cellValue的函数。如果函数返回true,将显示。 Plunkr
{ field: 'name', filter: {
condition: function(searchTerm, cellValue) {
return cellValue.indexOf(searchTerm) > -1
}
}}
#1
5
You can use filter: {condition: uiGridConstants.filter.CONTAINS}
in the column definition to allow that column to search anywhere in the text.
您可以在列定义中使用filter:{condition:uiGridConstants.filter.CONTAINS}以允许该列搜索文本中的任何位置。
Here's a sample column definition with this in place:
这是一个示例列定义,其中包含:
columnDefs: [
// default
{ field: 'name',
filter: {condition: uiGridConstants.filter.CONTAINS} },
...
#2
1
You can pass a custom filter object that takes a condition
property, which can be a function that takes searchTerm
and cellValue
. Will display if the function returns true
. Plunkr
您可以传递一个带有条件属性的自定义过滤器对象,该属性可以是一个带有searchTerm和cellValue的函数。如果函数返回true,将显示。 Plunkr
{ field: 'name', filter: {
condition: function(searchTerm, cellValue) {
return cellValue.indexOf(searchTerm) > -1
}
}}