Created
June 6, 2019 14:56
-
-
Save confraria/423f232f8431d02e1c8157f4ab395ba3 to your computer and use it in GitHub Desktop.
order
This file contains hidden or 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
function orderBy(property) { | |
let prop = property; | |
if (_.isArray(prop)) { | |
prop = prop.join('.'); | |
} | |
const [, sign, iterateeString] = prop.match(/^(-?)(.*)$/); | |
const order = sign === '-' ? 'desc' : 'asc'; | |
let iteratee = iterateeString; | |
if (iteratee.match(/lastMeasurement_\d+/)) { | |
const key = iteratee; | |
iteratee = (asset) => { | |
let value = asset[key]; | |
if (typeof value === 'string') { | |
value = parseInt(value, 10); | |
const orderMultiplier = order === 'asc' ? 1 : -1; | |
value = Number.isNaN(value) ? (orderMultiplier * Infinity) : value; | |
}else if (typeof value === 'object') { | |
value = value.value; | |
} | |
return value; | |
}; | |
} | |
$scope.devices = _.orderBy($scope.devices, iteratee, order); | |
$scope.$broadcast('c8yScrollLoad::refresh'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment