valor-software / ng2-table

Simple table extension with sorting, filtering, paging... for Angular2 apps
http://valor-software.github.io/ng2-table/
MIT License
553 stars 335 forks source link

How to put a link to a specific column #559

Open YuTung opened 7 years ago

YuTung commented 7 years ago

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

mbtakanov commented 7 years ago

I did it like this:

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

@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>  
arinhere commented 6 years ago

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

mbtakanov commented 6 years ago

@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.

levibautista commented 5 years ago

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