您可以尝试创建自定义过滤器吗?如下所示:
组件.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-my-table',
templateUrl: './my-table.component.html',
styleUrls: ['./my-table.component.css']
})
export class MyTableComponent {
data: any[] = [
{ duration: '00:04:53' },
{ duration: '00:03:20' },
// Add more data here
];
customDurationFilter(value: string, filter: string): boolean {
if (!filter) {
return true;
}
const filterParts = filter.split(':').map(part => parseInt(part, 10));
const valueParts = value.split(':').map(part => parseInt(part, 10));
for (let i = 0; i < filterParts.length; i++) {
if (filterParts[i] !== valueParts[i]) {
return false;
}
}
return true;
}
}
用表数据源替换数据。然后,在
组件.html
<p-table [value]="data">
<ng-template pTemplate="header">
<tr>
<th pSortableColumn="duration">
Duration
<p-columnFilter type="custom" [field]="'duration'" [matchMode]="'custom'" [filterFunction]="customDurationFilter" display="menu"></p-columnFilter>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData>
<tr>
<td>{{ rowData.duration }}</td>
</tr>
</ng-template>
</p-table>