Michael meshaev
Michael meshaev

Reputation: 31

PrimeNg - unable to filter p-table with a parameter

Im using Angular 7 and PrimeNg library.

I have my p-table delaration:

<p-table #tasktable [columns]="displayedColumns" [value]="Tasks" [globalFilterFields]="['name']" [paginator]="true" paginatorPosition="both"
     rows="20" [autoLayout]="true" selectionMode="single" [(selection)]="selectedTask"
     [reorderableColumns]="true" >

Then I have the text input for the global filter:

<input type="text" pInputText size="50" placeholder="Search by Task name" [(ngModel)]="filterFromUrl" (input)="tasktable.filterGlobal($event.target.value, 'contains')" style="width:auto">

So far so good. sometimes i get a parameter inside my URL, to get it I used in my component.ts:

 this.activatedRoute.queryParams.subscribe(params => {
 this.filterFromUrl = params['task'];
});

And now I have the parameter from the URL in my filterFromUrl parameter. My problem:

I cant get the table filter the data by the parameter.

I used [(ngModel)] bind in the ,it doesn't work, I can see the parameter on the search control: enter image description here

But it just doesn't fire the event and the data not filtered.

Upvotes: 0

Views: 3246

Answers (1)

Zak Treister
Zak Treister

Reputation: 26

All you need to do is add the filters into the table (make sure it's in the format the table expects), like so:

@ViewChild("tasktable ") public table: Table;
this.table.filters = {global { value: 'SUBMIT_ORDER', matchMode: 'search' }};

Upvotes: 1

Related Questions