Angular2 primeNG Datatable 过滤来自外部事件的数据
Angular2 primeNG Datatable filter data from external event
我有一个应用程序有一个图形组件,我的想法是当在图形上使用点击时,正确的过滤将发生在另一个组件上,这是一个 primeng 数据 table
为此,我创建了一个事件,我可以在 table 组件上捕获该事件
然后我尝试了两种方法来正确过滤 table
1.using ngModel,根据事件设置值 - 不起作用
<p-column field="result" [filter]="true" [style]="{'overflow':'visible'}" filterMatchMode="equals">
<ng-template let-col let-compliance="rowData" let-ri="rowIndex" pTemplate="body">
<span [ngClass]="{green: compliance.result=='SUCCESS', red: compliance.result=='FAILURE',
orange: compliance.result=='EXCLUDED', grey: compliance.result=='UNCHECKED'}">{{compliance.result}}</span>
</ng-template>
<ng-template pTemplate="filter" let-col>
<p-dropdown [options]="stationResults" [style]="{'width':'100%'}" appendTo="body"
(onChange)="dt.filter($event.value,col.field,col.filterMatchMode)" styleClass="ui-column-filter" [(ngModel)]="selectedResult"></p-dropdown>
</ng-template>
</p-column>
table 未被过滤
后来我尝试了第二种方法
2.add 过滤 属性 到数据 table
this.stationService.upDownGraphEvent.subscribe(upDownEvent => {
this.dt.filter(upDownEvent, 'result', 'equals');
this.selectedResult = upDownEvent;
});
在那种情况下什么也不会发生
我需要在 dt 上调用一个函数来强制它重新检查它的过滤器吗?
更新 ******
我尝试了以下代码但没有成功
this.dt.filter(upDownEvent, 'result', 'equals');
this.dt._filter();
this.dt.updateDataToRender(this.dt.filteredValue);
您可以使用 globalFilter 属性 绑定,如下所示
<input #filterText type="text" placeholder="Search text...">
<p-dataTable [value]="compliance" [globalFilter]="filterText">
this.alertService.alertSwitchGraphEvent.subscribe(switchNameEvent => {
if(this.dt.dataToRender){
this.dt.filter(switchNameEvent, 'switchName', 'equals');
}
});
我创建了一个外部事件,在我订阅它的数据表组件上发出
然后我调用 dt.filter
我有一个应用程序有一个图形组件,我的想法是当在图形上使用点击时,正确的过滤将发生在另一个组件上,这是一个 primeng 数据 table
为此,我创建了一个事件,我可以在 table 组件上捕获该事件
然后我尝试了两种方法来正确过滤 table
1.using ngModel,根据事件设置值 - 不起作用
<p-column field="result" [filter]="true" [style]="{'overflow':'visible'}" filterMatchMode="equals">
<ng-template let-col let-compliance="rowData" let-ri="rowIndex" pTemplate="body">
<span [ngClass]="{green: compliance.result=='SUCCESS', red: compliance.result=='FAILURE',
orange: compliance.result=='EXCLUDED', grey: compliance.result=='UNCHECKED'}">{{compliance.result}}</span>
</ng-template>
<ng-template pTemplate="filter" let-col>
<p-dropdown [options]="stationResults" [style]="{'width':'100%'}" appendTo="body"
(onChange)="dt.filter($event.value,col.field,col.filterMatchMode)" styleClass="ui-column-filter" [(ngModel)]="selectedResult"></p-dropdown>
</ng-template>
</p-column>
table 未被过滤
后来我尝试了第二种方法
2.add 过滤 属性 到数据 table
this.stationService.upDownGraphEvent.subscribe(upDownEvent => {
this.dt.filter(upDownEvent, 'result', 'equals');
this.selectedResult = upDownEvent;
});
在那种情况下什么也不会发生
我需要在 dt 上调用一个函数来强制它重新检查它的过滤器吗?
更新 ******
我尝试了以下代码但没有成功
this.dt.filter(upDownEvent, 'result', 'equals');
this.dt._filter();
this.dt.updateDataToRender(this.dt.filteredValue);
您可以使用 globalFilter 属性 绑定,如下所示
<input #filterText type="text" placeholder="Search text...">
<p-dataTable [value]="compliance" [globalFilter]="filterText">
this.alertService.alertSwitchGraphEvent.subscribe(switchNameEvent => {
if(this.dt.dataToRender){
this.dt.filter(switchNameEvent, 'switchName', 'equals');
}
});
我创建了一个外部事件,在我订阅它的数据表组件上发出 然后我调用 dt.filter