PrimeNg p-table的类型定义

问题描述 投票:0回答:1

我有一个PrimeNg p表,我需要根据用户设置默认过滤,所以我想我需要使用类似let table = document.getElementById("dt");的地方其中table是primeNg的表对象,所以我可以像在html中那样调用table.filter(filterDefault, col.field, 'in');。我只是不知道如何将#dt作为正确的类型得到我的打字稿,或者使用p-table已有的更简单的方法来做到这一点。

         <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>
angular typescript primeng
1个回答
1
投票

在TS文件中使用@Viewchild

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

    @ViewChild('dt') table: Table;

然后你可以打电话

 this.table.filter()
© www.soinside.com 2019 - 2024. All rights reserved.