I have a PrimeNG datatable with dynamic columns and I want to add a filter to these columns filtering for the value.
Here is my datatable column with the filter :
<p-column *ngFor="let param of searchFilters" [style]="{'width':'auto'}" header="{{param.name}}"
[filter]="true" filterPlaceholder="Search">
<ng-template pTemplate="filter" let-col>
<input type="text" (keyup)="dt.onFilterKeyup($event.target.value, param.name, 'contains')"/>
</ng-template>
<ng-template let-col let-user="rowData" pTemplate="body">
<span>
{{getUserAttributeCaseInsensitive(user.attributes, param.name)}}
</span>
</ng-template>
</p-column>
My User object which represents the data for the datatable looks something like this :
User {
id?: number;
attributes?: Object;
}
And in this attributes object you can find the values for each column. The searchFilters used for the *ngFor
to build each column is dynamically build and does not always contain everything that the attributes object contains. Now because it is an object I can not set the field="attribute[param.name]"
(from the *ngFor
). So I tried a custom filter which does not work either.
Can somebody help ?