description |
---|
Grid Tile allows you to create a container of list of particular rows and columns. It can be used alone as well as inside the grid-list. |
A Grid Tile component is used to display a list of items.The column inside the Grid Tile component will contain the attribute and the row will contain the data of a particular attribute.
The data to be displayed can be iterated by providing ngFor
loop which can access data from the array and display on the screen.
- Drag and drop a Grid Tile component.
- Set the attributes of the component.
- Depending to the properties that you set, the list item will be displayed on the screen.
Display a Grid List component with 3 items. Also add a Grid Tile component within the Grid List.
- Drag and drop a Grid List component to a page container.
- Set the following values in the Attributes window:
cols
= 4 to display 4 columns.rowHeight
= 100px
- Drag and drop a Grid Tile component inside the Grid List and set the following values for the Grid Tile component:
colspan
= 1rowspan
= 1Label
= Refer the code belowngFor
= Refer the code below
Displaylist.html file
<mat-grid-list cols="2" rowHeight="100px">
<mat-grid-tile
*ngFor="let tile of tiles" // in *ngFor attribute
{{tile.text}} // label attribute
</mat-grid-tile>
</mat-grid-list>
Displaylist.ts
tiles: Tile[] = [
{text: 'One'},
{text: 'Two'},
{text: 'Three'},
{text: 'Four'},
];
-
So in the above example, the grid has two columns, and tile is an array which has four items containing string values (labels). The labels will be displayed using the
ngFor
loop. -
Save and Run the page.
-
A table with four items will be displayed inside the Grid List.
-
Grid Tile Label
: Used to give a label to the Grid Tile. -
style
: Accepts a string value that affects different properties of Grid Tile such as height, width, and color, based on the values provided. For example:background:orange:height:200px
. -
class
: Used to point to a class in a style sheet. Each class contains one or more style statements defined in the Style editor. TheClass
field accepts space separated class names such asclass1 class2
, where each class is defined in the Style editor as shown below:.class1 { border-radius:10px; flex-basis:10%; height:100px; } .class2 { border-radius:10px; flex-basis:10%; height:100px; }
-
ngFor
: A loop used to iterate through array objects and get the data. The syntax of ``ngFor
is *`ngFor="let d of data"` where `d` _****_is a loop variable and `data` is an array or object from which the data will be accessed. -
rowspan
: Defines the number of rows a cell should span. In a normal row therowspan
is always set to 1. This attribute is required when there is a requirement to change the row size. For example, when a row size is to be two times the size of the normal row, in such a case, therowspan
value will be set to 2. -
colspan
: Defines the number of columns a table cell should span. In a normal column, thecolspan
is always set to 1. This attribute is required only when there is a requirement to change the column size. For example, when a column size is to be two times the size of the normal column, in such a case, thecolspan
value will be set to 2.****
Support
- Devices: Android, iOS
- Browsers: Latest version of all modern browsers
- Dependencies version:
- Angular CLI version: 6.0.0 +
- Cordova version: 7.1.0 +