jQuery数据表 - 重音不敏感的字母表和搜索 [英] jQuery DataTables - Accent-Insensitive Alphabetization and Searching

查看:277
本文介绍了jQuery数据表 - 重音不敏感的字母表和搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 jQuery DataTables 时,使用过滤器可能会对重音不敏感的搜索?例如,当我把'e'字符时,我想用'e'或'é','è'搜索每个单词。

When using jQuery DataTables is it possible to do accent-insensitive searches when using the filter? For instance, when I put the 'e' character, I'd like to search every word with 'e' or 'é', 'è'.

想到的是正常化字符串并将它们放入一个单独的隐藏列,但不能解决字母顺序问题。

Something that came to mind is normalizing the strings and putting them into a separate, hidden column but that wouldn't solve the alphabetizing issue.

我尝试了以下内容:

$.fn.dataTableExt.ofnSearch = function ( data ) {
return ! data ?
    '' :
    typeof data === 'string' ?
        data
            .replace( /\n/g, ' ' )
            .replace( /á/g, 'a' )
            .replace( /é/g, 'e' )
            .replace( /í/g, 'i' )
            .replace( /ó/g, 'o' )
            .replace( /ú/g, 'u' )
            .replace( /ê/g, 'e' )
            .replace( /î/g, 'i' )
            .replace( /ô/g, 'o' )
            .replace( /è/g, 'e' )
            .replace( /ï/g, 'i' )
            .replace( /ü/g, 'u' )
            .replace( /ç/g, 'c' ) :
        data;
};

JS File Gist

推荐答案

如此关闭你的编辑你尝试了什么,除了你不必要重要的事情:定义过滤器插件的scope或sType 。这个函数从来没有被调用过,对吧?这是因为插件没有与 sType 相关联。

You are so close in your edit, what you have tried, except that you lack the must important thing : Defining the "scope" or sType of your filter plugin. The function is never called, right? This is because the plugin is not associated with a sType.

为了让你的代码工作,只需声明插件像这样:

To get your code to work simply declare the plugin like this :

$.fn.dataTableExt.ofnSearch['string'] = function ( data ) {
return ! data ?
    '' :
    typeof data === 'string' ?
..
..
}

看到这个小提琴 - > http://jsfiddle.net/Y5ycM/ 我已经把一些互联网Explorer列入Internetéxplorer,一些Opera到öpera等,尝试搜索 ex op

See this fiddle -> http://jsfiddle.net/Y5ycM/ I have turned some "Internet Explorer" columns into "Internet éxplorer", some "Opera" to "öpera" etc, Try search for ex or op.

请参阅 https://datatables.net/development/filtering ,基于类型的列过滤
部分:

See https://datatables.net/development/filtering, section "Type based column filtering " :


当您为列分配sType(或通过DataTables或类型检测插件检测到自动
)时,您将
通常用于自定义排序,但它可以也可用于
提供自定义过滤选项。 这是通过向
添加函数来完成的,该对象具有与该
目标列
的sType匹配的参数名称

When you assign the sType for a column (or have it automatically detected for you by DataTables or a type detection plug-in), you will typically be using this for custom sorting, but it can also be used to provide custom filtering options. This is done by adding functions to the the object with a parameter name which matches the sType for that target column:

我想这里有一个打字或监督的文档,它说

I guess there here is a typo or oversight in the documentation, it says

$。fn.dataTableExt.ofnSearch ,但应正确为 $。fn.dataTableExt.ofnSearch [sType] ,作为示例之后明确指出。

$.fn.dataTableExt.ofnSearch but should correctly be $.fn.dataTableExt.ofnSearch[sType], as the example just after clearly points out.

更新。 Allan Jardine证实这是1.9.4中的错误 这里

Update. Allan Jardine confirms this is a bug in 1.9.4 here :


Yup - 1.9中的错误。 4。不幸的是,1.9.4破坏了这部分代码。
它还会影响从过滤器中删除HTML标记,因为
使用相同的机制。它固定在1.10 betas。

Yup - bug in 1.9.4. 1.9.4 broke this part of the code unfortunately. It also effects the removal of HTML tags from the filter, since that was using the same mechanism. It is fixed in the 1.10 betas though.

这篇关于jQuery数据表 - 重音不敏感的字母表和搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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