Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type definition for PrimeNg p-table

I have a PrimeNg p-table that I need to setup default filtering based on the user so I think I need to use something like let table = document.getElementById("dt"); Where table is whatever primeNg's table object is so I can call table.filter(filterDefault, col.field, 'in'); as is done in the html. I just don't know how to get the #dt over to my typescript as the correct type or maybe there is an easier way to do this using what the p-table already has.

         <p-table #dt>
                ...
                  <tr>
                    <th *ngFor="let col of columns" [ngSwitch]="col.filterType" class=showOverflow pResizableColumn>
                      ...

                      <p-multiSelect *ngSwitchCase="'DropDown'" [options]="masterSearchTypes" defaultLabel="All"
                        [(ngModel)]="filterDefault" (onChange)="dt.filter($event.value, col.field, 'in' )"></p-multiSelect>

                    </th>
                  </tr>
                  ...
              </p-table>
like image 605
azulBonnet Avatar asked Sep 21 '25 10:09

azulBonnet


1 Answers

Use @Viewchild in your TS file :

import { ViewChild } from '@angular/core';    
import { Table } from 'primeng/table';    

    @ViewChild('dt') table: Table;

Then you can call

 this.table.filter()
like image 139
Tim Avatar answered Sep 23 '25 00:09

Tim