From a60abb2e20eb494db1a485572f93c841b4cf7af0 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 2 Jun 2016 14:21:41 +0100 Subject: [PATCH] #82 datatable sorting improvements --- .../app/components/datatable/datatable-demo.component.ts | 9 +++++---- .../src/data/object-datatable-adapter.ts | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/demo-shell-ng2/app/components/datatable/datatable-demo.component.ts b/demo-shell-ng2/app/components/datatable/datatable-demo.component.ts index c239df2080..d5898500b5 100644 --- a/demo-shell-ng2/app/components/datatable/datatable-demo.component.ts +++ b/demo-shell-ng2/app/components/datatable/datatable-demo.component.ts @@ -50,14 +50,15 @@ export class DataTableDemoComponent { reset() { this.data = new ObjectDataTableAdapter( [ - {id: 1, name: 'Name 1', createdBy: this._createdBy, icon: 'material-icons://folder_open'}, - {id: 2, name: 'Name 2', createdBy: this._createdBy, icon: 'material-icons://accessibility'}, - {id: 3, name: 'Name 3', createdBy: this._createdBy, icon: 'material-icons://alarm'}, - {id: 4, name: 'Image 1', createdBy: this._createdBy, icon: this._imageUrl} + {id: 1, name: 'Name 1', createdOn: new Date(2016, 6, 2, 15, 8, 1), createdBy: this._createdBy, icon: 'material-icons://folder_open'}, + {id: 2, name: 'Name 2', createdOn: new Date(2016, 6, 2, 15, 8, 2), createdBy: this._createdBy, icon: 'material-icons://accessibility'}, + {id: 3, name: 'Name 3', createdOn: new Date(2016, 6, 2, 15, 8, 3), createdBy: this._createdBy, icon: 'material-icons://alarm'}, + {id: 4, name: 'Image 1', createdOn: new Date(2016, 6, 2, 15, 8, 4), createdBy: this._createdBy, icon: this._imageUrl} ], [ {type: 'image', key: 'icon', title: '', srTitle: 'Thumbnail'}, {type: 'text', key: 'id', title: 'Id', sortable: true}, + {type: 'text', key: 'createdOn', title: 'Created On', sortable: true}, {type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true}, {type: 'text', key: 'createdBy.name', title: 'Created By', sortable: true} ] diff --git a/ng2-components/ng2-alfresco-datatable/src/data/object-datatable-adapter.ts b/ng2-components/ng2-alfresco-datatable/src/data/object-datatable-adapter.ts index f8cde061f2..8e6a65e0a3 100644 --- a/ng2-components/ng2-alfresco-datatable/src/data/object-datatable-adapter.ts +++ b/ng2-components/ng2-alfresco-datatable/src/data/object-datatable-adapter.ts @@ -80,8 +80,11 @@ export class ObjectDataTableAdapter implements DataTableAdapter { if (sorting && sorting.key) { this._rows.sort((a: DataRow, b: DataRow) => { - let left = a.getValue(sorting.key).toString(); - let right = b.getValue(sorting.key).toString(); + let left = a.getValue(sorting.key); + left = (left instanceof Date) ? left.valueOf().toString() : left.toString(); + + let right = b.getValue(sorting.key); + right = (right instanceof Date) ? right.valueOf().toString() : right.toString(); return sorting.direction === 'asc' ? left.localeCompare(right)