From 264f9fd31eeb27630de663658de259e32d912ea9 Mon Sep 17 00:00:00 2001 From: Yuksel Date: Tue, 19 Aug 2014 20:06:46 +0200 Subject: [PATCH] Create turkish-string.js Sorting in Javascript for Turkish Characters. This plug-in will replace the special turkish letters (non english characters) and replace in English. --- sorting/turkish-string.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 sorting/turkish-string.js diff --git a/sorting/turkish-string.js b/sorting/turkish-string.js new file mode 100644 index 0000000..0c1ee5f --- /dev/null +++ b/sorting/turkish-string.js @@ -0,0 +1,33 @@ +/** + * Sorting in Javascript for Turkish Characters. This plug-in will replace the special + * turkish letters (non english characters) and replace in English. + * + * + * @name Turkish + * @summary Sort Turkish characters + * @author [Yuksel Beyti](http://yukselbeyti.com) + * + * @example + * $('#example').dataTable({ + * 'aoColumns' : [ + * {'sType' : 'turkish'} + * ] + * }); + */ + +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "turkish-pre": function ( a ) { + var special_letters = { "İ": "ib", "I": "ia", "Ş": "sa", "Ğ": "ga", "Ü": "ua", "Ö": "oa", "Ç": "ca", "i": "ia", "ı": "ia", "ş": "sa", "ğ": "ga", "ü": "ua", "ö": "oa", "ç": "ca" }; + for (var val in special_letters) + a = a.split(val).join(special_letters[val]).toLowerCase(); + return a; + }, + + "turkish-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "turkish-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } +} );