Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

536
Visualizações
Angular2 primeNG Datatable filter data from external event

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);
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can use the globalFilter property binding as below

<input #filterText type="text" placeholder="Search text...">
<p-dataTable [value]="compliance" [globalFilter]="filterText">
over 4 years ago · Santiago Trujillo Relatório

0

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

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda