Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p-Table: resizing a scrollable table resizes the expanded row #10609

Closed
Quacck opened this issue Sep 10, 2021 · 3 comments
Closed

p-Table: resizing a scrollable table resizes the expanded row #10609

Quacck opened this issue Sep 10, 2021 · 3 comments
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@Quacck
Copy link

Quacck commented Sep 10, 2021

I'm submitting a ... (check one with "x")

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)
https://stackblitz.com/edit/primeng-tablerowexpansion-demo-te1jhb?file=src%2Fapp%2Fapp.component.html

Current behavior
Resizing a column in a table that has an expandable row, resizes the expanded row to the width of the first column of the parent-table.

Expected behavior
The expanded row should have the width of the whole table.

Minimal reproduction of the problem with instructions

  • Go to the above stackblitz
  • expand the first row. Notice how the width is still the same as the whole table.
  • Also notice the column widths of the child-table
  • Grab the resizer from 'Name', drag it to the left of 'Price'
  • The expand row is now wrongly the size of the first column
  • Scroll through the expanded row. The widths of the child-table's columns are also wrongly adjusted (they match the widths of the parent-table!)

What is the motivation / use case for changing the behavior?
We want to resize tables that have expanded rows. Resizing the parent table should not bleed into the child table.

Please tell us about your environment:

Angular version: 12

PrimeNG version: 12.1.0

Browser: Chrome Version 92.0.4515.159

Language: TypeScript

Node (for AoT issues): node --version = v14.15.4

@MuhSchaf
Copy link

MuhSchaf commented Oct 25, 2021

I have this problem too.
I found out, that on resize, the <th> and <td> -elements get an id: #pr_id_1.
The expanded row tables recieve the same id's. Therefore i assume that the resize-event uses the assigned id's.

I want to add, that you can slightly improve this behaviour, if you add flex: 1 1 0 !important; as styling to your expanded row <td>.

<td colspan="7" style="background-color: red; color: black; overflow:scroll" style="flex: 1 1 0 !important">

@MuhSchaf
Copy link

So, after some research, i found the culprit.

Inside the table.ts - file on line 1923 and 1924 the column-widths get set:

let headers = DomHandler.find(this.containerViewChild.nativeElement, '.p-datatable-thead > tr > th');
headers.forEach(header => widths.push(DomHandler.getOuterWidth(header)));

The DomHandler find - function searches inside the parent table for ALL tableHeader.
In @Quacck 's case (and in mine too), the DomHandler finds the tableheader for the parent and child table.
Therefore he adds the #pr_id_1 to every tableCell and changes therefore every width of the nth-childs equivalent to this id.

Solution Idea:

const tableHead = DomHandler.findSingle(this.containerViewChild.nativeElement, '.p-datatable-thead');
let headers = DomHandler.find(tableHead, 'tr > th');

In this case, the DomHandler will only find the header for the parent table.

Be blessed

@yigitfindikli yigitfindikli self-assigned this Oct 30, 2021
@yigitfindikli yigitfindikli added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Oct 30, 2021
@yigitfindikli yigitfindikli added this to the 12.2.2 milestone Oct 30, 2021
@yigitfindikli yigitfindikli added Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Nov 2, 2021
@sandipchitale
Copy link
Contributor

sandipchitale commented Dec 2, 2022

The rule like this:

#pr_id_1-table > .p-datatable-tbody > tr > td:nth-child(2)

seems to make an assumption that all rows of header, body and rowexpansion templates have same column structure. But this may not be true for the rowexpansion template. For expansion rows we typically use:

<tr}>
  <td style="width: 3rem"><!-- whitespace in first column below the expansion icon --></td>
  <td colspan="N-1">
  ... expansion data which itself could be a table.
  </td>
<tr>

This needs to be fixed differently. At minimum rule should be (note the :not([colspan])):

#pr_id_1-table > .p-datatable-tbody > tr > td:not([colspan]):nth-child(2)

Hope the above makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

No branches or pull requests

4 participants