From e6a6196c39a0837ac8f50a2c1a950c8e6e27f0f0 Mon Sep 17 00:00:00 2001 From: Giorgio Fellipe Date: Mon, 20 Feb 2017 11:15:21 -0300 Subject: [PATCH] Check if the comparison is between boolean or Date This should fix #99 --- src/pipes/OrderBy/OrderBy.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pipes/OrderBy/OrderBy.ts b/src/pipes/OrderBy/OrderBy.ts index 1fa52371..e33367cb 100644 --- a/src/pipes/OrderBy/OrderBy.ts +++ b/src/pipes/OrderBy/OrderBy.ts @@ -16,13 +16,17 @@ export class OrderByPipe implements PipeTransform { if(a === null || typeof a === 'undefined') a = 0; if(b === null || typeof b === 'undefined') b = 0; - - if((isNaN(parseFloat(a)) || !isFinite(a)) || (isNaN(parseFloat(b)) || !isFinite(b))){ + + if ((typeof a == 'boolean' || typeof b == 'boolean') || (a instanceof Date || b instanceof Date)) { + if (a < b) return -1; + if (a > b) return 1; + } + else if((isNaN(parseFloat(a)) || !isFinite(a)) || (isNaN(parseFloat(b)) || !isFinite(b))){ //Isn't a number so lowercase the string to properly compare if(a.toLowerCase() < b.toLowerCase()) return -1; if(a.toLowerCase() > b.toLowerCase()) return 1; } - else{ + else { //Parse strings as numbers to compare properly if(parseFloat(a) < parseFloat(b)) return -1; if(parseFloat(a) > parseFloat(b)) return 1; @@ -115,4 +119,4 @@ export class OrderByPipe implements PipeTransform { export let ORDERBY_PROVIDERS = [ OrderByPipe -]; \ No newline at end of file +];