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

DataTable with explicit widths causes headers and table cells to misalign #487

Closed
gatapia opened this issue Jun 15, 2016 · 42 comments
Closed
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@gatapia
Copy link
Contributor

gatapia commented Jun 15, 2016

The following table:

<p-dataTable [value]="entities" 
      [lazy]="true" [totalRecords]="totrows" (onLazyLoad)="refresh($event, table)"
      selectionMode="single" (onRowSelect)="edit($event)" 
      sortField="ContactName" [sortOrder]="1"
      [globalFilter]="globalfilter"
      scrollable="true" [scrollHeight]="winheight" #table>    
    <p-column [style]="{'width':'300px'}" field="Company" header="Company" [sortable]="true" [filter]="true"></p-column>
    <p-column field="ContactName" header="Name" [sortable]="true" [filter]="true"></p-column>
    <p-column [style]="{'width':'250px'}" field="Email" header="Email" [sortable]="true" [filter]="true"></p-column>    
    <p-column [style]="{'width':'80px'}" field="IsKeyContact" header="Key Contact" [sortable]="true" [filter]="true">
      <template let-entity="rowData">{{entity.IsKeyContact ? "Yes" : "No"}}</template>
    </p-column>
    <p-column [style]="{'width':'80px'}" field="DateNextFollowUp" header="Follow Up" [sortable]="true" [filter]="true"></p-column>
  </p-dataTable>  

(And any other table that uses explicit widths) causes the following layout issues:

image

I am using the Modena theme, so not sure if it could be this. There is no CSS interfearing with the table (I assume given encapsulation and my brief inspection appears to support this).

@cagataycivici
Copy link
Member

Can you also add width to ContactName column as well.

@gatapia
Copy link
Contributor Author

gatapia commented Jun 20, 2016

Setting the width on ContactName (which I dont want to do as I want it to take remaining space) yields slightly less misaligned results but still not great:

image

@gatapia
Copy link
Contributor Author

gatapia commented Jul 5, 2016

Just to clarify further, this only happens with scrollable=true tables as the header is a separate element from the body.

@billdwhite
Copy link

+1 on this; same problem here

@sylvainpey
Copy link

I have the same problem with relative width (in %). I precise that it appears only if the scrollbar is not displayed (not enought lines). Actually, the scrollbar width is always "reserved" on the right of the header but not in the lines part.

@edangerfield
Copy link

Same problem as well

@tgomas
Copy link

tgomas commented Aug 3, 2016

Also affected by this problem.

@sgomanf
Copy link

sgomanf commented Aug 4, 2016

same problem as well

@github-ek
Copy link

Same problem as well

@cagataycivici
Copy link
Member

cagataycivici commented Sep 13, 2016

Is this related to premium themes or also happens on other themes as well?

@tgomas
Copy link

tgomas commented Sep 14, 2016

Here we encounter it with default theme.
However we don't use last version:
"primeng": "1.0.0-beta.8",
"primeui": "4.1.12"

@erlopezh
Copy link

@cagataycivici

I'm using delta theme,
"primeng": "1.0.0-beta.15",
"primeui": "4.1.15",

This is related with #859, when setting scrolling="true" this issue occurs.

lbamburski added a commit to lbamburski/primeng that referenced this issue Sep 20, 2016
 sortable, columnResizeMode, scrollHeight, scrollWidth and column toggler.

Fixes issues with scrollable:
-DataTable with scroll and few data causes headers and table cells to misalign primefaces#917
-dataTable when scrollable and scrollheight is set - style issue primefaces#465
-Column Reorder and Resize support for Scrollable DataTable primefaces#238
-Maybe: DataTable with explicit widths causes headers and table cells to misalign primefaces#487
-Maybe: Datatable scrollable="true" breaks column template header primefaces#859
lbamburski added a commit to lbamburski/primeng that referenced this issue Sep 21, 2016
   sortable, columnResizeMode, scrollHeight, scrollWidth, header,footer, filter, paginator, selectionMode,
  expandableRows with inner table and column toggler.

  Fixed footer width and partially pagination width when scrollWidth is used

Fixes issues with scrollable:
-DataTable with scroll and few data causes headers and table cells to misalign primefaces#917
-dataTable when scrollable and scrollheight is set - style issue primefaces#465
-Column Reorder and Resize support for Scrollable DataTable primefaces#238
-Maybe: DataTable with explicit widths causes headers and table cells to misalign primefaces#487
-Maybe: Datatable scrollable="true" breaks column template header primefaces#859
lbamburski added a commit to lbamburski/primeng that referenced this issue Sep 21, 2016
   sortable, columnResizeMode, scrollHeight, scrollWidth, header,footer, filter, paginator, selectionMode,
  expandableRows with inner table and column toggler.

  Fixed footer width and partially pagination width when scrollWidth is used

