0

I have used p-table in angular to display data and used scrollbar with fixed height as "300px"

<p-table [columns]="myCols" [value]="myList" [scrollable]="true" scrollHeight="300px" [responsive]="true">

Here, I am adding rows to the table dynamically which creates scrollbar at runtime and at that time the header becomes misaligned.

enter image description here

So it only has scrollbar on body.

If it has scrollbar at page load then it works fine but has issue when we have scrollbar at runtime.

Here is the stackblitz for the same issue (click 'clone' button to add rows to table dynamically)

5 Answers 5

4

I have fixed it.

Just needed to make use of spread operator (...)

Need to add below line at the end of the clone event.

this.cars = [...this.cars];

Updated stackblitz

Sign up to request clarification or add additional context in comments.

Comments

1

just add margin to align header and body.

.ui-table-scrollable-header-box {
   margin-right: 17px !important;
}

see this example.fore more reference visit this link

4 Comments

It will be misaligned on load.. I don't want any in-line CSS..
This works perfect in my case where I always show the scrollbar. Because if I don't then table does not recalculate scrollbar place when changing screen size or list size
Actually, better to use padding-right.. because sometimes primeng adds padding-right of 17px.. which would add to the margin and cause problems..
For Mac users, where the scrollbar can be hidden by default until scrolling begins, the margin-right and and always showing scrollbar approaches don't quite work
1
::ng-deep .p-datatable-scrollable-header-box {
  margin-right: 17px !important;
}

Add these lines on scss file of your compoenent

Comments

0

I have the same trouble as you but i used [resizableColumns]="true". when the header becomes misaligned I will drag the horizontal bar scroll. It will not be misaligned

Comments

0

Actually it's a bug from primeng end, when scrollable height is added to p-table tag and more no.of rows are there then this issue occurs. When only one row then this issue is not there.

SOLUTION: Instead of using scrollable and scroll height, add height to the parent tav of the table. With the below mentioned approach I am able to resolve alignment issues.

Eg:`

<div style ="max-height:60vh;overflow:auto">
<p-table></p-table>
</div>

`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.