I need split page vertically (e.g. 60%:40%) to the two areas and splitter must be draggable. So I chose PrimeNG p-splitter. Right area contains p-table with horizontal scrollbar (based on doc: https://www.primefaces.org/primeng/showcase/#/table/scroll part: "Horizontal and Vertical"):
<p-splitter [panelSizes]="[60,40]" [style]="{'height': '400px'}">
<ng-template pTemplate>
<p-table [value]="cars" [scrollable]="true" [style]="{width:'600px'}" scrollHeight="200px">
...
</p-table>
</ng-template>
<ng-template pTemplate>
Panel 2
</ng-template>
</p-splitter>
Problem is that table width is bound to 600px and:
- it is not possible to drag splitter to the right (table does not allow it)
- when splitter is dragged to the left, table width stays 600px (so there is useless blank space between table and splitter).
Project on StackBlitz
https://stackblitz.com/edit/primeng-splitter-and-datatable
Complete code
<p-splitter [panelSizes]="[60,40]" [style]="{'height': '400px'}">
<ng-template pTemplate>
<p-table [value]="cars" [scrollable]="true" [style]="{width:'600px'}" scrollHeight="200px">
<ng-template pTemplate="colgroup" let-columns>
<colgroup>
<col style="width:250px">
<col style="width:250px">
<col style="width:250px">
<col style="width:250px">
</colgroup>
</ng-template>
<ng-template pTemplate="header">
<tr>
<th>Vin</th>
<th>Year</th>
<th>Brand</th>
<th>Color</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-car>
<tr>
<td>{{car.vin}}</td>
<td>{{car.year}}</td>
<td>{{car.brand}}</td>
<td>{{car.color}}</td>
</tr>
</ng-template>
</p-table>
</ng-template>
<ng-template pTemplate>
Panel 2
</ng-template>
</p-splitter>
import {Component, OnInit} from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
cars: any[] = [];
ngOnInit(): void {
this.cars = [
{
vin: 1001,
year: '2021',
brand: 'VW',
color: 'red',
country: 'Algeria'
},
{
vin: 1002,
year: '2021',
brand: 'VW',
color: 'red',
country: 'Algeria'
},
{
vin: 1003,
year: '2021',
brand: 'VW',
color: 'red',
country: 'Algeria'
},
{
vin: 1004,
year: '2021',
brand: 'VW',
color: 'red',
country: 'Algeria'
},
{
vin: 1005,
year: '2021',
brand: 'VW',
color: 'red',
country: 'Algeria'
}
];
}
}