mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
#99 improved date sorting
sort dates by numeric values rather than by formatted strings
This commit is contained in:
@@ -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];
|
||||
|
Reference in New Issue
Block a user