如何在<p-datatable>中使用模板 [英] How to use template in <p-datatable>
问题描述
我有一个非常基本的问题我无法回答,因为大多数链接到 http://www.primefaces.org/primenga> 不再工作.我也尝试注册到他们的论坛,但他们的激活邮件从未到达.
I've got a very basic question which I can't answer myself because most links to http://www.primefaces.org/primeng don't work anymore. I also tried registering to their forum but their activation mail never arrives.
我使用 Angular2 并有一个包含两列的数据表:文件名和状态.我要更改的状态列.它现在包含一个从 1 到 4 的数字,我想根据状态显示一个字形.
I use Angular2 and have a datatable with two columns: filename and status. The status column I want to change. It holds now a number from 1 to 4 and I want to show a glyphicon based on the status.
我现在有了这个,它正在工作:
I now have this, which is working:
<p-dataTable [hidden]="loading" [value]="files" selectionMode="single" sortField="Status" [sortOrder]="-1">
<p-column field="FileName" header="Naam" sortable="true"></p-column>
<p-column field="Status" header="Status" sortable="true"></p-column>
</p-dataTable>
我试过这个,只是为了测试模板,但没有任何变化:
I tried this, just to test the templating but nothing changes:
<p-dataTable [hidden]="loading" [value]="files" selectionMode="single" sortField="Status" [sortOrder]="-1">
<p-column field="FileName" header="Naam" sortable="true"></p-column>
<p-column field="Status" header="Status" sortable="true">
<template let-file="rowData">
{{file.Status == 1 ? "Yes" : "No"}}
</template>
</p-column>
</p-dataTable>
所以保存到结论我没有正确使用它.
So save to conclude I'm not using it properly.
我们使用的是 PrimeNG 1.0.0-beta.16
We're using PrimeNG 1.0.0-beta.16
推荐答案
每个 p-column
可以有两个模板 - body
和 header
,您应该指定它是哪一个.这不是强制性的,因为我认为 body
是默认的,这就是你在这种情况下需要的,但这是一个很好的做法.您还需要将 pTemplate
添加到模板中,以便 p-column
使用它,这就是 p-column
不会显示的原因您提供的模板.因此,您的代码应如下所示:
Each p-column
can have two templates - body
and header
, you should specify which one it is. It's not mandatory because body
is default I think and this is what you need in this case, but it's good practice. You also need to add pTemplate
to template in order for p-column
to use it, this is the reason p-column
won't display template you provided. So, your code should look like this:
<p-dataTable [hidden]="loading" [value]="files" selectionMode="single" sortField="Status" [sortOrder]="-1">
<p-column field="FileName" header="Naam" sortable="true"></p-column>
<p-column field="Status" header="Status" sortable="true">
<ng-template let-file="rowData" pTemplate type="body">
{{file.Status == 1 ? "Yes" : "No"}}
</ng-template>
</p-column>
</p-dataTable>
这篇关于如何在<p-datatable>中使用模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!