prime-ng datatable: how to use Globalfilter with ng-template tag in p-column

蓝咒 提交于 2019-12-14 02:22:03

问题


CONTEXT

I use Prime-ng Datatable module in my Angular project. I have 7 columns like shown below in my datatable. The data shows very well in browser

PROBLEM

I can't use [globalFilter]. When I try to do a search, the result in my datatable is always displayed as "No records found". It's like the Global filter can't reach the data in my <ng-template>.

APP.COMPONENT.HTML

<!-- language: lang-html -->

<div>
    <input #gb type="text" pInputText size="50" placeholder="Global Filter">
</div>

<p-dataTable [value]="reviewTasksList" [rows]="5" [paginator]="true" [globalFilter]="gb" [pageLinks]="3" [responsive]="true" [stacked]="stacked">
 <p-column field="name" header="Name">
   <ng-template let-col let-file="rowData" pTemplate="body">
       <a [routerLink]="[file.id]" href="#">{{ file.category.name }}</a>
   </ng-template>
 </p-column>
</p-dataTable>

回答1:


I think you should ensure field is set properly.

For example, if you model correspond to this:

reviewTaskList = {
  category: {
    name: "Category Name"
  }
}

Then you'd have to use it like this:

<p-dataTable [value]="reviewTasksList" [rows]="5" [paginator]="true" [globalFilter]="gb" [pageLinks]="3" [responsive]="true" [stacked]="stacked">
 <p-column field="reviewTasksList.category.name" header="Name"></p-column>
</p-dataTable>


来源:https://stackoverflow.com/questions/43610356/prime-ng-datatable-how-to-use-globalfilter-with-ng-template-tag-in-p-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!