I am trying to search some words with special characters in jQuery Datatables plugin.
There are some results in datatable like this:
Peinado, Alma_María
Aguilar Castillo, Antonio José
When I try to search "alma_maría", the first result is shown:
Peinado, Alma_María
When I try "alma_maria" (note that I am using character "i" instead "í"), nothing is shown.
Screenshot 1:
Screenshot 2:
Is there any way to configure Datatables to show special characters results when I search without special characters?
My HTML/Javascript code:
<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>
The answer is Accent neutralisation. and there is ready plugin for it.
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;
};