Skip to content

Commit

Permalink
tree-data-table column name customize issue fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
DatsGawas committed Aug 10, 2017
1 parent c8c8b56 commit 1d8ee9a
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/treedatatable/treedatatable.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
*
*/

import {OnInit, Input, Component, SimpleChange, EventEmitter, Output} from '@angular/core';
import {
OnInit, Input, Component, SimpleChange, EventEmitter, Output, QueryList, ContentChildren, AfterContentInit
} from '@angular/core';
import {CommonHttpService} from '../common.http.service';
import {ColumnComponent} from "../datatable/column.component";


@Component({
Expand Down Expand Up @@ -82,7 +85,7 @@ import {CommonHttpService} from '../common.http.service';
]
})

export class TreeDataTableComponent implements OnInit{
export class TreeDataTableComponent implements OnInit, AfterContentInit{

@Input() title: string;

Expand All @@ -108,10 +111,9 @@ export class TreeDataTableComponent implements OnInit{

responseData: any;

constructor (private treeDataTableService: CommonHttpService){
this.columns.push({text: 'Task', dataIndex: 'task', hidden: false, dataType : 'string'});
this.columns.push({text: 'Duration', dataIndex: 'duration', hidden: false , dataType : 'number'});
this.columns.push({text: 'User', dataIndex: 'user', hidden: false, dataType : 'string'});
@ContentChildren(ColumnComponent) columnRef: QueryList<ColumnComponent>;

constructor (private treeDataTableService: CommonHttpService) {
}

ngOnInit(){
Expand All @@ -130,8 +132,25 @@ export class TreeDataTableComponent implements OnInit{
}
}

ngAfterViewInit(){
ngAfterContentInit() {
this.createConfig();
}

createConfig() {
let columnRefArray = [];
columnRefArray = this.columnRef.toArray();
for (let cr = 0 ; cr < columnRefArray.length; cr++) {
const columnConfig = columnRefArray[cr];
let columnData: any;
if (columnConfig.bodyTemplate == null && columnConfig.headerTemplate == null) {
columnData = {
text: columnConfig.text, dataIndex: columnConfig.dataIndex,
hidden: columnConfig.hidden, dataType : columnConfig.dataType
};
}

this.columns.push(columnData);
}
}

ngOnChanges(change: SimpleChange){
Expand Down

0 comments on commit 1d8ee9a

Please sign in to comment.