datatables - 使用重音中和进行单个列搜索
datatables - Individual column searching with accent neutralise
我想使用重音中和插件在列中进行搜索,但它根本不起作用。它将搜索到的文本转换为无重音,但与结果不匹配。我想搜索 Kollar 并得到结果 Kollár.
示例:
- 搜索名称 Kollar 没有结果,但在 table 中是 Kollár 多次。
- 搜索名称 Kollár 没有结果...
代码如下:
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 - Accent-Insensitive Alphabetization and Searching 的副本,因为我需要它进行列搜索而不是全局搜索。我已经读过它,但它对我不起作用。
问题出在 table。它包含空(只有白色 space)单元格,在这种情况下,整个 table 没有使用重音中和功能进行过滤。所以我将白色 space 更改为
,它就像一个魅力:)。我花了很多时间才找到它:).
我想使用重音中和插件在列中进行搜索,但它根本不起作用。它将搜索到的文本转换为无重音,但与结果不匹配。我想搜索 Kollar 并得到结果 Kollár.
示例:
- 搜索名称 Kollar 没有结果,但在 table 中是 Kollár 多次。
- 搜索名称 Kollár 没有结果...
代码如下:
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 - Accent-Insensitive Alphabetization and Searching 的副本,因为我需要它进行列搜索而不是全局搜索。我已经读过它,但它对我不起作用。
问题出在 table。它包含空(只有白色 space)单元格,在这种情况下,整个 table 没有使用重音中和功能进行过滤。所以我将白色 space 更改为
,它就像一个魅力:)。我花了很多时间才找到它:).