mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
#82 multiselection UI for datatable
This commit is contained in:
parent
4e9deac9ed
commit
58f7429f25
@ -1,5 +1,11 @@
|
|||||||
<div class="p-10">
|
<div class="p-10">
|
||||||
<alfresco-datatable [data]="data"></alfresco-datatable>
|
<alfresco-datatable [data]="data" [multiselect]="multiselect"></alfresco-datatable>
|
||||||
|
</div>
|
||||||
|
<div class="p-10">
|
||||||
|
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="checkbox-1">
|
||||||
|
<input type="checkbox" id="checkbox-1" class="mdl-checkbox__input" [(ngModel)]="multiselect">
|
||||||
|
<span class="mdl-checkbox__label">Multiselect</span>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="p-10">
|
<div class="p-10">
|
||||||
<button
|
<button
|
||||||
|
@ -35,6 +35,8 @@ declare let __moduleName: string;
|
|||||||
pipes: [AlfrescoPipeTranslate]
|
pipes: [AlfrescoPipeTranslate]
|
||||||
})
|
})
|
||||||
export class DataTableDemoComponent {
|
export class DataTableDemoComponent {
|
||||||
|
|
||||||
|
multiselect: boolean = false;
|
||||||
data: ObjectDataTableAdapter;
|
data: ObjectDataTableAdapter;
|
||||||
|
|
||||||
private _imageUrl: string = 'http://placehold.it/140x100';
|
private _imageUrl: string = 'http://placehold.it/140x100';
|
||||||
@ -88,7 +90,7 @@ export class DataTableDemoComponent {
|
|||||||
replaceColumns() {
|
replaceColumns() {
|
||||||
let schema = [
|
let schema = [
|
||||||
{ type: 'text', key: 'id', sortable: true },
|
{ type: 'text', key: 'id', sortable: true },
|
||||||
{ type: 'text', key: 'name', sortable: true }
|
{ type: 'text', key: 'name', sortable: true, cssClass: 'full-width name-column' }
|
||||||
];
|
];
|
||||||
let columns = schema.map(col => new ObjectDataColumn(col));
|
let columns = schema.map(col => new ObjectDataColumn(col));
|
||||||
this.data.setColumns(columns);
|
this.data.setColumns(columns);
|
||||||
|
@ -14,6 +14,5 @@
|
|||||||
"node_modules",
|
"node_modules",
|
||||||
"typings/main",
|
"typings/main",
|
||||||
"typings/main.d.ts"
|
"typings/main.d.ts"
|
||||||
],
|
]
|
||||||
"compileOnSave": true
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,18 @@
|
|||||||
<table *ngIf="data" class="mdl-data-table mdl-js-data-table mdl-shadow--2dp full-width">
|
<table
|
||||||
|
*ngIf="data"
|
||||||
|
class="mdl-data-table mdl-js-data-table mdl-shadow--2dp full-width">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<!-- Columns -->
|
<!-- Columns -->
|
||||||
|
<th *ngIf="multiselect">
|
||||||
|
<label
|
||||||
|
class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect mdl-data-table__select"
|
||||||
|
[class.is-checked]="isSelectAllChecked"
|
||||||
|
for="table-header"
|
||||||
|
(click)="onSelectAllClick($event)">
|
||||||
|
<input type="checkbox" id="table-header" class="mdl-checkbox__input" />
|
||||||
|
</label>
|
||||||
|
</th>
|
||||||
<th class="mdl-data-table__cell--non-numeric {{col.cssClass}}"
|
<th class="mdl-data-table__cell--non-numeric {{col.cssClass}}"
|
||||||
*ngFor="#col of data.getColumns()"
|
*ngFor="#col of data.getColumns()"
|
||||||
[class.column-header]="col.title"
|
[class.column-header]="col.title"
|
||||||
@ -21,7 +32,14 @@
|
|||||||
<!-- todo: special 'navigate parent row' support -->
|
<!-- todo: special 'navigate parent row' support -->
|
||||||
|
|
||||||
<tr *ngFor="#row of data.getRows(); #idx = index">
|
<tr *ngFor="#row of data.getRows(); #idx = index">
|
||||||
|
<td *ngIf="multiselect">
|
||||||
|
<label
|
||||||
|
class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect mdl-data-table__select"
|
||||||
|
[attr.for]="'row[' + idx + ']'"
|
||||||
|
[class.is-checked]="row.isSelected">
|
||||||
|
<input type="checkbox" [attr.id]="'row[' + idx + ']'" class="mdl-checkbox__input" [(ngModel)]="row.isSelected" />
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
<td *ngFor="#col of data.getColumns()" [ngSwitch]="col.type"
|
<td *ngFor="#col of data.getColumns()" [ngSwitch]="col.type"
|
||||||
class="mdl-data-table__cell--non-numeric data-cell {{col.cssClass}}"
|
class="mdl-data-table__cell--non-numeric data-cell {{col.cssClass}}"
|
||||||
(click)="onRowClick(row, $event)" (dblclick)="onRowDblClick(row, $event)">
|
(click)="onRowClick(row, $event)" (dblclick)="onRowDblClick(row, $event)">
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Component,
|
Component,
|
||||||
|
// NgZone,
|
||||||
OnInit,
|
OnInit,
|
||||||
Input,
|
Input,
|
||||||
Output,
|
Output,
|
||||||
@ -46,12 +47,19 @@ export class DataTableComponent implements OnInit, AfterViewChecked {
|
|||||||
@Input()
|
@Input()
|
||||||
data: DataTableAdapter;
|
data: DataTableAdapter;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
multiselect: boolean = false;
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
rowClick: EventEmitter<any> = new EventEmitter();
|
rowClick: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
rowDblClick: EventEmitter<any> = new EventEmitter();
|
rowDblClick: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
|
isSelectAllChecked: boolean = false;
|
||||||
|
|
||||||
|
constructor(/*private _ngZone?: NgZone*/) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.data) {
|
if (this.data) {
|
||||||
console.log(this.data);
|
console.log(this.data);
|
||||||
@ -98,6 +106,26 @@ export class DataTableComponent implements OnInit, AfterViewChecked {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSelectAllClick(e?) {
|
||||||
|
if (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isSelectAllChecked = !this.isSelectAllChecked;
|
||||||
|
|
||||||
|
if (this.multiselect) {
|
||||||
|
let rows = this.data.getRows();
|
||||||
|
for (let i = 0; i < rows.length; i++) {
|
||||||
|
rows[i].isSelected = this.isSelectAllChecked;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
this._ngZone.run(() => {
|
||||||
|
this.data.getRows()[1].isSelected = true;
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isIconValue(row: DataRow, col: DataColumn) {
|
isIconValue(row: DataRow, col: DataColumn) {
|
||||||
return row.getValue(col.key).startsWith('material-icons://');
|
return row.getValue(col.key).startsWith('material-icons://');
|
||||||
}
|
}
|
||||||
|
@ -25,25 +25,33 @@ export interface DataTableAdapter {
|
|||||||
getSorting(): DataSorting;
|
getSorting(): DataSorting;
|
||||||
setSorting(sorting: DataSorting): void;
|
setSorting(sorting: DataSorting): void;
|
||||||
sort(key?: string, direction?: string): void;
|
sort(key?: string, direction?: string): void;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DataRow {
|
export interface DataRow {
|
||||||
|
|
||||||
|
isSelected: boolean;
|
||||||
hasValue(key: string): boolean;
|
hasValue(key: string): boolean;
|
||||||
getValue(key: string): any;
|
getValue(key: string): any;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DataColumn {
|
export interface DataColumn {
|
||||||
|
|
||||||
key: string;
|
key: string;
|
||||||
type: string; // text|image
|
type: string; // text|image
|
||||||
sortable?: boolean;
|
sortable?: boolean;
|
||||||
title?: string;
|
title?: string;
|
||||||
srTitle?: string;
|
srTitle?: string;
|
||||||
cssClass?: string;
|
cssClass?: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DataSorting {
|
export class DataSorting {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public key?: string,
|
public key?: string,
|
||||||
public direction?: string) {
|
public direction?: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,9 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
|
|||||||
|
|
||||||
// Simple implementation of the DataRow interface.
|
// Simple implementation of the DataRow interface.
|
||||||
export class ObjectDataRow implements DataRow {
|
export class ObjectDataRow implements DataRow {
|
||||||
|
|
||||||
|
isSelected: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private obj: any) {
|
private obj: any) {
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user