angular2 routing - Adding Links not working in ng2-smart table -
im trying add link in ng2-smart table plugin of angular 2
https://akveo.github.io/ng2-smart-table/#/examples/custom-editors-viewers
for adding link have given below:
mycomponent.ts
@component({ template: ` {{rendervalue}} `, }) export class customrendercomponent implements viewcell, oninit { rendervalue: string; @input() value: string | number; @input() rowdata: any; ngoninit() { this.rendervalue = this.value.tostring().touppercase(); } } @component({ template: ` name: <input [ngclass]="inputclass" #name class="form-control short-input" [name]="cell.getid()" [disabled]="!cell.iseditable()" [placeholder]="cell.gettitle()" (click)="onclick.emit($event)" (keyup)="updatevalue()" (keydown.enter)="onedited.emit($event)" (keydown.esc)="onstopediting.emit()"><br> url: <input [ngclass]="inputclass" #url class="form-control short-input" [name]="cell.getid()" [disabled]="!cell.iseditable()" [placeholder]="cell.gettitle()" (click)="onclick.emit($event)" (keyup)="updatevalue()" (keydown.enter)="onedited.emit($event)" (keydown.esc)="onstopediting.emit()"> <div [hidden]="true" [innerhtml]="cell.getvalue()" #htmlvalue></div> `, }) export class customeditorcomponent extends defaulteditor implements afterviewinit { @viewchild('name') name: elementref; @viewchild('url') url: elementref; @viewchild('htmlvalue') htmlvalue: elementref; constructor() { super(); console.log('asdasdasdasdfsdfgd') } ngafterviewinit() { console.log('link here') if (this.cell.newvalue !== '') { this.name.nativeelement.value = this.geturlname(); this.url.nativeelement.value = this.geturlhref(); } } updatevalue() { const href = this.url.nativeelement.value; const name = this.name.nativeelement.value; this.cell.newvalue = `<a href='${href}'>${name}</a>`; } geturlname(): string { return this.htmlvalue.nativeelement.innertext; } geturlhref(): string { return this.htmlvalue.nativeelement.queryselector('a').getattribute('href'); } } export class mycomponent ... .... link: { title: 'link', type: 'html', editor: { type: 'custom', component: customeditorcomponent, }, },
with customeditorcomponent class added in code,(https://github.com/akveo/ng2-smart-table/blob/master/src/app/pages/examples/custom-edit-view/custom-editor.component.ts) link doesnt appear.
Comments
Post a Comment