正则表达式不使用Datatables插件中的重音字符

时间:2017-04-02 16:21:14

标签: jquery regex search datatables

我正在尝试使用正则表达式实现数据表搜索。

如果我搜索“lu..a”(返回Lucia,Luzia,LUZIA等),它可以正常工作,但如果我尝试“concei..o”(寻找Conceição,conceicao等)则不行。

问题在于数据库中带有重音的字符“ç”或“ã”(pt_BR)。

我已经尝试过accent-neutralize插件,但它会产生相反的效果(https://datatables.net/plug-ins/filtering/type-based/accent-neutralise

在表初始化中有很多选项我在这里省略(按钮,翻译等),但一个重要的细节是这个平板电脑正在从服务器端检索数据。

以下是搜索代码:

来源:https://datatables.net/examples/api/multi_filter.html

// Setup - add a text input to each footer cell
$('.exportTable tfoot th.select-filter').each(function() {
  var title = $(this).text();
  $(this).html('<div class="form-group form-float" style="width: 100%">' +
    '<div class="form-line">' +
    '<input class="form-control" placeholder="' + title + '" title="Filtrar ' + title + '" type="text" style="width: 100%">' +
    '</div>' +
    '</div>');
});

table = $('.exportTable').DataTable();

// Apply the search
table.columns().every(function() {
  var that = this;
  $('input', this.footer()).on('keyup change', function() {
    if (that.search() !== this.value) {
      that
        .search(this.value, true, false, true)
        .draw();
    }
  });
});

1 个答案:

答案 0 :(得分:2)

您只需要一个更完整的diacritics表格。我没有声称提到的表是完整的,但我知道的最好。包括脚本和

jQuery.fn.DataTable.ext.type.search.string = function (s) {
    return removeDiacritics(s)
};
使用Conceição进行

演示 - &gt;的 https://jsfiddle.net/s2yo99de/

更新:以上解决方案现已作为官方DataTables插件的一部分提供

排序 - &gt;的 https://datatables.net/plug-ins/sorting/diacritics-sort
过滤 - &gt;的 https://datatables.net/plug-ins/filtering/type-based/diacritics-neutralise