2
votes

I have an application that has one graph component and my idea is that when use clicks on a graph the correct filtering will occur on the other component which is an primeng data table

for that end i've created an event and i can capture the event on the table component

then i tried two approaches to filter the table correctly

1.using ngModel, setting the value based on the event - not working

<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 is not being filtered

later i tried a second approach

2.add filters property to the datatable

this.stationService.upDownGraphEvent.subscribe(upDownEvent => {
      this.dt.filter(upDownEvent, 'result', 'equals');
      this.selectedResult = upDownEvent;
    });

in that case nothing happens

is there a function i need to call on the dt to force it to recheck its filters?

UPDATE ******

I've tried the following code but without success

this.dt.filter(upDownEvent, 'result', 'equals');
      this.dt._filter();
      this.dt.updateDataToRender(this.dt.filteredValue);
2
I have the same issue. Did you found any solution? - Asterius
posted a solution that im using - naoru

2 Answers

0
votes

You can use the globalFilter property binding as below

<input #filterText type="text" placeholder="Search text...">
<p-dataTable [value]="compliance" [globalFilter]="filterText">
0
votes
this.alertService.alertSwitchGraphEvent.subscribe(switchNameEvent => {
      if(this.dt.dataToRender){
        this.dt.filter(switchNameEvent, 'switchName', 'equals');
      }
    });

I've created an external event that emitted, on the datatable component i subscribe to it and then i call the dt.filter