Permalink
Browse files

Merge pull request #19 from alexandernst/master

Incorrect sorting
  • Loading branch information...
2 parents e2c4c30 + ce39952 commit c86747b6c212a848615f3f61bc065f3a5994d299 @addyosmani addyosmani committed May 9, 2012
Showing with 97 additions and 25 deletions.
  1. +48 −12 dist/backbone.paginator.js
  2. +2 −2 dist/backbone.paginator.min.js
  3. +47 −11 lib/backbone.paginator.js
View
@@ -1,4 +1,4 @@
-/*! backbone.paginator - v0.1.54 - 5/7/2012
+/*! backbone.paginator - v0.1.54 - 5/9/2012
* http://github.com/addyosmani/backbone.paginator
* Copyright (c) 2012 Addy Osmani; Licensed MIT */
@@ -102,23 +102,59 @@ Backbone.Paginator = (function ( Backbone, _, $ ) {
models = models.sort(function (a, b) {
var ac = a.get(sort),
bc = b.get(sort);
-
+
+ if ( !ac || !bc ) {
+ return 0;
+ } else {
+ /* Make sure that both ac and bc are lowercase strings.
+ * .toString() first so we don't have to worry if ac or bc
+ * have other String-only methods.
+ */
+ ac = ac.toString().toLowerCase();
+ bc = bc.toString().toLowerCase();
+ }
+
if (direction === 'desc') {
- if (ac > bc) {
- return -1;
- }
- if (ac < bc) {
- return 1;
+ 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 < bc) {
- return -1;
- }
- if (ac > bc) {
- return 1;
+ 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;
+ }
}
+
}
return 0;

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -99,23 +99,59 @@ Backbone.Paginator = (function ( Backbone, _, $ ) {
models = models.sort(function (a, b) {
var ac = a.get(sort),
bc = b.get(sort);
-
+
+ if ( !ac || !bc ) {
+ return 0;
+ } else {
+ /* Make sure that both ac and bc are lowercase strings.
+ * .toString() first so we don't have to worry if ac or bc
+ * have other String-only methods.
+ */
+ ac = ac.toString().toLowerCase();
+ bc = bc.toString().toLowerCase();
+ }
+
if (direction === 'desc') {
- if (ac > bc) {
- return -1;
- }
- if (ac < bc) {
- return 1;
+ 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 < bc) {
- return -1;
- }
- if (ac > bc) {
- return 1;
+ 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;
+ }
}
+
}
return 0;

0 comments on commit c86747b

Please sign in to comment.