我正在与 PrimeNg 合作来过滤我的 p 表上的列。
我p-multiSelect嵌套在一个p-ColumnFilter.
过滤按预期工作,但是 中的搜索功能p-multiSelect始终返回no results found.
这是我的模板代码:
<th class="table-header-primary" [ngStyle]="{'width':'200px'}" [pSortableColumn]="'docCategory'">Type
<p-columnFilter class="p-ml-auto" type="text" field="doctypeLabel" matchMode="in" display="menu" [showApplyButton]="false" [showMatchModes]="false" [showOperator]="false" [showAddButton]="false">
<ng-template pTemplate="filter" let-value let-filter="filterCallback">
<p-multiSelect [(ngModel)]="doctypeLabel" [options]="_doctypeLabelList" placeholder="Select" (onChange)="filter($event.value)">
</p-multiSelect>
</ng-template>
</p-columnFilter></th>
Run Code Online (Sandbox Code Playgroud)
这是我的相关打字稿文件:
_doctypeLabelList:any[]=[];
doctypeLabel:any="";
constructor() {
}
Run Code Online (Sandbox Code Playgroud)
我附上了两张照片,希望能澄清我的问题。
我的多选下拉列表,填充了来自以下位置的适当字段_doctypeLabelList:

一旦我尝试在下拉列表中搜索匹配的值:

我尝试过一种方式绑定doctypeLabel,但没有成功。在选项下拉列表中显示_doctypeLabelList良好,只是在输入栏中搜索时总是会立即产生no results found. 我真的不知道还能尝试什么。我一遍又一遍地查看 PrimeNg 文档,但没有找到任何结果。文档中的示例是一个相当简单的用例,所以我想知道这是否p-columnFilter会以某种方式影响我的p-multiSelect.
有同样烦人的问题,最初我使用string[]作为选项的输入,这给了我同样的问题。
通过将字符串数组转换为SelectItem[]数组并将其用作 [options] 输入来修复此问题。
public items: string[]; // <-- OLD INPUT
// NEW INPUT: return items as SelectItem
get itemsAsSelectItems(): SelectItem [] {
return this.items.map((item) => ({ label: item, value: item } as SelectItem));
}
Run Code Online (Sandbox Code Playgroud)
模板实现:
<p-multiSelect [options]="itemsAsSelectItems" ... ></p-multiSelect>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13006 次 |
| 最近记录: |