Fixes issues with scrollable:
-DataTable with scroll and few data causes headers and table cells to misalign primefaces#917
-dataTable when scrollable and scrollheight is set - style issue primefaces#465
-Column Reorder and Resize support for Scrollable DataTable primefaces#238
-Maybe: DataTable with explicit widths causes headers and table cells to misalign primefaces#487
-Maybe: Datatable scrollable="true" breaks column template header primefaces#859
lbamburski added a commit to lbamburski/primeng that referenced this issue Sep 21, 2016
   sortable, columnResizeMode, scrollHeight, scrollWidth, header,footer, filter, paginator, selectionMode,
  expandableRows with inner table and column toggler.

  Fixed footer width and partially pagination width when scrollWidth is used

Fixes issues with scrollable:
-DataTable with scroll and few data causes headers and table cells to misalign primefaces#917
-dataTable when scrollable and scrollheight is set - style issue primefaces#465
-Column Reorder and Resize support for Scrollable DataTable primefaces#238
-Maybe: DataTable with explicit widths causes headers and table cells to misalign primefaces#487
-Maybe: Datatable scrollable="true" breaks column template header primefaces#859
@cbelhaffef
Copy link

Hi, same problem as well

I'm using delta theme,
"primeng": "1.0.0-beta.16",
"primeui": "4.1.15",

@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Nov 1, 2016
@cagataycivici cagataycivici added this to the 1.0.0-RC1 milestone Nov 1, 2016
@cagataycivici cagataycivici self-assigned this Nov 1, 2016
@cagataycivici
Copy link
Member

cagataycivici commented Nov 1, 2016

1171 adds improvements to scrollable and I can't replicate this right now, please try with upcoming RC1 and drop a comment if you still experience it then we'll reopen.

@sgomanf
Copy link

sgomanf commented Nov 4, 2016

when I put the resizableColumns="true", columns with explicit witdh, do not respect such wide.

<p-dataTable [value]="resumen" selectionMode="single" [(selection)]="liqselected" (onRowSelect)="onRowSelect()" [rows]="17" [paginator]="true" [pageLinks]="3" [rowsPerPageOptions]="[5,10,30]" [responsive]="true" resizableColumns="true"> <p-column field="codigo" header="CODIGO" [sortable]="true" [style]="{'width':'20%'}" > <template let-col let-prest="rowData" pTemplate type="body"> <span>{{prest[col.field]}}</span> </template> </p-column> <p-column field="nombre" header="NOMBRE" [sortable]="true" [filter]="true" filterMatchMode="contains" ></p-column> <p-column field="saldo" header="MONTO" [sortable]="true" [style]="{'width':'16%'}" > <template let-col let-prest="rowData" pTemplate type="body"> <span style="float:right">{{prest[col.field] | number:'1.2-2'}}</span> </template> </p-column> </p-dataTable>

@gatapia
Copy link
Contributor Author

gatapia commented Nov 23, 2016

This is still an issue in RC6:

image

Cannot reopen issue, should I open a new one?

@simeyla
Copy link

simeyla commented Jan 6, 2017

Why is this closed? It is still a problem even with final release

@simeyla
Copy link

simeyla commented Jan 7, 2017

I think I was mistaken - seems to be fixed

@sliekens
Copy link

sliekens commented Jan 26, 2017

I still have this issue when I use the Bootstrap theme. Column headers are too narrow when scrollable=true.

I find that this issue only occurs when there are not enough rows to fill up the scrollHeight. Since there is no overflow, no scrollbar is shown. The columns stretch to fill the available width. I think this is why the column headers are misaligned.

col

<p-dialog #dialog (onBeforeShow)="onBeforeShow($event)" (onBeforeHide)="onBeforeHide($event)" [header]="title" [(visible)]="visible"
  modal="modal">
  <div style="max-width: 600px;">
    <p-dataTable #dt [value]="values" selectionMode="single" [(selection)]="current" [globalFilter]="filter" scrollable="true"
      scrollHeight="300px">
      <p-header>
        <div class="ui-widget-header">
          <div class="has-feedback">
            <input #filter type="text" class="form-control" placeholder="Search">
            <span class="fa fa-search form-control-feedback"></span>
          </div>
        </div>
      </p-header>
      <p-column field="name" header="Name"></p-column>
      <p-column field="isnType" header="Type"></p-column>
      <p-column field="description" header="Description"></p-column>
    </p-dataTable>
  </div>
  <p-footer>
    <div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
      <button type="button" class="btn btn-primary" (click)="confirm($event)">OK</button>
      <button type="button" class="btn btn-default" (click)="dialog.hide($event);">Cancel</button>
    </div>
  </p-footer>
</p-dialog>

@Gwiny
Copy link

Gwiny commented Jan 27, 2017

Yep. Still an issue on bootsrtrap theme.

@sliekens
Copy link

sliekens commented Jan 27, 2017

Still an issue with the Omega theme as well (but not super noticeable) . And probably with all other themes, because I don't think it's just a styling issue. See my previous comment.

