3

jQuery Datatables プラグインで特殊文字を含む単語を検索しようとしています。

次のようなデータテーブルにいくつかの結果があります。

Peinado, Alma_María
Aguilar Castillo, Antonio José

「alma_maría」を検索しようとすると、最初の結果が表示されます。

Peinado, Alma_María

「alma_maria」(「í」の代わりに「i」という文字を使用していることに注意してください) を試しても、何も表示されません。

スクリーンショット 1:

検索しようとしています

スクリーンショット 2:

検索しようとしています

特殊文字を使用せずに検索したときに特殊文字の結果を表示するように Datatables を構成する方法はありますか?

私のHTML/Javascriptコード:

<table class="display table table-bordered table-striped" id="table-colegiados">
<thead>
<tr>
    <th>{$TXT.nombre}</th>
    <th>{$TXT.ciudad}</th>
    <th>{$TXT.email}</th>
    <th>{$TXT.telefono}</th>
    <th>{$TXT.dni}</th>
    <th>{$TXT.colegiado}</th>
    <th>{$TXT.asesor}</th>
    <th>{$TXT.editar}</th>
    <th>{$TXT.borrar}</th>
</tr>
</thead>
<tbody>
</tbody>
</table>

<script type="text/javascript">
    $.fn.dataTableExt.oApi.fnGetFilteredNodes = function ( oSettings )
    {
        var anRows = [];
        for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ ) {
            var nRow = oSettings.aoData[ oSettings.aiDisplay[i] ].nTr;
            anRows.push( nRow );
        }
        return anRows;
    };
    $.fn.dataTableExt.afnFiltering.push(function(oSettings, aData, iDataIndex) {
        if ( oSettings.nTable == document.getElementById( 'table-colegiados' )){
            var asesor = aData[6];
            var checked = $('#checkbox_asesores').is(':checked');
            if (checked) {
                if (asesor == '1') {
                    return true;
                }
            } else {
                return true;
            }
            return false;
        } else {
            return true;
        }
    });
    var oTable = $('#table-colegiados').dataTable({
            "aaSorting": [ [0,'asc'] ],
            'iDisplayLength': 25,
            "bProcessing": true,
            "bServerSide": false,
            "bDeferRender": true,
            "sAjaxSource": "ajax/getColegiados.php",
            "fnServerData": function ( sSource, aoData, fnCallback ) {
                $.getJSON( sSource, aoData, function (json) {
                    fnCallback(json)
                } );
            }
    });
    $('#checkbox_asesores').on("click", function(e) {
        oTable.fnDraw();
    });
</script>
4

2 に答える 2

1

答えは、アクセントの中和です。そのための準備ができているプラ​​グインがあります。

http://www.datatables.net/plug-ins/filtering/type-based/accent-neutralise

$.fn.dataTableExt.ofnSearch['string'] = 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;
};

デモ: http://jsfiddle.net/kishoresahas/416mvzws/

于 2015-11-05T16:31:05.107 に答える