ng2-table icon indicating copy to clipboard operation
ng2-table copied to clipboard

How to put a link to a specific column

Open YuTung opened this issue 8 years ago • 5 comments

The table is working, but I want one column to have links. How to do that? Thanks.

YuTung avatar Jun 09 '17 21:06 YuTung

I did it like this:

private columnsForTable: Array<any> = [
{ prop1: 1, prop2: 2, prop3: '<a href="https://www.google.com">Link</a>'},
...
];

mbtakanov avatar Jun 30 '17 08:06 mbtakanov

@mbtakanov Is it possible to iterate over rows in html? I know for the fact that if you use [rows]="rows" then it will be populated but If i want to iterate over then how is it possible? The following I am doing but it doesn't work

<ng-table [config]="config" [columns]="columns">
			
          	<tr *ngFor="let row of rows">
          		<td>1</td>
          		<td>{{ row.eid }}</td>
          		<td>{{ row.rankValue }}</td>
          		<td>{{ row.reason.similarilty }}</td>
          	</tr>
        </ng-table>  

Sam2243 avatar Jan 19 '18 00:01 Sam2243

Is there any way to use routerlink, or even a click event in stead of href? as href will refresh the whole page, which is not expected for angular

arinhere avatar Jan 29 '18 06:01 arinhere

@Sam2243 Why you need to iterate over the rows in the html? What you aim for? @arinhere Yes, you can use routerLink=['/foo/123']. I've used the following:

// JS
public onCellClick(data: any): any {
    if (data.column === 'edit') {
        this.router.navigate(['/foo/', data.row.id]);
    }
}
<!--HTML-->
<ng-table [config]="config"
          (tableChanged)="onChangeTable(config)"
          (cellClicked)="onCellClick($event)"
          [rows]="rows" [columns]="columns">
// JS data object
let rows = [
{'id': 127314, 'edit': '<div>Edit</div>', ... ,},
 ...
]

This is in case you have edit as a property in your column and row arrays and id as a row property in your row array.

mbtakanov avatar Feb 19 '18 14:02 mbtakanov

@mbtakanov I tried your solutions on the column but it's just showing text instead a href link

levibautista avatar Nov 01 '18 07:11 levibautista