mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Bind tasks to table, datatable bug fixes
This commit is contained in:
@@ -17,22 +17,28 @@
|
|||||||
|
|
||||||
import { Component, OnInit } from 'angular2/core';
|
import { Component, OnInit } from 'angular2/core';
|
||||||
import { ActivitiService } from './activiti.service';
|
import { ActivitiService } from './activiti.service';
|
||||||
|
import {
|
||||||
|
ALFRESCO_DATATABLE_DIRECTIVES,
|
||||||
|
ObjectDataTableAdapter,
|
||||||
|
DataSorting,
|
||||||
|
ObjectDataRow,
|
||||||
|
ObjectDataColumn
|
||||||
|
} from 'ng2-alfresco-datatable/dist/ng2-alfresco-datatable';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tasks-demo',
|
selector: 'tasks-demo',
|
||||||
template: `
|
template: `
|
||||||
<h2>Tasks</h2>
|
<div class="container">
|
||||||
<ul>
|
<alfresco-datatable [data]="tasks"></alfresco-datatable>
|
||||||
<li *ngFor="#task of tasks">
|
</div>
|
||||||
{{task.name}}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
`,
|
`,
|
||||||
providers: [ActivitiService]
|
directives: [ALFRESCO_DATATABLE_DIRECTIVES],
|
||||||
|
providers: [ActivitiService],
|
||||||
|
styles: [':host > .container { padding: 10px; }']
|
||||||
})
|
})
|
||||||
export class TasksDemoComponent implements OnInit {
|
export class TasksDemoComponent implements OnInit {
|
||||||
|
|
||||||
tasks: any[];
|
tasks: ObjectDataTableAdapter;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private activitiService: ActivitiService) {}
|
private activitiService: ActivitiService) {}
|
||||||
@@ -43,11 +49,29 @@ export class TasksDemoComponent implements OnInit {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
this.activitiService
|
this.activitiService
|
||||||
.getTasks()
|
.getTasks()
|
||||||
.then((tasks) => {
|
.then((data) => {
|
||||||
this.tasks = tasks || []
|
let tasks = data || [];
|
||||||
console.log(this.tasks);
|
console.log(tasks);
|
||||||
|
this.loadTasks(tasks)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private loadTasks(tasks: any[]) {
|
||||||
|
tasks = tasks.map(t => {
|
||||||
|
t.name = t.name || 'Nameless task';
|
||||||
|
if (t.name.length > 50) {
|
||||||
|
t.name = t.name.substring(0, 50) + '...';
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.tasks = new ObjectDataTableAdapter(tasks, [
|
||||||
|
{ type: 'text', key: 'id', title: 'Id'},
|
||||||
|
{ type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true },
|
||||||
|
{ type: 'text', key: 'formKey', title: 'Form Key', sortable: true },
|
||||||
|
{ type: 'text', key: 'created', title: 'Created', sortable: true }
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -91,10 +91,18 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
|
|||||||
if (sorting && sorting.key) {
|
if (sorting && sorting.key) {
|
||||||
this._rows.sort((a: DataRow, b: DataRow) => {
|
this._rows.sort((a: DataRow, b: DataRow) => {
|
||||||
let left = a.getValue(sorting.key);
|
let left = a.getValue(sorting.key);
|
||||||
left = (left instanceof Date) ? left.valueOf().toString() : left.toString();
|
if (left) {
|
||||||
|
left = (left instanceof Date) ? left.valueOf().toString() : left.toString();
|
||||||
|
} else {
|
||||||
|
left = '';
|
||||||
|
}
|
||||||
|
|
||||||
let right = b.getValue(sorting.key);
|
let right = b.getValue(sorting.key);
|
||||||
right = (right instanceof Date) ? right.valueOf().toString() : right.toString();
|
if (right) {
|
||||||
|
right = (right instanceof Date) ? right.valueOf().toString() : right.toString();
|
||||||
|
} else {
|
||||||
|
right = '';
|
||||||
|
}
|
||||||
|
|
||||||
return sorting.direction === 'asc'
|
return sorting.direction === 'asc'
|
||||||
? left.localeCompare(right)
|
? left.localeCompare(right)
|
||||||
|
Reference in New Issue
Block a user