PrimeNg p 表的类型定义

azu*_*net 4 typescript primeng angular

我有一个 PrimeNg p 表,我需要根据用户设置默认过滤,所以我想我需要使用类似“ let table = document.getElementById("dt");Where table is 无论 primeNg 的表对象是什么”之类的东西,这样我就可以table.filter(filterDefault, col.field, 'in');像 html 中所做的那样进行调用。我只是不知道如何将#dt我的打字稿作为正确的类型进行转换,或者也许有一种更简单的方法可以使用 p 表已有的内容来完成此操作。

         <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>
Run Code Online (Sandbox Code Playgroud)

Tim*_*Tim 8

在你的 TS 文件中使用@Viewchild :

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

    @ViewChild('dt') table: Table;
Run Code Online (Sandbox Code Playgroud)

然后你可以打电话

 this.table.filter()
Run Code Online (Sandbox Code Playgroud)