From d2a13313427ef3744ad6ab66f867b6db9d93235a Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 2 Jun 2016 12:25:47 +0100 Subject: [PATCH] #99 improved date sorting sort dates by numeric values rather than by formatted strings --- .../src/components/document-list.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts index 70c1195d7b..956510daea 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts @@ -353,17 +353,11 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, if (this._hasEntries(node)) { node.list.entries.sort((a: MinimalNodeEntity, b: MinimalNodeEntity) => { if (a.entry.isFolder !== b.entry.isFolder) { - // Uncomment if it is needed to make files go top on desc - /* - return options.direction === 'asc' - ? (a.entry.isFolder ? -1 : 1) - : (a.entry.isFolder ? 1 : -1); - */ return a.entry.isFolder ? -1 : 1; } - let left = this.getObjectValue(a.entry, options.key).toString(); - let right = this.getObjectValue(b.entry, options.key).toString(); + let left = this._getObjectValueRaw(a.entry, options.key).toString(); + let right = this._getObjectValueRaw(b.entry, options.key).toString(); return options.direction === 'asc' ? left.localeCompare(right) @@ -373,6 +367,16 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, return node; } + private _getObjectValueRaw(target: any, key: string) { + let val = this.getObjectValue(target, key); + + if (val instanceof Date) { + val = val.valueOf(); + } + + return val; + } + private _createRootFolder(path: string): any { let parts = path.split('/'); let namePart = parts[parts.length - 1];