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.

Responsive - 图1

Source

View on GitHub

  1. <div class="ui-fluid">
  2. <div class="ui-g">
  3. <div class="ui-g-12 ui-md-6">
  4. <div class="ui-g-4">
  5. InputText
  6. </div>
  7. <div class="ui-g-8">
  8. <input pInputText type="text" />
  9. </div>
  10. </div>
  11. <div class="ui-g-12 ui-md-6">
  12. <div class="ui-g-4">
  13. Textarea
  14. </div>
  15. <div class="ui-g-8">
  16. <textarea pInputTextarea type="text"></textarea>
  17. </div>
  18. </div>
  19. <div class="ui-g-12 ui-md-6">
  20. <div class="ui-g-4">
  21. Calendar
  22. </div>
  23. <div class="ui-g-8">
  24. <p-calendar [(ngModel)]="date"></p-calendar>
  25. </div>
  26. </div>
  27. <div class="ui-g-12 ui-md-6">
  28. <div class="ui-g-4">
  29. Suggest
  30. </div>
  31. <div class="ui-g-8">
  32. <p-autoComplete [(ngModel)]="country" [suggestions]="filteredCountriesSingle" (completeMethod)="filterCountrySingle($event)" field="name" [size]="30"
  33. placeholder="Countries" [minLength]="1"></p-autoComplete>
  34. </div>
  35. </div>
  36. <div class="ui-g-12 ui-md-6">
  37. <div class="ui-g-4">
  38. Button
  39. </div>
  40. <div class="ui-g-8">
  41. <button pButton label="Save"type="button"></button>
  42. </div>
  43. </div>
  44. <div class="ui-g-12 ui-md-6">
  45. <div class="ui-g-4">
  46. SplitButton
  47. </div>
  48. <div class="ui-g-8">
  49. <p-splitButton label="Save" icon="pi pi-check" [model]="splitMenuItems"></p-splitButton>
  50. </div>
  51. </div>
  52. <div class="ui-g-12 ui-md-6">
  53. <div class="ui-g-4">
  54. Dropdown
  55. </div>
  56. <div class="ui-g-8">
  57. <p-dropdown [options]="cities" [(ngModel)]="selectedCity"></p-dropdown>
  58. </div>
  59. </div>
  60. <div class="ui-g-12 ui-md-6">
  61. <div class="ui-g-4">
  62. Password
  63. </div>
  64. <div class="ui-g-8">
  65. <input type="text" pPassword />
  66. </div>
  67. </div>
  68. <div class="ui-g-12 ui-md-6">
  69. <div class="ui-g-4">
  70. Listbox
  71. </div>
  72. <div class="ui-g-8">
  73. <p-listbox [options]="options" [(ngModel)]="selectedOption"></p-listbox>
  74. </div>
  75. </div>
  76. <div class="ui-g-12 ui-md-6">
  77. <div class="ui-g-4">
  78. Radio
  79. </div>
  80. <div class="ui-g-8">
  81. >div class="ui-g radiobuttons"<
  82. >div class="ui-g-12"<>p-radioButton name="group1" value="Option 1" label="Option 1" [(ngModel)]="val"<>/p-radioButton<>/div<
  83. >div class="ui-g-12"<>p-radioButton name="group1" value="Option 2" label="Option 2" [(ngModel)]="val"<>/p-radioButton<>/div<
  84. >div class="ui-g-12"<>p-radioButton name="group1" value="Option 3" label="Option 3" [(ngModel)]="val"<>/p-radioButton<>/div<
  85. >div class="ui-g-12"<>p-radioButton name="group1" value="Option 4" label="Option 4" [(ngModel)]="val"<>/p-radioButton<>/div<
  86. >/div<
  87. </div>
  88. </div>
  89. <div class="ui-g-2">
  90. Dialog
  91. </div>
  92. <div class="ui-g-10">
  93. <button pButton label="Show" type="button" icon="pi pi-plus" (click)="showDialog()"></button>
  94. </div>
  95. </div>
  96. <p-dialog header="Godfather 1" [(visible)]="display" [responsive]="true" [resizable]="false" [style]="{width: '300px'}">
  97. <p>The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.
  98. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
  99. 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,
  100. kind and benevolent to those who give respect,
  101. but given to ruthless violence whenever anything stands against the good of the family.</p>
  102. </p-dialog>
  103. <p-panel header="Panel" [style]="{'margin-top':'20px'}">
  104. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.
  105. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
  106. 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,
  107. kind and benevolent to those who give respect,
  108. but given to ruthless violence whenever anything stands against the good of the family.
  109. </p-panel>
  110. <p-table [value]="cars" [style]="{'margin-top':'20px'}" [value]="cars" [rows]="10" [paginator]="true" [pageLinks]="3" [responsive]="true">
  111. <ng-template pTemplate="header">
  112. <tr>
  113. <th>Vin</th>
  114. <th>Year</th>
  115. <th>Brand</th>
  116. <th>Color</th>
  117. </tr>
  118. </ng-template>
  119. <ng-template pTemplate="body" let-car>
  120. <tr>
  121. <td>{{car.vin}}</td>
  122. <td>{{car.year}}</td>
  123. <td>{{car.brand}}</td>
  124. <td>{{car.color}}</td>
  125. </tr>
  126. </ng-template>
  127. </p-table>
  128. <p-tree [value]="files" [style]="{'margin-top':'20px','margin-bottom':'20px'}"></p-tree>
  129. <p-orderList [value]="cars" [listStyle]="{'height':'250px'}" [style]="{'margin-top':'20px','margin-bottom':'20px'}" [responsive]="true" header="Responsive Cars">
  130. <ng-template let-car pTemplate="item">
  131. <img src="assets/showcase/images/demo/car/{{car.brand}}.gif" style="display:inline-block;margin:2px 0 2px 2px" width="48">
  132. <div style="font-size:14px;float:right;margin:15px 5px 0 0">{{car.brand}} - {{car.year}} - {{car.color}}</div>
  133. </ng-template>
  134. </p-orderList>
  135. <p-carousel headerText="Cars" [value]="cars2" [style]="{'margin-top':'20px','margin-bottom':'20px'}">
  136. <ng-template let-car pTemplate="item">
  137. <div class="ui-g" style="text-align:center">
  138. <div class="ui-g-12"><img src="assets/showcase/images/demo/car/{{car.brand}}.png" width="60"></div>
  139. <div class="ui-g-6">Vin</div>
  140. <div class="ui-g-6">{{car.vin}}</div>
  141. <div class="ui-g-6">Year</div>
  142. <div class="ui-g-6">{{car.year}}</div>
  143. <div class="ui-g-6">Color</div>
  144. <div class="ui-g-6">{{car.color}}</div>
  145. </div>
  146. </ng-template>
  147. </p-carousel>
  148. <p-pickList [source]="sourceCars" [target]="targetCars" sourceHeader="Available" targetHeader="Selected" [responsive]="true"
  149. [sourceStyle]="{'height':'300px'}" [targetStyle]="{'height':'300px'}" [style]="{'margin-top':'20px','margin-bottom':'20px'}">
  150. <ng-template let-car pTemplate="item">
  151. <img src="assets/showcase/images/demo/car/{{car.brand}}.gif" style="display:inline-block;margin:2px 0 2px 2px" width="48">
  152. <div style="font-size:14px;float:right;margin:15px 5px 0 0">{{car.brand}} - {{car.year}} - {{car.color}}</div>
  153. </ng-template>
  154. </p-pickList>
  155. <div class="ui-g">
  156. <div class="ui-g-12 ui-md-4">
  157. <p-menu [model]="items1"></p-menu>
  158. </div>
  159. <div class="ui-g-12 ui-md-8">
  160. <p-panelMenu [model]="items2"></p-panelMenu>
  161. </div>
  162. </div>
  163. </div>
  164.  
  1. export class ResponsiveDemo implements OnInit {
  2. cities: SelectItem[];
  3. files: TreeNode[];
  4. sourceCars: Car[];
  5. targetCars: Car[];
  6. data: any;
  7. selectedCity: string;
  8. val: string;
  9. options: SelectItem[];
  10. selectedOption: string;
  11. display: boolean = false;
  12. cars: Car[];
  13. cars1: Car[];
  14. cars2: Car[];
  15. cars3: Car[];
  16. date: string;
  17. text: string;
  18. filteredCountriesSingle: any[];
  19. items1: MenuItem[];
  20. items2: MenuItem[];
  21. splitMenuItems: MenuItem[];
  22. country: any;
  23. showDialog() {
  24. this.display = true;
  25. }
  26. constructor(private carService: CarService, private countryService: CountryService, private nodeService: NodeService) {
  27. this.cars2 = [
  28. {vin: 'r3278r2', year: 2010, brand: 'Audi', color: 'Black'},
  29. {vin: 'jhto2g2', year: 2015, brand: 'BMW', color: 'White'},
  30. {vin: 'h453w54', year: 2012, brand: 'Honda', color: 'Blue'},
  31. {vin: 'g43gwwg', year: 1998, brand: 'Renault', color: 'White'},
  32. {vin: 'gf45wg5', year: 2011, brand: 'VW', color: 'Red'},
  33. {vin: 'bhv5y5w', year: 2015, brand: 'Jaguar', color: 'Blue'},
  34. {vin: 'ybw5fsd', year: 2012, brand: 'Ford', color: 'Yellow'},
  35. {vin: '45665e5', year: 2011, brand: 'Mercedes', color: 'Brown'},
  36. {vin: 'he6sb5v', year: 2015, brand: 'Ford', color: 'Black'}
  37. ];
  38. this.cities = [];
  39. this.cities.push({label:'Select Cities', value:'Select Cities'});
  40. this.cities.push({label:'New York', value:'New York'});
  41. this.cities.push({label:'Rome', value:'Rome'});
  42. this.cities.push({label:'London', value:'London'});
  43. this.cities.push({label:'Istanbul', value:'Istanbul'});
  44. this.cities.push({label:'Paris', value:'Paris'});
  45. this.options = [];
  46. this.options.push({label:'Option 1', value:'Option 1'});
  47. this.options.push({label:'Option 2', value:'Option 2'});
  48. this.options.push({label:'Option 3', value:'Option 3'});
  49. this.options.push({label:'Option 4', value:'Option 4'});
  50. this.options.push({label:'Option 5', value:'Option 5'});
  51. this.data = {
  52. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  53. datasets: [
  54. {
  55. label: 'My First dataset',
  56. fillColor: 'rgba(220,220,220,0.2)',
  57. strokeColor: 'rgba(220,220,220,1)',
  58. pointColor: 'rgba(220,220,220,1)',
  59. pointStrokeColor: '#fff',
  60. pointHighlightFill: '#fff',
  61. pointHighlightStroke: 'rgba(220,220,220,1)',
  62. data: [65, 59, 80, 81, 56, 55, 40]
  63. },
  64. {
  65. label: 'My Second dataset',
  66. fillColor: 'rgba(151,187,205,0.2)',
  67. strokeColor: 'rgba(151,187,205,1)',
  68. pointColor: 'rgba(151,187,205,1)',
  69. pointStrokeColor: '#fff',
  70. pointHighlightFill: '#fff',
  71. pointHighlightStroke: 'rgba(151,187,205,1)',
  72. data: [28, 48, 40, 19, 86, 27, 90]
  73. }
  74. ]
  75. }
  76. }
  77. ngOnInit() {
  78. this.carService.getCarsMedium().then(cars => this.cars = cars);
  79. this.nodeService.getFiles().then(files => this.files = files);
  80. this.carService.getCarsSmall().then(cars1 => this.cars1 = cars1);
  81. this.carService.getCarsSmall().then(cars3 => this.sourceCars = cars3);
  82. this.targetCars = [];
  83. this.items1 = [{
  84. label: 'File',
  85. items: [
  86. {label: 'New', icon: 'fa fa-fw fa-plus'},
  87. {label: 'Open', icon: 'fa fa-fw fa-download'}
  88. ]
  89. },
  90. {
  91. label: 'Edit',
  92. items: [
  93. {label: 'Undo', icon: 'fa fa-fw fa-refresh'},
  94. {label: 'Redo', icon: 'fa fa-fw fa-repeat'}
  95. ]
  96. }];
  97. this.items2 = [
  98. {
  99. label: 'File',
  100. icon: 'fa fa-fw fa-file-o',
  101. items: [{
  102. label: 'New',
  103. icon: 'fa fa-fw fa-plus',
  104. items: [
  105. {label: 'Project'},
  106. {label: 'Other'},
  107. ]
  108. },
  109. {label: 'Open'},
  110. {label: 'Quit'}
  111. ]
  112. },
  113. {
  114. label: 'Edit',
  115. icon: 'fa fa-fw fa-edit',
  116. items: [
  117. {label: 'Undo', icon: 'fa fa-fw fa-mail-forward'},
  118. {label: 'Redo', icon: 'fa fa-fw fa-mail-reply'}
  119. ]
  120. },
  121. {
  122. label: 'Help',
  123. icon: 'fa fa-fw fa-question',
  124. items: [
  125. {
  126. label: 'Contents'
  127. },
  128. {
  129. label: 'Search',
  130. icon: 'fa fa-fw fa-search',
  131. items: [
  132. {
  133. label: 'Text',
  134. items: [
  135. {
  136. label: 'Workspace'
  137. }
  138. ]
  139. },
  140. {
  141. label: 'File'
  142. }
  143. ]}
  144. ]
  145. },
  146. {
  147. label: 'Actions',
  148. icon: 'fa fa-fw fa-gear',
  149. items: [
  150. {
  151. label: 'Edit',
  152. icon: 'fa fa-fw fa-refresh',
  153. items: [
  154. {label: 'Save', icon: 'fa fa-fw fa-save'},
  155. {label: 'Update', icon: 'fa fa-fw fa-save'},
  156. ]
  157. },
  158. {
  159. label: 'Other',
  160. icon: 'fa fa-fw fa-phone',
  161. items: [
  162. {label: 'Delete', icon: 'fa fa-fw fa-minus'}
  163. ]
  164. }
  165. ]
  166. }
  167. ];
  168. this.splitMenuItems = [
  169. {label: 'Update', icon: 'fa fa-fw fa-refresh'},
  170. {label: 'Delete', icon: 'fa fa-fw fa-close'},
  171. {label: 'Angular.io', icon: 'fa fa-fw fa-link', url: 'http://angular.io'},
  172. {label: 'Theming', icon: 'fa fa-fw fa-paint-brush', routerLink: ['/theming']}
  173. ];
  174. }
  175. filterCountrySingle(event) {
  176. let query = event.query;
  177. this.countryService.getCountries().then(countries => {
  178. this.filteredCountriesSingle = this.filterCountry(query, countries);
  179. });
  180. }
  181. filterCountry(query, countries: any[]):any[] {
  182. //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
  183. let filtered : any[] = [];
  184. for(let i = 0; i < countries.length; i++) {
  185. let country = countries[i];
  186. if(country.name.toLowerCase().indexOf(query.toLowerCase()) == 0) {
  187. filtered.push(country);
  188. }
  189. }
  190. return filtered;
  191. }
  192. }
  193.