我正在开发一个带有 PrimeNG 表的 SPA 来显示记录,并且每列都有一个数据过滤器。
其中之一是日期记录,它以 ISO 字符串形式出现,并在输入到表本身之前转换为 Date 对象。
我需要日期格式为“dd/MM/yyyy”,并且默认情况下日期的 p-columnFilter 与“MM/dd/yyyy”一起使用,因此我使用过滤器的 pTemplate 来自定义日历中的格式。
<ng-template ngFor let-col [ngForOf]="columns">
<th *ngIf="col.type !== 'date'" [pSortableColumn]="col.field">
{{col.header}}
<p-sortIcon [field]="col.field"></p-sortIcon>
</th>
<th *ngIf="col.type === 'date'" class="obe-table__date-header" [pSortableColumn]="col.field" [attr.rowspan]="2">
{{col.header}}
<p-sortIcon [field]="col.field"></p-sortIcon>
<p-columnFilter type="date" [field]="col.field" display="menu">
<ng-template pTemplate="filter">
<p-calendar dateFormat="dd/mm/yy"></p-calendar>
</ng-template>
</p-columnFilter>
</th>
</ng-template>Run Code Online (Sandbox Code Playgroud)
然后,当显示过滤器 UI 并单击“应用”时,它会表现得好像没有注册该值。我在想我在日历中缺少 [ngModel] 绑定,但我也尝试过但没有成功。
先感谢您。