How to GlobalFilter for selected Columns only?

391 Views Asked by At

I want to use GlobalFilter of PrimeNG on my p-datatable on only employeeid and name columns... I have 5 other columns also in this table but I dont want to use globalfilter for them, and also the requirement is only globalfilter, otherwise I could have done column filter. How can I do it ?

I searched about it, it is possible in p-table, but I want to do it with p-datatable.

Here is my code :

<div class="md-input-wrapper">
 <input #gb type="text" pInputText size="50" class="md-form-control md-valid"
 placeholder="Global Filter" />
 </div>

<p-dataTable [globalFilter]="gb" [value]="employees" class="table table-hover"
 [paginator]="true" [rows]="10" [pageLinks]="3">
 <p-column field="employeeid" header="Emp ID" [sortable]="true"></p-column>
 <p-column field="name" header="Name" [sortable]="true" ></p-column>
1

There are 1 best solutions below

0
fastAsTortoise On

you can use use p-table I don't they have datatables anymore. PrimeNg table has lots of options and very good documentation. Hope this will help. I have not tried this code though. You can also change the match mode to any of the following:

"startsWith", "contains", "endsWith", "equals", "notEquals", "in", "lt", "lte", "gt" and "gte"

<div class="md-input-wrapper">
 <input type="text" pInputText size="50" class="md-form-control md-valid"
 placeholder="Global Filter" (input)="dt.filterGlobal($event.target.value, 'contains')" />
 </div>

<p-table #dt [columns]="cols" [value]="employees" [globalFilterFields]="['name','emplyoeeId']" class="table table-hover"
 [paginator]="true" [rows]="10" [pageLinks]="3"></p-table>