我使用Angular 7和PrimeNg库。
我有我的p-table声明:
<p-table #tasktable [columns]="displayedColumns" [value]="Tasks" [globalFilterFields]="['name']" [paginator]="true" paginatorPosition="both"
rows="20" [autoLayout]="true" selectionMode="single" [(selection)]="selectedTask"
[reorderableColumns]="true" >
然后我输入了全局过滤器的文本:
<input type="text" pInputText size="50" placeholder="Search by Task name" [(ngModel)]="filterFromUrl" (input)="tasktable.filterGlobal($event.target.value, 'contains')" style="width:auto">
到目前为止,一切都很好。 有时我会在URL中获取一个参数 我在我的component.ts中使用了:
this.activatedRoute.queryParams.subscribe(params => {
this.filterFromUrl = params['task'];
});
现在我在 filterFromUrl 参数中有了URL中的参数。 我的问题:
我无法通过参数过滤表。
我在[[ngModel)]绑定中使用了,它不起作用,
我可以在搜索控件上看到该参数:
但是它不会触发事件,并且不会过滤数据。
答案 0 :(得分:0)
您需要做的就是将过滤器添加到表中(确保其格式符合表所期望的格式),如下所示:
@ViewChild("tasktable ") public table: Table;
this.table.filters = {global { value: 'SUBMIT_ORDER', matchMode: 'search' }};