Search code examples
angulartypescriptprimengprimeng-datatable

PrimeNG dataView Search Box Setup Issue


I am using p-dataView with Angular 5 and getting error

Cannot read property 'split' of undefined at DataView.filter

I read the documentation and could not find anything to resolve my issue. Also there no code needed in typescript side... so i just have this html code Note the search should be pointing to the cheackbox (app_name)

  <p-dataView [value]="iApps" #dv [paginator]="true" [rows]="20"  paginatorPosition="both">
<p-header> 
      <input type="search" pInputText placeholder="Search" (keyup)="dv.filter($event.target.value)">
</p-header>

                  <ng-template let-apps let-rowIndexValue="rowIndex" pTemplate="listItem">

                           <input type="checkbox" (click)="toggleSelectedApp($event,rowIndexValue)" id="defaultAppID" name="defaultApps" style="margin-right:5px;margin-bottom:5px;margin-left:5px; margin-top:5px" [value]='apps.app_id'> {{apps.app_name}}

                                                    <select name="role" class="dropdown"  style="width:85%" (ngModelChange)="selectedDefaultAppRole($event,rowIndexValue)" [(ngModel)]="apps.seletedAppRoleID">
                                                        <option class="dropdown-item" value="-1" selected>Select</option>
                                                        <option class="dropdown-item" *ngFor='let role of apps.roles' [ngValue]="role.app_role_id">
                                                            {{role.app_role_name}}
                                                        </option>
                                                    </select>

                                    </ng-template>

                                </p-dataView>

Solution

  • If you are using filter. I think you should use filterBy property as well.

    <p-dataView #dv [value]="cars" filterBy="brand">
    

    As per the documentation Filtering is implemented by defining the filterBy property and calling the filter function of the component. I am suspecting because of this you are getting error 'split' of undefined at DataView.filter.