Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 47 additions & 44 deletions sorting/persian.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* Sorting in Javascript can be difficult to get right with non-Roman
* characters - for which special consideration must be made. This plug-in
* Sorting in Javascript can be difficult to get right with non-Roman
* characters - for which special consideration must be made. This plug-in
* performs correct sorting on Persian characters.
*
* @name Persian
* @summary Sort Persian strings alphabetically
* @author [Afshin Mehrabani](http://www.afshinblog.com/)
* @author [Mohammad Javad Naderi](https://github.com/mjnaderi)
*
* @example
* $('#example').dataTable( {
Expand All @@ -15,45 +16,47 @@
* } );
*/

(function(){

var persianSort = [ 'آ', 'ا', 'ب', 'پ', 'ت', 'ث', 'ج', 'چ', 'ح', 'خ', 'د', 'ذ', 'ر', 'ز', 'ژ',
'س', 'ش', 'ص', 'ط', 'ظ', 'ع', 'غ', 'ف', 'ق', 'ک', 'گ', 'ل', 'م', 'ن', 'و', 'ه', 'ی', 'ي' ];

function GetUniCode(source) {
source = $.trim(source);
var result = '';
var i, index;
for (i = 0; i < source.length; i++) {
//Check and fix IE indexOf bug
if (!Array.indexOf) {
index = jQuery.inArray(source.charAt(i), persianSort);
}else{
index = persianSort.indexOf(source.charAt(i));
}
if (index < 0) {
index = source.charCodeAt(i);
}
if (index < 10) {
index = '0' + index;
}
result += '00' + index;
}
return 'a' + result;
}

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"pstring-pre": function ( a ) {
return GetUniCode(a.toLowerCase());
},

"pstring-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},

"pstring-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );

}());
(function () {

var persianSort = ['آ', 'ا', 'ب', 'پ', 'ت', 'ث', 'ج', 'چ', 'ح', 'خ', 'د', 'ذ', 'ر', 'ز', 'ژ',
'س', 'ش', 'ص', 'ط', 'ظ', 'ع', 'غ', 'ف', 'ق', 'ک', 'گ', 'ل', 'م', 'ن', 'و', 'ه', 'ی', 'ي'];

function GetUniCode(source) {
source = $.trim(source);
var result = '';
var i, index;
for (i = 0; i < source.length; i++) {
//Check and fix IE indexOf bug
if (!Array.indexOf)
index = jQuery.inArray(source.charAt(i), persianSort);
else
index = persianSort.indexOf(source.charAt(i));

if (index < 0)
index = source.charCodeAt(i) + 40;

if (index < 10)
index = '00' + index;
else if (index < 100)
index = '0' + index;

result += index;
}
return 'a' + result;
}

jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"pstring-pre": function (a) {
return GetUniCode($(a.toLowerCase()).text());
},

"pstring-asc": function (a, b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},

"pstring-desc": function (a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});

}());