-1

As a continuation to this question:

angular primeng p-table pagination not working

I need a way to trigger html method from TypeScript. In the example in the question I need a way to run

table.reset()

from my TypeScript. The reason for that is that my current component is called whenever a different link is used (a menu) and each time the displayed is changed. I have learned that in order to init the paginator fields, I need to use the reset() method - BUT my problem is how to trigger this change.

For the first time there is no problem because I added it to the GET button I have but when the menu is used again I don't want to press the get button (I am triggering changes in the display using

ngAfterContentChecked()
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
RMagen
  • 612
  • 2
  • 9
  • 23
  • 3
    Get a reference to the table using a `ViewChild`, and you can call the function using that – user184994 Oct 21 '18 at 13:16
  • thank you I am new to angular never new about this option I have read about it and using the help of @dirtyMind it is now working for me – RMagen Oct 22 '18 at 06:32

1 Answers1

1

Suppose this is your table:

<p-table #tt [value]="testdata" class="test-data" [lazy]="true"
         (onLazyLoad)="loadDataLazily($event)"
            [paginator]="true" [rows]="3" [totalRecords]="totalRecords">

To reset it in component file : use it like below:

import { Table } from '../../../../node_modules/primeng/components/table/table';
    export class TableComponent{
     @ViewChild('tt') tt: Table;
     resetTable(){
      this.tt.reset();
     }
}
DirtyMind
  • 2,353
  • 2
  • 22
  • 43