[p-table] custom filter

UI Components for Angular
Post Reply
Fearlezz90
Posts: 2
Joined: 08 Aug 2019, 16:10

19 Aug 2019, 15:25

Hi,
i have created a custom filterCostraints for p-table like this

Code: Select all

  @ViewChild('dt') dtTable;

  ngOnInit() {

this.dtTable.filterConstraints.currencyAmount = (value, filter: any): boolean => {
      if (filter === undefined || filter === null || filter === '') {
        return true;
      }
      if (value === undefined || value === null) {
        return false;
      }
      return (<string>value.toFixed(2)).startsWith((<string>filter).replace(',', '.'));
    };
    }
    
and i added it in every ngOnInit of any component where i need to use it.

there is any way to create this filter globally like "startsWith", "contains" .... to avoid the insert inside every ngOnInit?

yigitfindikli
Posts: 449
Joined: 08 Aug 2018, 14:09

03 Sep 2019, 10:27

Fearlezz90 wrote:
19 Aug 2019, 15:25
Hi,
i have created a custom filterCostraints for p-table like this

Code: Select all

  @ViewChild('dt') dtTable;

  ngOnInit() {

this.dtTable.filterConstraints.currencyAmount = (value, filter: any): boolean => {
      if (filter === undefined || filter === null || filter === '') {
        return true;
      }
      if (value === undefined || value === null) {
        return false;
      }
      return (<string>value.toFixed(2)).startsWith((<string>filter).replace(',', '.'));
    };
    }
    
and i added it in every ngOnInit of any component where i need to use it.

there is any way to create this filter globally like "startsWith", "contains" .... to avoid the insert inside every ngOnInit?
Hi,
You can use currencyAmount function in your component.
Best Regards.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 16 guests