【发布时间】:2019-02-22 17:49:49
【问题描述】:
设计师的 UI 模拟要求我将全局搜索过滤器移到 p 表之外,但我不确定如何执行此操作,或者是否可能?有没有人有做类似事情的经验?我可以严格使用 CSS 样式来做到这一点,同时为不同的屏幕尺寸保持响应式布局吗?
<p-table #dt [value]="tags" [paginator]="true" [rows]="25" [columns]="cols" [resizableColumns]="true" [globalFilterFields]="['vendor']">
<ng-template pTemplate="caption">
<div style="text-align: right; overflow-x: hidden;">
<p class="wrapper"><input type="text" class="search-vendors" pInputText size="50" placeholder="Search Vendors" (input)="dt.filterGlobal($event.target.value, 'contains')" style="width:auto"></p>
</div>
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr>
<th class="{{col.class}}" *ngFor="let col of columns" [pSortableColumn]="col.field">
<p-sortIcon [field]="col.field" *ngIf="col.field == 'fieldThree' || col.field == 'fieldOne' || col.field == 'fieldTwo' "></p-sortIcon>
{{col.header}}
<fa *ngIf="col.field == 'fieldThree' || col.field == 'fieldTwo'" name="info-circle" pTooltip="{{col.tooltip}}" tooltipPosition="right" showDelay="1000" hideDelay="500"></fa>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="cols">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of cols" [ngClass]="{'toggle-tag': col.field==''}">
<div *ngIf="col.field == 'fieldThree'; then vendorRow"></div>
<div *ngIf="col.field == 'fieldTwo' || col.field == 'domain' || col.field == 'fieldThree'; then default"></div>
<ng-template #vendorRow><a (click)="showVendorDetails(rowData)">{{rowData[col.field]}}</a></ng-template>
<ng-template #default>{{rowData[col.field]}}</ng-template>
</td>
</tr>
</ng-template>
</p-table>
【问题讨论】:
-
@Shantanu 的解决方案对我有用,另外我必须在我的 TS 文件中添加
@ViewChild('dt1') dt1: ElementRef;以便dt1可以在p-table之外访问。没有它,它会报错。