mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
committed by
Eugenio Romano
parent
033939615d
commit
2e03ef3548
@@ -185,14 +185,14 @@ describe('DataTable', () => {
|
||||
});
|
||||
|
||||
it('should initialize default adapter', () => {
|
||||
let table = new DataTableComponent(null);
|
||||
let table = new DataTableComponent(null, null);
|
||||
expect(table.data).toBeUndefined();
|
||||
table.ngOnChanges({'data': new SimpleChange('123', {}, true)});
|
||||
expect(table.data).toEqual(jasmine.any(ObjectDataTableAdapter));
|
||||
});
|
||||
|
||||
it('should load data table on onChange', () => {
|
||||
let table = new DataTableComponent(null);
|
||||
let table = new DataTableComponent(null, null);
|
||||
let data = new ObjectDataTableAdapter([], []);
|
||||
|
||||
expect(table.data).toBeUndefined();
|
||||
|
@@ -15,15 +15,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, OnChanges, SimpleChange, SimpleChanges, Input, Output, EventEmitter, ElementRef, TemplateRef, AfterContentInit, ContentChild, Optional } from '@angular/core';
|
||||
import { MdCheckboxChange } from '@angular/material';
|
||||
import { Observable, Observer } from 'rxjs/Rx';
|
||||
import { DataColumnListComponent } from 'ng2-alfresco-core';
|
||||
|
||||
import {
|
||||
Component, OnChanges, DoCheck, IterableDiffers, SimpleChange, SimpleChanges, Input,
|
||||
Output, EventEmitter, ElementRef, TemplateRef, AfterContentInit, ContentChild, Optional
|
||||
} from '@angular/core';
|
||||
import { DataTableAdapter, DataRow, DataColumn, DataSorting, DataRowEvent } from '../../data/datatable-adapter';
|
||||
import { ObjectDataTableAdapter, ObjectDataRow } from '../../data/object-datatable-adapter';
|
||||
import { DataCellEvent } from './data-cell.event';
|
||||
import { DataRowActionEvent } from './data-row-action.event';
|
||||
import { DataColumnListComponent } from 'ng2-alfresco-core';
|
||||
import { MdCheckboxChange } from '@angular/material';
|
||||
import { Observable, Observer } from 'rxjs/Rx';
|
||||
|
||||
declare var componentHandler;
|
||||
|
||||
@@ -32,7 +34,7 @@ declare var componentHandler;
|
||||
styleUrls: ['./datatable.component.css'],
|
||||
templateUrl: './datatable.component.html'
|
||||
})
|
||||
export class DataTableComponent implements AfterContentInit, OnChanges {
|
||||
export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck {
|
||||
|
||||
@ContentChild(DataColumnListComponent) columnList: DataColumnListComponent;
|
||||
|
||||
@@ -95,7 +97,16 @@ export class DataTableComponent implements AfterContentInit, OnChanges {
|
||||
private clickObserver: Observer<DataRowEvent>;
|
||||
private click$: Observable<DataRowEvent>;
|
||||
|
||||
constructor(@Optional() private el: ElementRef) {
|
||||
private schema: DataColumn[] = [];
|
||||
|
||||
private differ: any;
|
||||
|
||||
constructor(
|
||||
@Optional() private el: ElementRef,
|
||||
private differs: IterableDiffers) {
|
||||
if (differs) {
|
||||
this.differ = differs.find([]).create(null);
|
||||
}
|
||||
this.click$ = new Observable<DataRowEvent>(observer => this.clickObserver = observer).share();
|
||||
}
|
||||
|
||||
@@ -140,6 +151,13 @@ export class DataTableComponent implements AfterContentInit, OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
ngDoCheck() {
|
||||
let changes = this.differ.diff(this.rows);
|
||||
if (changes) {
|
||||
this.setTableRows(this.rows);
|
||||
}
|
||||
}
|
||||
|
||||
isPropertyChanged(property: SimpleChange): boolean {
|
||||
return property && property.currentValue ? true : false;
|
||||
}
|
||||
@@ -189,7 +207,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges {
|
||||
}
|
||||
|
||||
private initTable() {
|
||||
this.data = new ObjectDataTableAdapter(this.rows, []);
|
||||
this.data = new ObjectDataTableAdapter(this.rows, this.schema);
|
||||
}
|
||||
|
||||
isTableEmpty() {
|
||||
@@ -202,14 +220,12 @@ export class DataTableComponent implements AfterContentInit, OnChanges {
|
||||
}
|
||||
|
||||
private setTableSchema() {
|
||||
let schema: DataColumn[] = [];
|
||||
|
||||
if (this.columnList && this.columnList.columns) {
|
||||
schema = this.columnList.columns.map(c => <DataColumn> c);
|
||||
this.schema = this.columnList.columns.map(c => <DataColumn> c);
|
||||
}
|
||||
|
||||
if (this.data && schema && schema.length > 0) {
|
||||
this.data.setColumns(schema);
|
||||
if (this.data && this.schema && this.schema.length > 0) {
|
||||
this.data.setColumns(this.schema);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,4 +369,5 @@ export class DataTableComponent implements AfterContentInit, OnChanges {
|
||||
isMultiSelectionMode(): boolean {
|
||||
return this.selectionMode && this.selectionMode.toLowerCase() === 'multiple';
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user