Programmatic p-table filtering

UI Components for Angular
Post Reply
PhilHuhn
Posts: 177
Joined: 19 Sep 2018, 02:52
Location: Ann Arbor, Michigan USA
Contact:

18 Mar 2021, 22:57

I am sharing what I learned about tutbo table filtering via code.

For the HTML I needed # id, I used #team

Code: Select all

<p-table #team id='team-grid' [value]='selectedTeam' dataKey='value'>
  ...
</p-table>
Need to get an in-code reference to the #term via view child. I called my code variable teamTable. Then I applied a filter on teamTable in the ngOnInit methods.

Code: Select all

import { Component, OnInit, ViewChild } from '@angular/core';
...
export class ProjectTeamMemberComponent implements OnInit {
  ...
  @ViewChild('team', { static: true }) teamTable: Table;
  ...
  ngOnInit(): void {
    this.teamTable.filter( 3, 'Action', 'notEquals')
    ...
  }
}
You can replace the filter method on teamTable with a combination of globalFilterFields and filterGlobal method.

Code: Select all

    this.teamTable.globalFilterFields = ['Action'];
    this.teamTable.filterGlobal( 3, 'notEquals' );

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 17 guests