0

I want to click on a menu item, navigate to a different page that has a PrimeNG p-dataTable, and scroll to the item on the p-dataTable that the link corresponds to. (PrimeNG version being used is 4.0.3)

With this code, I am able to navigate to the new page correctly on both instances, with or without the item id,

http://localhost:4200/products?warehouseId=29 and http://localhost:4200/products/14?warehouseId=29

, but how do I get the table to scroll to the item ? Or does this particular PrimeNG p-datatable not provide such functionality?

So for example my menu item has something like

<div *ngFor="let product of products">                          
    <li>
       <div>
          <a [routerLink]="['/products', product.id]" [queryParams]="{ warehouseid: warehouse.id }">{{product.description}}</a>
       </div>
    </li>
</div>
<li>
    <a [routerLink]="['/products']" [queryParams]="{ warehouseid: warehouse.id }">View All Products</a>
</li>

And p-dataTable has

<p-dataTable [value]="products" dataKey="id" #dt>
    <p-column field="id" [style]="{ 'width': '0%' }" [hidden]="true">
       <ng-template pTemplate="body" let-product="rowData">
          <div>{{product.id}}</div>
       </ng-template>
    </p-column>                  
    <p-column field="description" [style]="{ 'width': '50%' }" [sortable]="true">
       <ng-template pTemplate="header">
          <span>Description</span>
       </ng-template>
       <ng-template pTemplate="body" let-product="rowData">
          <div>{{product.description}}</div>
       </ng-template>
    </p-column>        
</p-dataTable>

Also, just in case, I am not allowed to use jQuery in this project.

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
snowleopard
  • 781
  • 3
  • 13
  • 36
  • Have you tried to use [scrollIntoView](https://www.w3schools.com/jsref/met_element_scrollintoview.asp) method ? – Antikhippe Jul 06 '18 at 06:21
  • Apparently scrollIntoView is only available to primefaces datatable, not to the primeng datatable. – snowleopard Jul 11 '18 at 15:14
  • It's not linked to PrimeNG or Angular, check this link : https://www.w3schools.com/jsref/met_element_scrollintoview.asp – Antikhippe Jul 11 '18 at 16:13

0 Answers0