当我使用基本方式将数据绑定到 p-dataTable 时,列的 p-dropdown 过滤器工作正常,但是当我使用绑定 p-dataTable 时[lazy]="true" (onLazyLoad)="loadData($event)"
,下拉列过滤器不起作用。
工作代码:
<p-dataTable #dt id="myDataTable" [value]="data" selectionMode="single" (onRowSelect)="onRowSelect($event)" [paginator]="true"
rows="10" [responsive]="true" [totalRecords]="totalRecords">
<p-column field="Name" header="Name" [sortable]="true" [filter]="true" filterMatchMode="contains" [style]="{'width':'20%'}"></p-column>
<p-column field="Type" header="Type" [sortable]="true" [filter]="true" filterMatchMode="equals" [style]="{'width':'20%','overflow':'visible'}">
<template pTemplate="filter" let-col>
<p-dropdown [options]="typesFilter" [style]="{'width':'100%'}" (onChange)="dt.filter($event.value,col.field,col.filterMatchMode)" styleClass="ui-column-filter"></p-dropdown>
</template>
</p-column>
</p-dataTable>
不工作代码:
<p-dataTable #dt id="myDataTable" [value]="data" selectionMode="single" (onRowSelect)="onRowSelect($event)" [lazy]="true" (onLazyLoad)="loadData($event)" [paginator]="true"
rows="10" [responsive]="true" [totalRecords]="totalRecords">
<p-column field="Name" header="Name" [sortable]="true" [filter]="true" filterMatchMode="contains" [style]="{'width':'20%'}"></p-column>
<p-column field="Type" header="Type" [sortable]="true" [filter]="true" filterMatchMode="equals" [style]="{'width':'20%','overflow':'visible'}">
<template pTemplate="filter" let-col>
<p-dropdown [options]="typesFilter" [style]="{'width':'100%'}" (onChange)="dt.filter($event.value,col.field,col.filterMatchMode)" styleClass="ui-column-filter"></p-dropdown>
</template>
</p-column>
</p-dataTable>
工作代码和不工作代码之间的区别如下
[lazy]="true" (onLazyLoad)="loadData($event)"
在 p-dataTable 中绑定在第一行。