selected row highlight (#1448)

* showing selected row

Support for showing selected row for the components:

- DataTable
- DocumentList
- Activiti TaskList
- Activiti ProcessList

fixes #170

* unit test fixes
This commit is contained in:
Denys Vuika 2017-01-13 12:45:37 +00:00 committed by Mario Romano
parent 01ab948666
commit 0fa87bb17d
8 changed files with 37 additions and 15 deletions

View File

@ -191,8 +191,13 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
*/
selectFirst() {
if (!this.isListEmpty()) {
this.currentInstanceId = this.data.getRows()[0].getValue('id');
let row = this.data.getRows()[0];
this.data.selectedRow = row;
this.currentInstanceId = row.getValue('id');
} else {
if (this.data) {
this.data.selectedRow = null;
}
this.currentInstanceId = null;
}
}

View File

@ -189,20 +189,20 @@ export class ActivitiTaskList implements OnInit, OnChanges {
*/
selectTask(taskIdToSelect: string) {
if (!this.isListEmpty()) {
let dataRow = this.data.getRows().find(row => row.getValue('id') === taskIdToSelect);
this.currentInstanceId = dataRow ? dataRow.getValue('id') : this.selectFirst();
let rows = this.data.getRows();
if (rows.length > 0) {
let dataRow = rows.find(row => row.getValue('id') === taskIdToSelect) || rows[0];
this.data.selectedRow = dataRow;
this.currentInstanceId = dataRow.getValue('id');
}
} else {
if (this.data) {
this.data.selectedRow = null;
}
this.currentInstanceId = null;
}
}
/**
* Select the first instance of a list if present
*/
selectFirst() {
return this.data.getRows()[0].getValue('id');
}
/**
* Return the current id
* @returns {string}

View File

@ -114,3 +114,8 @@
border-collapse: unset;
border-spacing: 0;
}
.alfresco-datatable__row--selected {
color: rgb(68,138,255);
}

View File

@ -31,7 +31,8 @@
</thead>
<tbody>
<tr *ngFor="let row of data.getRows(); let idx = index" tabindex="0">
<tr *ngFor="let row of data.getRows(); let idx = index" tabindex="0"
[class.alfresco-datatable__row--selected]="selectedRow === row">
<td *ngIf="multiselect">
<label
class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect mdl-data-table__select"

View File

@ -53,10 +53,6 @@ export class DataTableComponent implements OnInit {
@Output()
rowDblClick: EventEmitter<DataRowEvent> = new EventEmitter<DataRowEvent>();
noContentTemplate: TemplateRef<any>;
isSelectAllChecked: boolean = false;
@Output()
showRowContextMenu: EventEmitter<any> = new EventEmitter();
@ -66,6 +62,13 @@ export class DataTableComponent implements OnInit {
@Output()
executeRowAction: EventEmitter<any> = new EventEmitter();
noContentTemplate: TemplateRef<any>;
isSelectAllChecked: boolean = false;
get selectedRow(): DataRow {
return this.data.selectedRow;
}
ngOnInit() {
if (!this.data) {
this.data = new ObjectDataTableAdapter([], []);
@ -82,6 +85,10 @@ export class DataTableComponent implements OnInit {
e.preventDefault();
}
if (this.data) {
this.data.selectedRow = row;
}
this.rowClick.emit({
value: row,
event: e

View File

@ -16,6 +16,7 @@
*/
export interface DataTableAdapter {
selectedRow: DataRow;
getRows(): Array<DataRow>;
setRows(rows: Array<DataRow>): void;
getColumns(): Array<DataColumn>;

View File

@ -26,6 +26,8 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
private _rows: DataRow[];
private _columns: DataColumn[];
selectedRow: DataRow;
static generateSchema(data: any[]) {
let schema = [];

View File

@ -48,6 +48,7 @@ export class ShareDataTableAdapter implements DataTableAdapter, PaginationProvid
thumbnails: boolean = false;
dataLoaded: DataLoadedEventEmitter;
selectedRow: DataRow;
constructor(private documentListService: DocumentListService,
private basePath: string,