jqGrid自定义过滤,内置过滤工具栏 [英] jqGrid custom filtering with build in filtering toolbar

查看:114
本文介绍了jqGrid自定义过滤,内置过滤工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新的jqGrid版本,我想知道是否可以使用自定义规则进行本地过滤(请参阅下面的示例)。首先,可以通过应用



jQuery(#grid)来启用过滤器工具栏.jqGrid('filterToolbar',options) ;



过去我手动实现了这个(我目前使用的版本不支持本地过滤,所以我根据我添加了这个功能现在,在更新到最新版本之后,我问自己jqGrid是否默认提供此功能(不是本地过滤,它可以,但自定义过滤规则),因为功能在过去几个月中大幅增加。我阅读了文档并搜索了互联网,但没有找到合适的例子。



这是我想要实现的一个例子。



有一列名字,其中包含所显示人员的名字。

  Stefan 
Stephan
Stephano
Stelios
Philip
Phillip
Philipp
Ivan
Iwan
...

现在,用户在列名字的过滤栏中输入 Ste ,并且使用默认过滤算法的结果应该是:)

  Stefan 
Stephan
Stephano
Stelios

到目前为止一切顺利。但是,如果我想要显示与其相似的名称呢?我希望用户输入 Ste * an * 仅显示

  Stefan 
Stephan
Stephano

所以你看, * 代表任何字符的通配符零次或多次。此外,我希望用户能够输入 Ste?an * ,从而产生

  Stefan 

其中表示任何性格恰好一次。最后一个要求是使过滤更容忍并且不仅匹配孔线(开始和结束,相当于正则表达式),而是匹配列值,如果它包含输入的文本,即 e * o 匹配

  Stephano 
Stelios

如果你能给我一个 * 通配符的提示,其他问题应该是正确的。



提前致谢



解决方案

在我的旧答案覆盖一些内部jqGrid使用的搜索方法


I'm using the latest jqGrid version and I'm wondering if it's possible to do local filtering with custom rules (see example below). First of all, the filter toolbar can be switched on by applying

jQuery("#grid").jqGrid('filterToolbar', options);

In the past I implemented this manually (the version I currently use does not support local filtering, so I added this feature according the my needs) and now, after an update to the latest version, I asked myself if jqGrid offers this functionalty by default (Not the local filtering, which it does, but the custom filtering rules) as the functionality impressively increased over the last months. I read the documentation and searched the internet, but did not find a suitable example.

Here is an example of what I want to achieve.

There's a column First Name which hold the first name of the persons displayed.

Stefan
Stephan
Stephano
Stelios
Philip
Phillip
Philipp
Ivan
Iwan
...

Now the user enters Ste in the filtering bar for column First Name and the result with the default filtering algorithm should be :)

Stefan
Stephan
Stephano
Stelios

So far so good. But what if I want to display names which are ortographically similar? I want the user to enter Ste*an* to only display

Stefan
Stephan
Stephano

So you see, * stands for a wildcard for any character zero or more times. Additionally I want the user to be able to enter Ste?an* resulting in

Stefan

where ? means any character exactly once. One last requirement is to make the filtering more tolerant and matching not only the hole line (starting and ending, equivalent to regular expressions), but matching the column value if it contains the text entered, i.e. e*o matching

Stephano
Stelios

If you could give me a hint with the * wildcard, the other problems should right themselves.

Thanks in advance

Kai

解决方案

In my old answers here and here I described how one can implement custom filtering.

If you in the demo type for example "ev" in the filter for 'Client' column you will see the following:

You can easy modify the demo to make for example 'Stephan' and 'Stefan' equivalent.

I personally use mostly defaultSearch: 'cn' in the filterToolbar options. Together with the usage of ignoreCase: true it follow to very good user experience. In my personal opinion such filtering is good enough. More advanced user can use Advanced Searching to create the filter like 'begin with' "Ste" AND 'contains' "an" instead of Ste*an*.

Nevertheless you can use idea from my old demo to overwrite some internal searching methods used by jqGrid.

这篇关于jqGrid自定义过滤,内置过滤工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