@sliekens
Copy link

sliekens commented Feb 3, 2017

cc @cagataycivici
One reliable fix is to apply the following style:

div.ui-datatable-scrollable-body {
  overflow-y: scroll;
}

This style causes the scrollbar of the scrollable part to always be visible. This prevents the table body from expanding and becoming misaligned with the table headers.

Before
before

After
after

@jibin-tj
Copy link

Thanks for the work-around @StevenLiekens

@uberroot4
Copy link

How did you get this working? I am using .ui-datatable table { table-layout: auto !important; } for auto-width, but mine isn't looking like it should (as you can see on the picture)

bildschirmfoto 2017-05-28 um 11 46 39

@cagataycivici
Copy link
Member

This issue is a bit bloated with different cases, please create a new ticket if issue still persists with 4.0.2.

@uberroot4
Copy link

Is 4.0.2 already out? Have installed 4.0.1 right now.

@cagataycivici
Copy link
Member

cagataycivici commented May 28, 2017

Not yet, will be by tuesday. If you can provide a plunkr right now, that would help so we can review before release. But this was discussed many times, technically table-layout auto is not supported bh scrollable tables so we cant do much about it.

@uberroot4
Copy link

I got the plunkr to work: https://plnkr.co/edit/BQEPSsjz8UJO4bVf8jgi?p=preview

@akashdeepg12
Copy link

screenshot 30
i got solution by below css class

.ui-datatable table
{
table-layout: auto !important;
}

@jibin-tj
Copy link

Hi MrToasty97
Please make sure you have the change in the correct component. Or else put it in style.css global css

@uberroot4
Copy link

I can't check it right now, but as I know I've put it in the gobal styles.css file.

@giscafer
Copy link

giscafer commented Jun 5, 2017

i fix it use the global css

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

div.ui-datatable-scrollable-body {
    overflow-y: scroll;
}

@lanbin45
Copy link

lanbin45 commented Jun 29, 2017

@giscafer This works fine with a maximum client window size; But did you try resize your window size? The mis-aligned issue still exists!

update: It occurs only when you set every column's width with an explicit width. try set seval columns width before they fixed this issue

@bhaidar
Copy link

bhaidar commented Sep 5, 2017

@cagataycivici I am still getting this behavior with 4.1.1
I have a scrollable="true" with fixed column width. Any workaround?

@Rchoudhary-tcs
Copy link

@bhaidar i am not getting any issues with the "LTR" but with "RTL",i am having the same mentioned issue.

@loliparra80
Copy link

I have a similar issue with frozen property and scrollable.
imagen

The frozen columns have 100px of width, but the cell doesn't adjust, if remove the property scrollable, the cells have the same width than the header.

The html is:
<div class="content-section"> <p-dataTable [value]="dataInfo" [scrollable]="true" frozenWidth="400px" unfrozenWidth="600px" [responsive]="true" > <p-column field="name" header="Nombre" [style]="{'width':'200px'}" frozen="true"></p-column> <p-column field="edit" header="Valor" [style]="{'width':'200px'}" frozen="true"></p-column> <p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header" [style]="{'width':'100px'}"> </p-column> </p-dataTable> </div>

@peterstayne
Copy link

We're experiencing this really annoying issue in our app. Are the devs even looking into this? This bug is coming up to a year and a half old.

@bartosz-brodzik
Copy link

I'm struggling with this issue as well... is there gonna be a fix for this?

@AlanParsonsPro
Copy link

It works for me:

.ui-datatable-scrollable-header-box{
margin-right: 15px!important;
}

.ui-datatable-scrollable-body {
overflow-y: scroll !important;
}

.ui-datatable-scrollable-header {
width: 100%;
}

@NoX1337
Copy link

NoX1337 commented Jun 11, 2018

For any future dev who stumbles upon this:
None of the above proposed solutions are solving the problem, at least not when you have multiple pages and multiple different usages of the dataTable element.

@pabl8garcia
Copy link

I experienced this issue too, it is not related with primefaces at all, it is happening when you use a template based on bootstrap i think most of the templates are based on bootstrap, you have to locate the code in bootstrap.css of your template and delete it, in my case i deleted all the css related with glyphicon and the beggining of the file, i dont know if this is the best solution but it worked for me.

@laurieatkinson
Copy link

These styles alone did not solve the problem when the table width became too small. Adding the following finally did the trick for me.

This fixes the column width mismatch problem:
.ui-datatable-scrollable-header table { table-layout: fixed; }

This fixes the problem with the cell contents overlapping the boundaries of the cells. If you do not like the scrollbar and would rather see the content chopped off, use hidden instead of auto.
.ui-datatable-scrollable table td, .ui-datatable-scrollable table th { overflow-x: auto; }

atretyak1985 pushed a commit to Nanitor/primeng that referenced this issue Jul 18, 2020
Use checkboxes to remove issue filters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests