Get row count after Filter search

UI Components for Angular
Post Reply
rendy.rex
Posts: 1
Joined: 16 Oct 2018, 17:23

16 Oct 2018, 18:17

Good day,i have a similar table as from the link : https://www.primefaces.org/primeng/#/table/filter where i can filter the table with any column.

I want to count the current number of rows after filtering the table,i believe this can be done with a event but i have no clue where to start,can you kindly help with a guideline on how i can achieve this.

PhilHuhn
Posts: 177
Joined: 19 Sep 2018, 02:52
Location: Ann Arbor, Michigan USA
Contact:

18 Oct 2018, 17:12

From the PrimeNG sample code, the slider has an on change event that calls with the #dt table reference:

Code: Select all

<p-table #dt [columns]="cols" [value]="cars" [paginator]="true" [rows]="10">
    ...
    <ng-template pTemplate="header" let-columns>
       ...
        <tr>
            <th *ngFor="let col of columns" [ngSwitch]="col.field">
                ...
                    <p-slider [style]="{'width':'100%','margin-top':'8px'}" [(ngModel)]="yearFilter" [min]="1970" [max]="2010" (onChange)="onYearChange($event, dt)"></p-slider>
                ...
            </th>
        </tr>
    </ng-template>
    ...
</p-table>
The function 'onYearChange' is called on year change:

Code: Select all

export class TableFilterDemo implements OnInit {
    ...
    onYearChange(event, dt) {
        if (this.yearTimeout) {
            clearTimeout(this.yearTimeout);
        }

        this.yearTimeout = setTimeout(() => {
            dt.filter(event.value, 'year', 'gt');
        }, 250);
    }
}
Alternately, one can attach to #dt via ViewChild:

Code: Select all

import { Component, ..., ViewChild, ... } from '@angular/core';
...
import { Table, TableModule } from 'primeng/components/table/table';
...
export class ... {
	...
	@ViewChild( 'dt' ) dt: Table;
	...
		this.dt.filterGlobal( ..., 'contains' );
	...

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests