You must put th in a tr tag:
See Prime Ng Filter Example from Site:
export class TableFilterDemo implements OnInit {
cars: Car[];
cols: any[];
brands: SelectItem[];
colors: SelectItem[];
yearFilter: number;
yearTimeout: any;
constructor(private carService: CarService) { }
ngOnInit() {
this.carService.getCarsMedium().then(cars => this.cars = cars);
this.brands = [
{ label: 'All Brands', value: null },
{ label: 'Audi', value: 'Audi' },
{ label: 'BMW', value: 'BMW' },
{ label: 'Fiat', value: 'Fiat' },
{ label: 'Honda', value: 'Honda' },
{ label: 'Jaguar', value: 'Jaguar' },
{ label: 'Mercedes', value: 'Mercedes' },
{ label: 'Renault', value: 'Renault' },
{ label: 'VW', value: 'VW' },
{ label: 'Volvo', value: 'Volvo' }
];
this.colors = [
{ label: 'White', value: 'White' },
{ label: 'Green', value: 'Green' },
{ label: 'Silver', value: 'Silver' },
{ label: 'Black', value: 'Black' },
{ label: 'Red', value: 'Red' },
{ label: 'Maroon', value: 'Maroon' },
{ label: 'Brown', value: 'Brown' },
{ label: 'Orange', value: 'Orange' },
{ label: 'Blue', value: 'Blue' }
];
this.cols = [
{ field: 'vin', header: 'Vin' },
{ field: 'year', header: 'Year' },
{ field: 'brand', header: 'Brand' },
{ field: 'color', header: 'Color' }
];
}
onYearChange(event, dt) {
if (this.yearTimeout) {
clearTimeout(this.yearTimeout);
}
this.yearTimeout = setTimeout(() => {
dt.filter(event.value, 'year', 'gt');
}, 250);
}
}
and html File:
<p-table #dt [columns]="cols" [value]="cars" [paginator]="true" [rows]="10">
<ng-template pTemplate="caption">
<div style="text-align: right">
<i class="fa fa-search" style="margin:4px 4px 0 0"></i>
<input type="text" pInputText size="50" placeholder="Global Filter" (input)="dt.filterGlobal($event.target.value, 'contains')" style="width:auto">
</div>
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
<tr>
<th *ngFor="let col of columns" [ngSwitch]="col.field">
<input *ngSwitchCase="'vin'" pInputText type="text" (input)="dt.filter($event.target.value, col.field, col.filterMatchMode)">
<div *ngSwitchCase="'year'">
Value < {{yearFilter}}
<i class="fa fa-close" (click)="yearFilter=null;dt.filter(null, col.field, col.filterMatchMode)" style="cursor:pointer" *ngIf="yearFilter"></i>
<p-slider [style]="{'width':'100%','margin-top':'8px'}" [(ngModel)]="yearFilter" [min]="1970" [max]="2010" (onChange)="onYearChange($event, dt)"></p-slider>
</div>
<p-dropdown *ngSwitchCase="'brand'" [options]="brands" [style]="{'width':'100%'}" (onChange)="dt.filter($event.value, col.field, 'equals')"></p-dropdown>
<p-multiSelect *ngSwitchCase="'color'" [options]="colors" defaultLabel="All Colors" (onChange)="dt.filter($event.value, col.field, 'in')"></p-multiSelect>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
p-dropdown .ui-dropdown
in your CSS. See this stackblitz. – ConnorsFan