I have a primeng table where on column value is obtained from a nested object.I am unable to filter the table using that column value.The filter works fine if enter value present in other columns.Please help.Thanks in advance.
Here is my typescript:
this.cols = [
{ field: 'name', header: 'Name' },
{ field: 'email', header: 'Email' },
{ field: 'phnNumber', header: 'Contact No' },
{ field: 'grades[0].grade1', header: 'Grade' },
];
here is my filter:
<div class="col-md-6">
<p-table [columns]="cols" #dt [value]="students" [autoLayout]="true" [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="30" placeholder="Search" (input)="dt.filterGlobal($event.target.value, 'contains')" class="filter">
</div>
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr>
<th class="row-header" *ngFor="let col of columns" [pSortableColumn]="col.field">
{{col.header}}
<p-sortIcon class="" [field]="col.field" ariaLabel="Activate to sort" ariaLabelDesc="Activate to sort in descending order" ariaLabelAsc="Activate to sort in ascending order">
</p-sortIcon>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-student let-columns="columns">
<tr class="center-text">
<td class="row-cell">{{student.name}}</td>
<td class="row-cell">
{{student.email}}
</td>
<td class="row-cell">{{student.grades[0].grade1}}</td>
</tr>
</ng-template>
</p-table>
</div>
If I enter any value present in the grade column,I get empty response. I think there's some issue with using grades[0].grade1 as field.
JSON Structure:
[
{
"name": "Test",
"email": null,
"phnNumber": 1,
"grades": [
{
"grade1": "A",
"grade2": "B"
}
]
}
]
Stackblitz- https://stackblitz.com/edit/angular-dbwfep