Skip to content

Instantly share code, notes, and snippets.

@kashmiry
Last active October 12, 2024 14:14
Show Gist options
  • Save kashmiry/ba35115ba23e8b6f034c2562dbd4042c to your computer and use it in GitHub Desktop.
Save kashmiry/ba35115ba23e8b6f034c2562dbd4042c to your computer and use it in GitHub Desktop.
DataTables Arabic Search Normalization. this extends the diacritics function provided in DataTables >= 2.0
//ready
$(function() {
//extend diacritics to support arabic characters
if(typeof DataTable !== 'undefined') {
DataTable.util.diacritics(function(str, both) {
if(typeof str !== 'string') {
return str;
}
var normalized = str
.normalize("NFD")
.replace(/[أآإ]/g, 'ا') //alef
.replace("ؤ", "و") //waw
.replace(/ة/g, "ه") //taa marbota
.replace(/[\u064B-\u065F]/g, ''); //tashkeel
return normalized.length !== str.length ?
(both === true ? str + ' ' : '') + normalized.replace(/[\u0300-\u036f]/g, "") :
normalized;
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment