Responsive.ui-fluid style class provides fluid width to components for efficient use of space in screen. This example demonstrates ui-fluid in combination with Grid CSS and the components having built-in responsive modes like datatable. Note that Grid CSS is not mandatory, any grid system can be used with ui-fluid.
Source
<div class="ui-fluid">
<div class="ui-g">
<div class="ui-g-12 ui-md-6">
<div class="ui-g-4">
InputText
</div>
<div class="ui-g-8">
<input pInputText type="text" />
</div>
</div>
<div class="ui-g-12 ui-md-6">
<div class="ui-g-4">
Textarea
</div>
<div class="ui-g-8">
<textarea pInputTextarea type="text"></textarea>
</div>
</div>
<div class="ui-g-12 ui-md-6">
<div class="ui-g-4">
Calendar
</div>
<div class="ui-g-8">
<p-calendar [(ngModel)]="date"></p-calendar>
</div>
</div>
<div class="ui-g-12 ui-md-6">
<div class="ui-g-4">
Suggest
</div>
<div class="ui-g-8">
<p-autoComplete [(ngModel)]="country" [suggestions]="filteredCountriesSingle" (completeMethod)="filterCountrySingle($event)" field="name" [size]="30"
placeholder="Countries" [minLength]="1"></p-autoComplete>
</div>
</div>
<div class="ui-g-12 ui-md-6">
<div class="ui-g-4">
Button
</div>
<div class="ui-g-8">
<button pButton label="Save"type="button"></button>
</div>
</div>
<div class="ui-g-12 ui-md-6">
<div class="ui-g-4">
SplitButton
</div>
<div class="ui-g-8">
<p-splitButton label="Save" icon="pi pi-check" [model]="splitMenuItems"></p-splitButton>
</div>
</div>
<div class="ui-g-12 ui-md-6">
<div class="ui-g-4">
Dropdown
</div>
<div class="ui-g-8">
<p-dropdown [options]="cities" [(ngModel)]="selectedCity"></p-dropdown>
</div>
</div>
<div class="ui-g-12 ui-md-6">
<div class="ui-g-4">
Password
</div>
<div class="ui-g-8">
<input type="text" pPassword />
</div>
</div>
<div class="ui-g-12 ui-md-6">
<div class="ui-g-4">
Listbox
</div>
<div class="ui-g-8">
<p-listbox [options]="options" [(ngModel)]="selectedOption"></p-listbox>
</div>
</div>
<div class="ui-g-12 ui-md-6">
<div class="ui-g-4">
Radio
</div>
<div class="ui-g-8">
>div class="ui-g radiobuttons"<
>div class="ui-g-12"<>p-radioButton name="group1" value="Option 1" label="Option 1" [(ngModel)]="val"<>/p-radioButton<>/div<
>div class="ui-g-12"<>p-radioButton name="group1" value="Option 2" label="Option 2" [(ngModel)]="val"<>/p-radioButton<>/div<
>div class="ui-g-12"<>p-radioButton name="group1" value="Option 3" label="Option 3" [(ngModel)]="val"<>/p-radioButton<>/div<
>div class="ui-g-12"<>p-radioButton name="group1" value="Option 4" label="Option 4" [(ngModel)]="val"<>/p-radioButton<>/div<
>/div<
</div>
</div>
<div class="ui-g-2">
Dialog
</div>
<div class="ui-g-10">
<button pButton label="Show" type="button" icon="pi pi-plus" (click)="showDialog()"></button>
</div>
</div>
<p-dialog header="Godfather 1" [(visible)]="display" [responsive]="true" [resizable]="false" [style]="{width: '300px'}">
<p>The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.
His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family,
kind and benevolent to those who give respect,
but given to ruthless violence whenever anything stands against the good of the family.</p>
</p-dialog>
<p-panel header="Panel" [style]="{'margin-top':'20px'}">
The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.
His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family,
kind and benevolent to those who give respect,
but given to ruthless violence whenever anything stands against the good of the family.
</p-panel>
<p-table [value]="cars" [style]="{'margin-top':'20px'}" [value]="cars" [rows]="10" [paginator]="true" [pageLinks]="3" [responsive]="true">
<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>
<p-tree [value]="files" [style]="{'margin-top':'20px','margin-bottom':'20px'}"></p-tree>
<p-orderList [value]="cars" [listStyle]="{'height':'250px'}" [style]="{'margin-top':'20px','margin-bottom':'20px'}" [responsive]="true" header="Responsive Cars">
<ng-template let-car pTemplate="item">
<img src="assets/showcase/images/demo/car/{{car.brand}}.gif" style="display:inline-block;margin:2px 0 2px 2px" width="48">
<div style="font-size:14px;float:right;margin:15px 5px 0 0">{{car.brand}} - {{car.year}} - {{car.color}}</div>
</ng-template>
</p-orderList>
<p-carousel headerText="Cars" [value]="cars2" [style]="{'margin-top':'20px','margin-bottom':'20px'}">
<ng-template let-car pTemplate="item">
<div class="ui-g" style="text-align:center">
<div class="ui-g-12"><img src="assets/showcase/images/demo/car/{{car.brand}}.png" width="60"></div>
<div class="ui-g-6">Vin</div>
<div class="ui-g-6">{{car.vin}}</div>
<div class="ui-g-6">Year</div>
<div class="ui-g-6">{{car.year}}</div>
<div class="ui-g-6">Color</div>
<div class="ui-g-6">{{car.color}}</div>
</div>
</ng-template>
</p-carousel>
<p-pickList [source]="sourceCars" [target]="targetCars" sourceHeader="Available" targetHeader="Selected" [responsive]="true"
[sourceStyle]="{'height':'300px'}" [targetStyle]="{'height':'300px'}" [style]="{'margin-top':'20px','margin-bottom':'20px'}">
<ng-template let-car pTemplate="item">
<img src="assets/showcase/images/demo/car/{{car.brand}}.gif" style="display:inline-block;margin:2px 0 2px 2px" width="48">
<div style="font-size:14px;float:right;margin:15px 5px 0 0">{{car.brand}} - {{car.year}} - {{car.color}}</div>
</ng-template>
</p-pickList>
<div class="ui-g">
<div class="ui-g-12 ui-md-4">
<p-menu [model]="items1"></p-menu>
</div>
<div class="ui-g-12 ui-md-8">
<p-panelMenu [model]="items2"></p-panelMenu>
</div>
</div>
</div>
export class ResponsiveDemo implements OnInit {
cities: SelectItem[];
files: TreeNode[];
sourceCars: Car[];
targetCars: Car[];
data: any;
selectedCity: string;
val: string;
options: SelectItem[];
selectedOption: string;
display: boolean = false;
cars: Car[];
cars1: Car[];
cars2: Car[];
cars3: Car[];
date: string;
text: string;
filteredCountriesSingle: any[];
items1: MenuItem[];
items2: MenuItem[];
splitMenuItems: MenuItem[];
country: any;
showDialog() {
this.display = true;
}
constructor(private carService: CarService, private countryService: CountryService, private nodeService: NodeService) {
this.cars2 = [
{vin: 'r3278r2', year: 2010, brand: 'Audi', color: 'Black'},
{vin: 'jhto2g2', year: 2015, brand: 'BMW', color: 'White'},
{vin: 'h453w54', year: 2012, brand: 'Honda', color: 'Blue'},
{vin: 'g43gwwg', year: 1998, brand: 'Renault', color: 'White'},
{vin: 'gf45wg5', year: 2011, brand: 'VW', color: 'Red'},
{vin: 'bhv5y5w', year: 2015, brand: 'Jaguar', color: 'Blue'},
{vin: 'ybw5fsd', year: 2012, brand: 'Ford', color: 'Yellow'},
{vin: '45665e5', year: 2011, brand: 'Mercedes', color: 'Brown'},
{vin: 'he6sb5v', year: 2015, brand: 'Ford', color: 'Black'}
];
this.cities = [];
this.cities.push({label:'Select Cities', value:'Select Cities'});
this.cities.push({label:'New York', value:'New York'});
this.cities.push({label:'Rome', value:'Rome'});
this.cities.push({label:'London', value:'London'});
this.cities.push({label:'Istanbul', value:'Istanbul'});
this.cities.push({label:'Paris', value:'Paris'});
this.options = [];
this.options.push({label:'Option 1', value:'Option 1'});
this.options.push({label:'Option 2', value:'Option 2'});
this.options.push({label:'Option 3', value:'Option 3'});
this.options.push({label:'Option 4', value:'Option 4'});
this.options.push({label:'Option 5', value:'Option 5'});
this.data = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [
{
label: 'My First dataset',
fillColor: 'rgba(220,220,220,0.2)',
strokeColor: 'rgba(220,220,220,1)',
pointColor: 'rgba(220,220,220,1)',
pointStrokeColor: '#fff',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(220,220,220,1)',
data: [65, 59, 80, 81, 56, 55, 40]
},
{
label: 'My Second dataset',
fillColor: 'rgba(151,187,205,0.2)',
strokeColor: 'rgba(151,187,205,1)',
pointColor: 'rgba(151,187,205,1)',
pointStrokeColor: '#fff',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(151,187,205,1)',
data: [28, 48, 40, 19, 86, 27, 90]
}
]
}
}
ngOnInit() {
this.carService.getCarsMedium().then(cars => this.cars = cars);
this.nodeService.getFiles().then(files => this.files = files);
this.carService.getCarsSmall().then(cars1 => this.cars1 = cars1);
this.carService.getCarsSmall().then(cars3 => this.sourceCars = cars3);
this.targetCars = [];
this.items1 = [{
label: 'File',
items: [
{label: 'New', icon: 'fa fa-fw fa-plus'},
{label: 'Open', icon: 'fa fa-fw fa-download'}
]
},
{
label: 'Edit',
items: [
{label: 'Undo', icon: 'fa fa-fw fa-refresh'},
{label: 'Redo', icon: 'fa fa-fw fa-repeat'}
]
}];
this.items2 = [
{
label: 'File',
icon: 'fa fa-fw fa-file-o',
items: [{
label: 'New',
icon: 'fa fa-fw fa-plus',
items: [
{label: 'Project'},
{label: 'Other'},
]
},
{label: 'Open'},
{label: 'Quit'}
]
},
{
label: 'Edit',
icon: 'fa fa-fw fa-edit',
items: [
{label: 'Undo', icon: 'fa fa-fw fa-mail-forward'},
{label: 'Redo', icon: 'fa fa-fw fa-mail-reply'}
]
},
{
label: 'Help',
icon: 'fa fa-fw fa-question',
items: [
{
label: 'Contents'
},
{
label: 'Search',
icon: 'fa fa-fw fa-search',
items: [
{
label: 'Text',
items: [
{
label: 'Workspace'
}
]
},
{
label: 'File'
}
]}
]
},
{
label: 'Actions',
icon: 'fa fa-fw fa-gear',
items: [
{
label: 'Edit',
icon: 'fa fa-fw fa-refresh',
items: [
{label: 'Save', icon: 'fa fa-fw fa-save'},
{label: 'Update', icon: 'fa fa-fw fa-save'},
]
},
{
label: 'Other',
icon: 'fa fa-fw fa-phone',
items: [
{label: 'Delete', icon: 'fa fa-fw fa-minus'}
]
}
]
}
];
this.splitMenuItems = [
{label: 'Update', icon: 'fa fa-fw fa-refresh'},
{label: 'Delete', icon: 'fa fa-fw fa-close'},
{label: 'Angular.io', icon: 'fa fa-fw fa-link', url: 'http://angular.io'},
{label: 'Theming', icon: 'fa fa-fw fa-paint-brush', routerLink: ['/theming']}
];
}
filterCountrySingle(event) {
let query = event.query;
this.countryService.getCountries().then(countries => {
this.filteredCountriesSingle = this.filterCountry(query, countries);
});
}
filterCountry(query, countries: any[]):any[] {
//in a real application, make a request to a remote url with the query and return filtered results, for demo we filter at client side
let filtered : any[] = [];
for(let i = 0; i < countries.length; i++) {
let country = countries[i];
if(country.name.toLowerCase().indexOf(query.toLowerCase()) == 0) {
filtered.push(country);
}
}
return filtered;
}
}