【发布时间】:2021-12-18 08:19:49
【问题描述】:
我想在更改下拉值时显示表格数据。例如,如果我将排名下拉值更改为“A”,那么表格应该只显示排名 A 数据。目前,我正在使用角度启动材料。在我得到问题表数据加倍错误之前,在我使用“let-pjt”解决该问题之后,我无法使用“ng2 搜索过滤器”选项。
component.html
<div class="col">
<p-dropdown [options]="rankArr" name="rank" [(ngModel)]="project.rank" optionLabel="rank" optionValue="rank" [style]="{'width':'100%'}" placeholder="{{'placeholder.rank' | translate}}"></p-dropdown>
</div>
<div class="table" style="margin-right: 15px; overflow-x:auto;">
<p-table [value]="projects" styleClass="p-datatable-gridlines" responsiveLayout="scroll" scrollHeight="17.8vw">
<ng-template pTemplate="header">
<tr>
<th style="text-align: center;" translate>itemlist.customer <br> itemlist.name</th>
<th style="text-align: center;" translate>itemlist.project <br> itemlist.name</th>
<th style="text-align: center;" translate>itemlist.business <br> itemlist.divition</th>
<th style="text-align: center;" translate>itemlist.rank</th>
<th style="text-align: center;" translate>itemlist.order <br> itemlist.amount</th>
<th style="text-align: center;" translate>itemlist.customer <br> itemlist.area</th>
<th style="text-align: center;" translate>itemlist.sales <br> itemlist.incharge</th>
<th style="text-align: center;" translate>itemlist.incharge<br> itemlist.pm</th>
<th style="text-align: center;" translate>itemlist.incharge<br> itemlist.pl</th>
<th style="text-align: center;" translate>itemlist.update <br> itemlist.date</th>
<th style="text-align: center;" translate>itemlist.updater</th>
<th style="text-align: center;" translate>itemlist.process</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-pjt>
<tr>
<td style="text-align: center;">{{ pjt.customer_name }}</td>
<td style="text-align: center; width: 15vw;">{{ pjt.project_name_jp }}</td>
<td style="text-align: center;">{{ pjt.business_divition }}</td>
<td style="text-align: center;">{{ pjt.rank }}</td>
<td style="text-align: center;">{{ pjt.order_amount }}</td>
<td style="text-align: center;">{{ pjt.customer_area }}</td>
<td style="text-align: center;">{{ pjt.sales_in_charge }}</td>
<td style="text-align: center;">{{ pjt.in_charge_pm }}</td>
<td style="text-align: center;">{{ pjt.in_charge_pl }}</td>
<td style="text-align: center;">{{ pjt.updated_at }}</td>
<td style="text-align: center;">{{ pjt.updated_by }}</td>
<td style="text-align: center; width: 70vw;">
<button pButton pRipple routerLink="item-register/{{ pjt.id }}" type="button" class="p-button-outlined p-button-secondary" translate>itemlist.actual <br> itemlist.input</button>
<button pButton pRipple type="button" translate="itemlist.duplicate" class="p-button-outlined"></button>
<button pButton pRipple (click)="deleteProject(pjt.id)" type="button" translate="itemlist.delete" class="p-button-outlined p-button-danger"></button>
</td>
</tr>
</ng-template>
</p-table>
在我可以使用以下代码进行搜索之前,表格数据翻了一番。
<ng-template pTemplate="body" >
<tr *ngFor="let pjt of projects | filter:project.rank | filter:project.business_divition | filter:project.in_charge_area
| filter:project.customer_area | filter:project.in_charge_pm | filter:project.in_charge_pl | filter:project.sales_in_charge
| filter:project.updated_by | filter:project.customer_name">
<td style="text-align: center;">{{ pjt.customer_name }}</td>
<td style="text-align: center; width: 15vw;">{{ pjt.project_name_jp }}</td>
<td style="text-align: center;">{{ pjt.business_divition }}</td>
<td style="text-align: center;">{{ pjt.rank }}</td>
<td style="text-align: center;">{{ pjt.order_amount }}</td>
<td style="text-align: center;">{{ pjt.customer_area }}</td>
<td style="text-align: center;">{{ pjt.sales_in_charge }}</td>
<td style="text-align: center;">{{ pjt.in_charge_pm }}</td>
<td style="text-align: center;">{{ pjt.in_charge_pl }}</td>
<td style="text-align: center;">{{ pjt.updated_at }}</td>
<td style="text-align: center;">{{ pjt.updated_by }}</td>
<td style="text-align: center; width: 70vw;">
<button pButton pRipple routerLink="item-register/{{ pjt.id }}" type="button" class="p-button-outlined p-button-secondary" translate>itemlist.actual <br> itemlist.input</button>
<button pButton pRipple type="button" translate="itemlist.duplicate" class="p-button-outlined"></button>
<button pButton pRipple (click)="deleteProject(pjt.id)" type="button" translate="itemlist.delete" class="p-button-outlined p-button-danger"></button>
</td>
</tr>
</ng-template>
【问题讨论】:
-
在我看来,使用 ng2-search-filter 管道将过滤所有包含解析值的列。您想要的答案是在指定列中搜索值(例如:排名值仅搜索排名列)还是搜索所有列的值(排名值所以搜索所有列)?
-
感谢您的评论@Yong_Shun 实际上,我想使用三个下拉列表过滤表数据。下拉菜单不在表格中,但在同一页面上。
-
如果您对这些多个过滤管道感兴趣,请将这些管道移至
<p-table [value]="projects | filter:project.rank | filter:project.business_divition | filter:project.in_charge_area | filter:project.customer_area | filter:project.in_charge_pm | filter:project.in_charge_pl | filter:project.sales_in_charge | filter:project.updated_by | filter:project.customer_name">。 -
看到这个demo
-
但它不能正常工作。只有B级工作。 @永顺
标签: html angular typescript primeng