summaryrefslogtreecommitdiff
path: root/html/assets/js/dataTables/search-neutralise.js
blob: d5c5ba0affe580ebaada0951c4512b4948718291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function NeutralizeAccent(data){
    return !data
        ? ''
        : typeof data === 'string'
        ? data
        .replace( /\n/g, ' ' )
        .replace( /\u0386/g, "\u0391" ) // 'Ά':'Α'
        .replace( /\u0388/g, "\u0395" ) // 'Έ':'Ε'
        .replace( /\u0389/g, "\u0397" ) // 'Ή':'Η'
        .replace( /\u038A/g, "\u0399" ) // 'Ί':'Ι'
        .replace( /\u038C/g, "\u039F" ) // 'Ό':'Ο'
        .replace( /\u038E/g, "\u03A5" ) // 'Ύ':'Υ'
        .replace( /\u038F/g, "\u03A9" ) // 'Ώ':'Ω'
        .replace( /\u0390/g, "\u03CA" ) // 'ΐ':'ϊ'
        .replace( /\u03AC/g, "\u03B1" ) // 'ά':'α'
        .replace( /\u03AD/g, "\u03B5" ) // 'έ':'ε'
        .replace( /\u03AE/g, "\u03B7" ) // 'ή':'η'
        .replace( /\u03AF/g, "\u03B9" ) // 'ί':'ι'
        .replace( /\u03B0/g, "\u03CB" ) // 'ΰ':'ϋ'
        .replace( /\u03CC/g, "\u03BF" ) // 'ό':'ο'
        .replace( /\u03CD/g, "\u03C5" ) // 'ύ':'υ'
        .replace( /\u03CE/g, "\u03C9" ) // 'ώ':'ω'
        : data
}

function custom_search(table_id){
    var filterVal = '';
    $('#'+table_id+'_filter input').unbind(); //Unbind default behaviour
    $('#'+table_id+'_filter input').on('keyup change', function(){
        var val = NeutralizeAccent(this.value);
        if(val !== filterVal){
            filterVal = val;
            $('#'+table_id+'').DataTable().search(val).draw(); 
        }
    });
}

jQuery.fn.dataTable.ext.type.search['locale-compare'] = function (data) {
    return NeutralizeAccent(data);
}