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

213
Visualizações
Is there a way to set multiple custom column filters in a PrimeNG table?

I've managed to add only one custom filter in my table.

View:

<th colspan="2">
    <p-columnFilter field="campaigns" [showMenu]="false" [matchMode]="'customFilter1'">
         <ng-template pTemplate="filter" let-value let-filter="filterCallback">
            <p-dropdown [options]="mainFilterListOfCountries" [resetFilterOnHide]="true"
              [(ngModel)]="selectedCountryToFilter" (onChange)="filter($event.value)">
                  //More code
            </p-dropdown>
         </ng-template>
    </p-columnFilter>
</th>

<th  colspan="2" >
   <p-columnFilter field="affiliateTypes" [showMenu]="false" [matchMode]="'customFilter2'">
        <ng-template pTemplate="filter" let-value let-filter="filterCallback">
               <p-selectButton [options]="activeOrAllAffiliatesMainFilterOptions"
                      [(ngModel)]="selectedStatus" (onChange)="filter($event.value)"
                                optionLabel="label">
   </p-selectButton>
      </ng-template>
  </p-columnFilter>
</th>

Component:

ngOnInit(): void {

this.filterService.register('customFilter1', (value, filter): boolean => {
  if (filter.option === "all") {
    return true;
  }
  if (value && value.length) {
    return true;
  } else {
    return false;
  }

});}

I need to add a few more custom filters.

Maybe something like this(?):

Component:

  ngOnInit(): void {

this.filterService.register([customFilter1 , customFilter2 ,....], (value, filter): boolean => {

  if(customFilter1){
    if (filter.option === "all") {
      return true;
    }
    if (value && value.length) {
      return true;
    } else {
      return false;
    }
  }
  else if(customFilter2){
    if (value && value.length) {
      return true;
    } else {
      return false;
    }
  }
});

}

I'm guessing that the thing is that you can't register multiple times to the same service in the same component...

I mean there probably is a way, it's just not to my knowledge...

  • Angular : 11
  • PrimeNG: 11.4.4
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This is old but... Maybe this is obvious or I don't understand your issue, but why don't you just register them both like

ngOnInit(): void {
    
    this.filterService.register('customFilter1', (value, filter): boolean => {
      //customFilter1 stuff
    });
    
    this.filterService.register('customFilter2', (value, filter): boolean => {
      //customFilter2 stuff
    });
}

Because you are essentially putting 2 callbacks in a map by key name (the customFilter1/2 bit as the key). The value being sent in is configured from the table markup and which column you selected to put the filter on.

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