|
| 1 | +# md-grid-list |
| 2 | + |
| 3 | +`md-grid-list` is an alternative list view that arranges cells into grid-based layout. |
| 4 | +See Material Design spec [here](https://www.google.com/design/spec/components/grid-lists.html). |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +### Simple grid list |
| 9 | + |
| 10 | +To use `md-grid-list`, first import the grid list directives and add them to your component's directives |
| 11 | +array: |
| 12 | + |
| 13 | +```javascript |
| 14 | +@Component({ |
| 15 | + ... |
| 16 | + directives: [MD_GRID_LIST_DIRECTIVES] |
| 17 | +}) |
| 18 | +``` |
| 19 | + |
| 20 | +In your template, create an `md-grid-list` element and specify the number of columns you want for |
| 21 | +your grid using the `cols` property (this is the only mandatory attribute). |
| 22 | + |
| 23 | +You can define each tile using an `md-grid-tile` element, passing any tile content between its tags. |
| 24 | + |
| 25 | +Tiles are greedily placed in the first position of the grid that fits them, so row count depends on |
| 26 | +how many tiles can fit in each row, given the col count and the colspan/rowspan of each tile. |
| 27 | + |
| 28 | +```html |
| 29 | +<md-grid-list cols="4" [style.background]="'lightblue'"> |
| 30 | + <md-grid-tile>One</md-grid-tile> |
| 31 | + <md-grid-tile>Two</md-grid-tile> |
| 32 | + <md-grid-tile>Three</md-grid-tile> |
| 33 | + <md-grid-tile>Four</md-grid-tile> |
| 34 | +</md-grid-list> |
| 35 | +``` |
| 36 | + |
| 37 | +Output: |
| 38 | + |
| 39 | +<img src="https://material.angularjs.org/material2_assets/grid-list/basic-grid-list.png"> |
| 40 | + |
| 41 | +## Grid list config |
| 42 | + |
| 43 | +####`cols` |
| 44 | + |
| 45 | +The `cols` property controls the number of columns displayed in your grid. It must be set or the |
| 46 | +grid list will not be able to generate your layout. |
| 47 | + |
| 48 | +Ex: `<md-grid-list cols="3">...` |
| 49 | + |
| 50 | +Default: There is no reasonable default value for this, so if it is unspecified, the grid list will |
| 51 | +throw an error. |
| 52 | + |
| 53 | +####`rowHeight` |
| 54 | + |
| 55 | +Row height for the list can be calculated in three ways: |
| 56 | + |
| 57 | +1. **Fixed height**: The height can be in `px`, `em`, or `rem`. If no units are specified, `px` |
| 58 | +units are assumed. |
| 59 | + |
| 60 | + Ex: `<md-grid-list cols="3" rowHeight="100px">...` |
| 61 | + |
| 62 | +2. **Ratio**: This ratio is width:height, and must be passed in with a colon, not a decimal. |
| 63 | + |
| 64 | + Ex: `<md-grid-list cols="3" rowHeight="4:3">...`. |
| 65 | + |
| 66 | +3. **Fit**: This mode automatically divides the available height by the number of rows. Please note |
| 67 | +the height of the grid-list or its container must be set. |
| 68 | + |
| 69 | + Ex: `<md-grid-list cols="3" rowHeight="fit">...` |
| 70 | + |
| 71 | +Defaults to a 1:1 ratio of width:height. |
| 72 | + |
| 73 | +####`gutterSize` |
| 74 | + |
| 75 | +Gutter size can be set to any `px`, `em`, or `rem` value with the `gutterSize` property. If no |
| 76 | +units are specified, `px` units are assumed. |
| 77 | + |
| 78 | +Ex: `<md-grid-list cols="3" gutterSize="4px">...` |
| 79 | + |
| 80 | +Defaults to `1px`. |
| 81 | + |
| 82 | +## Grid tile config |
| 83 | + |
| 84 | +You can set the rowspan and colspan of each tile individually, using the `rowspan` and `colspan` |
| 85 | +properties. If not set, they both default to `1`. |
| 86 | + |
| 87 | +```html |
| 88 | +<md-grid-list cols="4" rowHeight="100px"> |
| 89 | + <md-grid-tile *ngFor="let tile of tiles" [colspan]="tile.cols" [rowspan]="tile.rows" |
| 90 | + [style.background]="tile.color"> |
| 91 | + {{tile.text}} |
| 92 | + </md-grid-tile> |
| 93 | +</md-grid-list> |
| 94 | +``` |
| 95 | + |
| 96 | +```javascript |
| 97 | +... |
| 98 | +export class MyComp { |
| 99 | + tiles: any[] = [ |
| 100 | + {text: 'One', cols: 3, rows: 1, color: 'lightblue'}, |
| 101 | + {text: 'Two', cols: 1, rows: 2, color: 'lightgreen'}, |
| 102 | + {text: 'Three', cols: 1, rows: 1, color: 'lightpink'}, |
| 103 | + {text: 'Four', cols: 2, rows: 1, color: '#DDBDF1'}, |
| 104 | + ]; |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +Output: |
| 109 | + |
| 110 | +<img src="https://material.angularjs.org/material2_assets/grid-list/fancy-grid-list.png"> |
| 111 | + |
| 112 | +## TODO |
| 113 | + |
| 114 | +- Grid tile headers and footers |
| 115 | +- Responsive sizing support |
0 commit comments