在table中添加link Angular 8
Add link in a table Angular 8
我有一个 table 和一些列,我有一个 "documents" 可以单击和下载的列。
我怎样才能使文档名称成为 link?
HTML
<p-table #dt3 [columns]="colsPermessi" [value]="permessi" [paginator]="true" [scrollable]="false" [rows]="10" [autoLayout]="true">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" pResizableColumn>{{col.header}} </th>
<th>Azioni</th>
<th>Permessi</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of colsPermessi">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
因此,我希望 "document" 列是可点击的,点击它会调用 "downloadFile ()" 函数。
我该怎么做?
这可以使用 *ngIf 来分隔您的案例来完成。对于文档列,使用 ngIf 插入超链接标记。对于所有其他内容,只需插入文本即可。请参阅以下示例:
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of colsPermessi">
<span *ngIf="col.header == 'Documento'><a [href]="col.url">{{rowData[col.field]}}</a></span>
<span *ngIf="col.header != 'Documento'>{{rowData[col.field]}}</span>
</td>
</tr>
</ng-template>
我有一个 table 和一些列,我有一个 "documents" 可以单击和下载的列。 我怎样才能使文档名称成为 link?
HTML
<p-table #dt3 [columns]="colsPermessi" [value]="permessi" [paginator]="true" [scrollable]="false" [rows]="10" [autoLayout]="true">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" pResizableColumn>{{col.header}} </th>
<th>Azioni</th>
<th>Permessi</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of colsPermessi">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
因此,我希望 "document" 列是可点击的,点击它会调用 "downloadFile ()" 函数。 我该怎么做?
这可以使用 *ngIf 来分隔您的案例来完成。对于文档列,使用 ngIf 插入超链接标记。对于所有其他内容,只需插入文本即可。请参阅以下示例:
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of colsPermessi">
<span *ngIf="col.header == 'Documento'><a [href]="col.url">{{rowData[col.field]}}</a></span>
<span *ngIf="col.header != 'Documento'>{{rowData[col.field]}}</span>
</td>
</tr>
</ng-template>