Created
October 29, 2012 10:48
-
-
Save ihr/3972915 to your computer and use it in GitHub Desktop.
Second sort criterion for a backbone.paginator.clientPager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_sort: function ( models, sort, direction ) { | |
models = models.sort(function (a, b) { | |
var ac = a.get(sort), | |
bc = b.get(sort); | |
if ( !ac || !bc ) { | |
return 0; | |
} else { | |
ac = ac.toString().toLowerCase(); | |
bc = bc.toString().toLowerCase(); | |
} | |
if (direction === 'desc') { | |
if((!ac.match(/[^\d\.]/) && ac.match(/[\d\.]*/)) && | |
(!bc.match(/[^\d\.]/) && bc.match(/[\d\.]*/)) | |
){ | |
if( (ac - 0) < (bc - 0) ) { | |
return 1; | |
} | |
if( (ac - 0) > (bc - 0) ) { | |
return -1; | |
} | |
} else { | |
if (ac < bc) { | |
return 1; | |
} | |
if (ac > bc) { | |
return -1; | |
} | |
} | |
} else { | |
if((!ac.match(/[^\d\.]/) && ac.match(/[\d\.]*/)) && | |
(!bc.match(/[^\d\.]/) && bc.match(/[\d\.]*/)) | |
){ | |
if( (ac - 0) < (bc - 0) ) { | |
return -1; | |
} | |
if( (ac - 0) > (bc - 0) ) { | |
return 1; | |
} | |
} else { | |
if (ac < bc) { | |
return -1; | |
} | |
if (ac > bc) { | |
return 1; | |
} | |
} | |
} | |
/* BEGIN Code added */ | |
ac = a.get('unique_id'); | |
bc = b.get('unique_id'); | |
if (ac < bc) { | |
return -1; | |
} | |
else if (ac > bc) { | |
return 1; | |
} | |
/* END Code added */ | |
return 0; | |
}); | |
return models; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment