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

Update media/src/core/core.sort.js

Simplify and improve performance
- Only check once for the presence of any sorting class instead of checking for the 3 individual classes
- Use lastIndexOf(str, 0) instead of indexOf

http://jsperf.com/rep-reg-string/4
This commit is contained in:
Tim Tucker 2012-09-03 16:29:28 -03:00
parent 59dc2aed9c
commit 24fc23f63d

View File

@ -1,5 +1,4 @@
/**
* Change the order of the table
* @param {object} oSettings dataTables settings object
@ -411,30 +410,15 @@ function _fnSortingClasses( oSettings )
}
else if ( nTds.length >= iColumns )
{
var reClass = new RegExp(sClass + "[123]", "g");
for ( i=0 ; i<iColumns ; i++ )
{
if ( nTds[i].className.indexOf(sClass+"1") != -1 )
if ( nTds[i].className.lastIndexOf(sClass, 0) != -1 )
{
for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
{
nTds[(iColumns*j)+i].className =
$.trim( nTds[(iColumns*j)+i].className.replace( sClass+"1", "" ) );
}
}
else if ( nTds[i].className.indexOf(sClass+"2") != -1 )
{
for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
{
nTds[(iColumns*j)+i].className =
$.trim( nTds[(iColumns*j)+i].className.replace( sClass+"2", "" ) );
}
}
else if ( nTds[i].className.indexOf(sClass+"3") != -1 )
{
for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ )
{
nTds[(iColumns*j)+i].className =
$.trim( nTds[(iColumns*j)+i].className.replace( " "+sClass+"3", "" ) );
nTds[(iColumns*j)+i].className =
$.trim( nTds[(iColumns*j)+i].className.replace( reClass, "" ) );
}
}
}