import { cloneDeep } from 'lodash-es'; import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core'; import { data as treeData } from '../../treetable-demo.data'; import { TreeTableComponent } from '@farris/ui-treetable'; @Component({ selector: 'demo-cell-template', templateUrl: './demo-cell-template.component.html', }) export class DemoTreetableCellTemplateComponent implements OnInit { treedata = treeData.data; cols = []; showIcon = true; enableFindText = false; @ViewChild('activeCell') activeCell: TemplateRef; @ViewChild('tt') tt: TreeTableComponent; constructor() { } ngOnInit() { this.cols = [ { field: 'name', title: 'Name', width: 200}, { field: 'size', title: 'Size', width: 100 }, { field: 'type', title: 'Type', width: 100}, { field: 'single', title: '单身', width: 100}, { field: 'age', title: '年龄', width: 100}, { field: 'birthday', title: '日期', width: 100}, { field: 'photo', title: '头像', width: 100}, { field: 'xueli', title: '学历', width: 100}, { field: '', title: '操作', width: 200, template: this.activeCell } ]; } updateTreeicon() { this.tt.expandIcon = 'expand-icon'; this.tt.collapseIcon = 'collapse-icon'; this.tt.leafIcon = 'leaf-icon'; this.tt.detectChanges(); } editClick($event, ctx) { console.log(ctx); } appendNode() { const p = this.tt.selectedRow || null; this.tt.append({ name: 'Lucas Demo' + parseInt('' + Math.random() * 1000, 10), size: '60kg' }, p); // const newTreeData = cloneDeep(this.treedata); // const node = newTreeData.find((n: any) => n.id === 'Cloud'); // const newNode = {data: { name: 'Lucas Demo' + parseInt('' + Math.random() * 1000, 10), size: '60kg' }}; // node.children.push(newNode); // this.treedata = newTreeData; } deleteNode() { const p = this.tt.selectedRow || null; if (p) { this.tt.remove(p.id); } } moveDown() { } }