I need to add an ID to the table
, I'm using PrimeNG so I don't have this table tag in my component, only the p-table
.
I tried [id]
and [attr.id]
but without success.
Any other suggestions please ?
You can do this way:
Mark p-table with an id for accessing his reference in ngAfterViewInit method:
<p-table #pTableId></p-table>
Then in Component.ts :
import {Table} from 'primeng/table';
export class MyComponent {
@ViewChild('pTableId') pTableRef: Table;
ngAfterViewInit() {
const table = this.pTableRef.el.nativeElement.querySelector('table');
table.setAttribute('id', 'myTableId');
}
}