datatables - 使用重音中和的单个列搜索 [英] datatables - Individual column searching with accent neutralise

查看:103
本文介绍了datatables - 使用重音中和的单个列搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在带有重音中和插件的列中进行搜索,但它根本不起作用。它将搜索到的文本转换为无重复,但它与结果不匹配。我想搜索 Kollar ,结果Kollár

I want to search in columns with accent neutralise plugin, but it didnt work at all. It transform searched text to accentless, but it doesnt match the results. I want to search Kollar and with result Kollár.

示例:


  1. 搜索名称 Kollar 但没有结果,但在表格中Kollár多次。

  2. 搜索名称Kollár但没有结果......

  1. Searched name Kollar with no result, but in table is Kollár multiple times.
  2. Searched name Kollár with no result...

以下是代码:

var table = jQuery('#example').DataTable();
jQuery.fn.DataTable.ext.type.search.string = function ( data ) {
    return ! data ?
        '' :
       typeof data === 'string' ?
              data
                        .replace( /έ/g, 'ε')
                        .replace( /ύ/g, 'υ')
                        .replace( /ό/g, 'ο')
                        .replace( /ώ/g, 'ω')
                        .replace( /ά/g, 'α')
                        .replace( /ί/g, 'ι')
                        .replace( /ή/g, 'η')
                        .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, 'a' )
                        .replace( /õ/g, 'o' )
                        .replace( /ç/g, 'c' )
                        .replace( /ì/g, 'i' ) :
                    data;
        };

    table.columns().eq( 0 ).each( function ( colIdx ) {
            jQuery( 'input', table.column( colIdx ).header() ).on( 'keyup change', function () {
                table
                    .column( colIdx )
                    .search(
                        jQuery.fn.DataTable.ext.type.search.string( this.value )
                    )
                    .draw();
            });
        });

编辑:它不是 jQuery DataTables - 重音不敏感的字母表和搜索因为我需要它来进行列搜索而不是全局搜索。我已经阅读过了它并不适用于我。

Its not a duplicate of jQuery DataTables - Accent-Insensitive Alphabetization and Searching becouse I need it to column searching not for global search. Ive already read it and it doesnt works for me.

推荐答案

问题出现在表格中。它包含空(仅空白空间)单元格,在这种情况下,整个表格没有过滤带重音中和功能。所以我将空格更改为& nbsp; ,它就像魅力:)。我花了很多时间找到它:)。

The problem was in the table. It contains empty (only white space) cells and in this case whole table didnt filter with accent neutralise function. So I change white space to   and it works like a charm :). It cost me lot of time to find it out :).

这篇关于datatables - 使用重音中和的单个列搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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