1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-02-20 18:54:15 +01:00

New: Use localeCompare to do string comparison, allowing much better internationlisation support for sorting strings in DataTables

This commit is contained in:
Allan Jardine 2011-12-07 11:07:02 +00:00
parent 66a2e3d659
commit f535031e41
3 changed files with 15 additions and 16 deletions

View File

@ -10199,17 +10199,17 @@
"string-pre": function ( a )
{
if ( typeof a != 'string' ) { a = ''; }
return a.toLowerCase();
return a.toLocaleLowerCase();
},
"string-asc": function ( x, y )
{
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
return x.localeCompare(y);
},
"string-desc": function ( x, y )
{
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
return y.localeCompare(x);
},
@ -10218,17 +10218,17 @@
*/
"html-pre": function ( a )
{
return a.replace( /<.*?>/g, "" ).toLowerCase();
return a.replace( /<.*?>/g, "" ).toLocaleLowerCase();
},
"html-asc": function ( x, y )
{
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
return x.localeCompare(y);
},
"html-desc": function ( x, y )
{
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
return y.localeCompare(x);
},

View File

@ -6,17 +6,17 @@ $.extend( DataTable.ext.oSort, {
"string-pre": function ( a )
{
if ( typeof a != 'string' ) { a = ''; }
return a.toLowerCase();
return a.toLocaleLowerCase();
},
"string-asc": function ( x, y )
{
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
return x.localeCompare(y);
},
"string-desc": function ( x, y )
{
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
return y.localeCompare(x);
},
@ -25,17 +25,17 @@ $.extend( DataTable.ext.oSort, {
*/
"html-pre": function ( a )
{
return a.replace( /<.*?>/g, "" ).toLowerCase();
return a.replace( /<.*?>/g, "" ).toLocaleLowerCase();
},
"html-asc": function ( x, y )
{
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
return x.localeCompare(y);
},
"html-desc": function ( x, y )
{
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
return y.localeCompare(x);
},

View File

@ -38,11 +38,10 @@
//}
oTable.fnSort( [[ 1, 'asc' ]] );
oTable.fnFilter(1);
oTable.fnSort( [[ 1, 'asc' ]] );
//oTable.fnSort( [[ 2, 'asc' ]] );
//oTable.fnSort( [[ 1, 'asc' ]] );
//oTable.fnSort( [[ 2, 'asc' ]] );
oTable.fnSort( [[ 2, 'asc' ]] );
oTable.fnSort( [[ 1, 'asc' ]] );
oTable.fnSort( [[ 2, 'asc' ]] );
var iEnd = new Date().getTime();
document.getElementById('output').innerHTML = "Test took "+(iEnd-iStart)+" mS";