2

Hi I am using angular 8 and PrimeNG version 6. I want to reset the p-table on button click. I am getting error see below.

    import { Table } from 'primeng/table';

        @ViewChild('dt', { static: false }) Component
        table: Table;
        onClick() {

            this.table.reset();
        }

Error Getting after click :

KpientryComponent.html:146 ERROR TypeError: Cannot read property 'reset' of undefined
    at KpientryComponent.onClick (kpientry.component.ts:145)
Antikhippe
  • 6,316
  • 2
  • 28
  • 43
Rahul Mangal
  • 21
  • 1
  • 4

1 Answers1

0

The Table component in not declared correctly. The @ViewChild('dt') is the Table variable. Preform the reset on dt

import { Table } from "primeng/table";

@Component({
  selector: "app-table",
  templateUrl: "./app-table.component.html",
  styleUrls: ["./app-table.component.css"]
})
export class AppTableComponent {
  @ViewChild("dt", { static: false }) public dt: Table;

  onClick() {
    this.dt.reset();
  }
}

Binary Alchemist
  • 1,600
  • 1
  • 13
  • 28