Scrollbar causes misalignment of table in Microsoft Edge - html

I'm setting up a simple table at work using Angular and have come across a problem. After I froze a couple of the columns. Whenever I scroll all the way to the bottom, the frozen columns' rows are misaligned with the scrolling columns' rows. This problem only shows up when using Edge and Firefox but it's necessary to use them. However, in Chrome the rows are aligned.
I've tried applying padding and margins to the columns' elements but it doesn't seem to work. I should also mention that I'm using the primeNg data table components to set up the tables. Here's the HTML code. Colgroup is the group of columns that scroll and frozenName is the group of columns that are frozen.
<p-table [columns]="scrollableCols" [value]="data"
[scrollable]="true" [frozenColumns] = "frozenName" [frozenValue] =
"frozendata" scrollHeight="300px" frozenWidth='400px'
[style] = "{width:'1000px'}" >
<ng-template pTemplate="colgroup" let-columns>
<colgroup>
<col *ngFor="let col of columns" style="width:200px" >
</colgroup>
</ng-template>
<ng-template pTemplate="header" let-columns >
<tr>
<th *ngFor= "let col of columns" >
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="frozenrows" let-rowData let-columns="columns">
<tr>
<td *ngFor= "let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns" >
<tr>
<td *ngFor= "let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
No errors occur when applying padding and margins but they separate the rows from the header which is not what I want.

I don't think this is a problem with your code it's just that some css doesn't work in Microsoft Edge, because there is still a lot of work to do on it.
I also have the same problem with my website.
But you could try something like this:
https://www.w3schools.com/howto/howto_css_four_columns.asp

Related

PrimeNG table fit in the container

I have an angular component which shows a map or a primeNG table depending on a variable. This component is prepared to act as a child component and be used inside other components. The map fits on the container it is set, but the table exceeds the height of the container if it has too many rows.
I want to force the table fitting the container, It would be nice if it auto-selects the number of rows per page in the paginator depending on the space in the container, but I would also be fine with some kind of scrollbar.
I have tried the classic scrollable='true', scrollheight and that stuff, but they do not work for me.
Edit: Adding the table code:
<div><p-table #dt
[value]="listaMapa()"
[columns]="mostrarColumnas"
(sortFunction)="customSort($event)"
[customSort]="true"
[paginator]="true"
[showCurrentPageReport]="true" [rows]="10"
[scrollable]="true"
[scrollHeight]="'100%'"
currentPageReportTemplate="{first} - {last} de {totalRecords}" [rowsPerPageOptions]="[10,25,50]">
<ng-template pTemplate="header" let-columns>
<tr>
<th [pSortableColumn]="'matricula'">Matrícula
<p-sortIcon [field]="'matricula'"></p-sortIcon>
</th>
<th>Latitud
</th>
<th >Longitud
</th>
<th>Ubicación</th>
<th [pSortableColumn]="'zona'">Zona
<p-sortIcon [field]="'zona'" ></p-sortIcon>
</th>
<th [pSortableColumn]="'fecha'">Fecha de registro
<p-sortIcon [field]="'fecha'" ></p-sortIcon>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-posiciones>
<tr>
<td>{{posiciones.matricula}}</td>
<td>{{posiciones.latitud}}</td>
<td>{{posiciones.longitud}}</td>
<td>{{posiciones.descripcion}}</td>
<td>{{posiciones.zona}}</td>
<td>{{posiciones.fecha}}</td>
</tr>
</ng-template>
</p-table>
</div>
The point is that I want to be able to use this table as a child component and make sure that it will not get bigger than the container component. I have added [scrollable]="true" but it does not work for [scrollHeight]="'100%'" or [scrollHeight]="'100hv'" so I have to fix the height of the table in order to make the scroll work. I have also tried style="height: 100%;"but nothing changes.

Make CSS: "resize: horizontal" work with Mat-Table on firefox

