Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
8 lars 1
/**
2
 * Sorting in Javascript can be difficult to get right with non-Roman
3
 * characters - for which special consideration must be made. This plug-in
4
 * performs correct sorting on Persian characters.
5
 *
6
 *  @name Persian
7
 *  @summary Sort Persian strings alphabetically
8
 *  @author [Afshin Mehrabani](http://www.afshinblog.com/)
9
 *
10
 *  @example
11
 *    $('#example').dataTable( {
12
 *       columnDefs: [
13
 *         { type: 'pstring', targets: 0 }
14
 *       ]
15
 *    } );
16
 */
17
 
18
(function(){
19
 
20
var persianSort = [ 'آ', 'ا', 'ب', 'پ', 'ت', 'ث', 'ج', 'چ', 'ح', 'خ', 'د', 'ذ', 'ر', 'ز', 'ژ',
21
					'س', 'ش', 'ص', 'ط', 'ظ', 'ع', 'غ', 'ف', 'ق', 'ک', 'گ', 'ل', 'م', 'ن', 'و', 'ه', 'ی', 'ي' ];
22
 
23
function GetUniCode(source) {
24
	source = $.trim(source);
25
	var result = '';
26
	var i, index;
27
	for (i = 0; i < source.length; i++) {
28
		//Check and fix IE indexOf bug
29
		if (!Array.indexOf) {
30
			index = jQuery.inArray(source.charAt(i), persianSort);
31
		}else{
32
			index = persianSort.indexOf(source.charAt(i));
33
		}
34
		if (index < 0) {
35
			index = source.charCodeAt(i);
36
		}
37
		if (index < 10) {
38
			index = '0' + index;
39
		}
40
		result += '00' + index;
41
	}
42
	return 'a' + result;
43
}
44
 
45
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
46
	"pstring-pre": function ( a ) {
47
		return GetUniCode(a.toLowerCase());
48
	},
49
 
50
	"pstring-asc": function ( a, b ) {
51
		return ((a < b) ? -1 : ((a > b) ? 1 : 0));
52
	},
53
 
54
	"pstring-desc": function ( a, b ) {
55
		return ((a < b) ? 1 : ((a > b) ? -1 : 0));
56
	}
57
} );
58
 
59
}());