Created
April 13, 2017 10:51
-
-
Save JamesHusband/aa85a69478128f5cecca820d2aa70d71 to your computer and use it in GitHub Desktop.
Sort Function
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
onSortTableSuccess(sortOrder) { | |
let sortDirection = this.state.sortDirection; | |
let chars = this.state.characters; | |
if (sortDirection == 'asc') { | |
var sortedChars = _.sortBy(chars, function (i) { | |
if (sortOrder == 'id') { | |
return i[sortOrder] | |
} else { | |
return i[sortOrder].toLowerCase() | |
} | |
}).reverse(); | |
var newSortDirection = 'desc' | |
} | |
if (sortDirection == 'desc') { | |
var sortedChars = _.sortBy(chars, function (i) { | |
if (sortOrder == 'id') { | |
return i[sortOrder] | |
} else { | |
return i[sortOrder].toLowerCase() | |
} | |
}); | |
var newSortDirection = 'asc' | |
} | |
this.setState({ | |
characters: sortedChars, | |
sortDirection: newSortDirection | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment