-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds alphanumeric sorting reader option #218
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -967,6 +967,42 @@ | |
// force false boolean value to -1, true to 1, and tie to 0 | ||
return comparison === false ? -1 : (comparison - 0); | ||
}, | ||
alphaNumeric: function(a, b, attr, direction) { | ||
//swap if reverse | ||
if(direction === -1) { | ||
var temp = a; | ||
a = b; | ||
b = temp; | ||
} | ||
|
||
//extract display text | ||
a = $(a[attr.toString()]).text(); | ||
b = $(b[attr.toString()]).text(); | ||
|
||
var aMatch, bMatch, a1, b1, i= 0, n, | ||
|
||
regex =/(\.\d+)|(\d+(\.\d+)?)|([^\d.]+)|(\.\D+)|(\.$)/g; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment here that links to the URL this regex came from if copied. |
||
|
||
//equal | ||
if(a === b) return 0; | ||
|
||
//match | ||
aMatch = a.toLowerCase().match(regex); | ||
bMatch = b.toLowerCase().match(regex); | ||
|
||
//sort | ||
while(i< aMatch.length){ | ||
if(!bMatch[i]) return 1; | ||
a1= aMatch[i], | ||
b1= bMatch[i++]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this a little less confusing; we're doing two different things with this one line. We're first grabbing |
||
if(a1!== b1){ | ||
n= a1-b1; | ||
if(!isNaN(n)) return n; | ||
return a1>b1? 1:-1; | ||
} | ||
} | ||
return b[i]? -1:0; | ||
}, | ||
originalPlacement: function(a, b) { | ||
return a['dynatable-original-index'] - b['dynatable-original-index']; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the
toString()
on the attr names, since names are always strings anyway regardless of using integers, etc to refer to them.