Add an option to sort numerically.

This commit is contained in:
Tommy Goode authored and Thomas Lovén committed 2019-11-26 14:24:04 +01:00
1 parent 42315226bd
commit acf8fd1be1
3 files changed
+10 -2

No files matched your search

+6
View File
@@ -16,6 +16,12 @@ export function entity_sorter(hass, method) {
function compare(_a, _b) {
if(method.ignore_case && _a.toLowerCase) _a = _a.toLowerCase();
if(method.ignore_case && _b.toLowerCase) _b = _b.toLowerCase();
if(method.numeric) {
if (!(isNaN(parseFloat(_a)) && isNaN(parseFloat(_b)))) {
_a = isNaN(parseFloat(_a)) ? undefined : parseFloat(_a);
_b = isNaN(parseFloat(_b)) ? undefined : parseFloat(_b);
}
}
if(_a === undefined && _b === undefined) return 0;
if(_a === undefined) return lt;
if(_b === undefined) return gt;