I have a mat-table and wanted to make the columns resizeable, so I stumbled across the CSS property "resize" which works perfectly well for regular HTML tables
Basic HTML:
<table id="main_table">
<tr class="header">
<td><div class="tableHeaderCellDiv">Tech Name</div></td>
<td><div class="tableHeaderCellDiv">Name</div></td>
</tr>
</table>
CSS:
.tableHeaderCellDiv { resize: horizontal; overflow:hidden;}
Which gives the headers a very nice box with which you can resize the columns.
However, when trying to bring this exactly same thing over to my mat-table, the drag-box simply didn't show up.
<table mat-table [dataSource]="items" class="mat-elevation-z8">
<ng-container [matColumnDef]="column" *ngFor="let column of displayedColumnsMAT">
<th mat-header-cell class="custom-mat-header-styling tableHeaderCellDiv" *matHeaderCellDef>{{column}}</th>
</ng-container>
<tr mat-header-row class="tableHeaderCellDiv" *matHeaderRowDef="displayedColumnsMAT; sticky: true;" ></tr><!-- for the header row -->
</table>
I've cut out the not-header-rows for both examples, as they don't matter for now.
I've also tried inserting tableHeaderCellDiv (same CSS as for the plain HTML) as a class everywhere, guessing that that is the problem.
What am I doing wrong, or could it be that that feature simply does not work at all with Mat-Tables?
[EDIT:] thanks to #KrishnaRathore I now know that my code (probably) isn't the problem but Firefox is. If you're content with Chrome check out his answer though, it works.
HOWEVER, this problem seems to be unique to Mat-Table, as there is another small plain HTML table in my project with which the resizing works fine.
use this code
Stackblitz Demo
component.scss / component.css
.tableHeaderCellDiv {
resize: horizontal;
overflow:hidden;
}
component.html
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<ng-container [matColumnDef]="column" *ngFor="let column of displayedColumns">
<th mat-header-cell class="custom-mat-header-styling tableHeaderCellDiv" *matHeaderCellDef>{{column}}</th>
<td mat-cell *matCellDef="let element">{{element[column]}}</td>
</ng-container>
<tr mat-header-row class="tableHeaderCellDiv" *matHeaderRowDef="displayedColumns; sticky: true;"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
I have made it work (even on firefox), but I am absolutely certain that I tried this before and then it just didn't.
<th mat-header-cell class="custom-mat-header-styling" *matHeaderCellDef><div class="tableHeaderCellDiv">{{column}} </div></th>
so the trick is to have another div INSIDE the header cell, which is resizeable, and to not make the rest resizeable.

Visual Studio 'can't contain td inside div'

I am using primeNG p-table in my Angular application. I need to put this p-table in div. However Visual Studio gives a warning that I can't have td in div. But I have the whole table in it. Is it a good practice to put table into a div?
<div>
<p-table [value]="someData">
<ng-template pTemplate="header">
<tr>
<th>some header</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-car>
<tr>
<td>some value</td>
</tr>
</ng-template>
</p-table>
</div>

Primeng turbo table cell data overlapping other cells

How do I prevent primeng turbo table cell data from overlapping other cells,
I tried to add - [style]=" {'overflow':'hidden' }" to : <tr> , <td> and <div>, and none of these elements solved the overlapping..
anyone have an idea how to solve that?
Add class="ui-resizable-column" to each column and row. It prevents the data from other cells from overlapping into it (not it from overlapping into other rows), which is why in the example below, even the checkbox has it.
Example:
This will make the column headers not overlap:
<th *ngFor="let col of columns" class="ui-resizable-column">
</th>
<th style="width: 2.25em" class="ui-resizable-column">
<p-tableHeaderCheckbox></p-tableHeaderCheckbox>
</th>
Then you do the same for rows:
<td *ngFor="let col of columns" class="ui-resizable-column">
</td>
<td class="ui-resizable-column">
<p-tableCheckbox [value]="selectedrow"></p-tableCheckbox>
</td>

Angular 2 Make entire row clickable

I want to make each row of a table clickable in Angular 2. However, only the parts of the cell that contain data are clickable. i.e. if one cell contains more data than another, and so has a greater height, the empty bit of the smaller cell is not clickable.
For example, in the page below the first cell is only clickable on the line containing the name, whereas the entirety of the second cell is clickable
<table>
<thead></thead>
<tbody>
<tr *ngFor="let item of items" routerLink="/otherpage/{{item.Id}}">
<td>{{item.name}}</td>
<td>
<ul>
<li *ngFor="let detail of item.details">
{{detail}}
</li>
</ul>
</td>
</tr>
</tbody>
</table>
I've fixed the routerLink code for you.
<table>
<thead></thead>
<tbody>
<tr class="clickable" *ngFor="let item of items" [routerLink]="['/otherpage/', item.Id]">
<td>{{item.name}}</td>
<td>
<ul>
<li *ngFor="let detail of item.details">
{{detail}}
</li>
</ul>
</td>
</tr>
</tbody>
</table>
You need to add CSS for the animation.
clickable {
cursor: pointer;
}
This will make the entire <tr></tr> clickable with the cursor animation
set the padding for the <tr> to 0. this way the <td> elements would fill the rows, hence making the whole cell clickable.
note that depending on your css file this might be a bit more difficult. but the solution is basically to make your data cover your rows.