Angular Material Tutorial - 14 - Grid List
Summary
TLDRThis video tutorial introduces the Material Grid List, a two-dimensional list view in Angular Material. It explains the process of importing the necessary module, creating a grid with a specified number of columns, and adding grid tiles with titles. The video also covers advanced customization options such as row and column spanning, row height adjustments, and gutter size for spacing between tiles. By the end, viewers will understand how to create and style a dynamic grid layout effectively.
Takeaways
- ๐ฆ The material grid list is a two-dimensional list view organized in a grid-based layout.
- ๐ To use the grid list, first import the MatGridListModule from @angular/material and add it to the NgModule's imports array.
- ๐ The grid list is created with the mat-grid-list component, which requires a 'cols' attribute to define the number of columns.
- ๐จ Children of the grid list are mat-grid-tile components, which can be customized with titles and background colors.
- ๐ข The number of rows in the grid list is determined by the number of tiles and the specified number of columns.
- ๐ฝ Tiles can span multiple rows or columns using the 'rowSpan' and 'colSpan' attributes, but 'colSpan' must not exceed the 'cols' attribute value.
- ๐ The height of each row in the grid list can be set explicitly using the 'rowHeight' attribute with pixel values, ratios, or 'fit' to match the container's height.
- ๐จ The 'rowHeight' can be a ratio relative to the column width, such as 2:1, making the row height half of the column width.
- ๐๏ธ When using 'rowHeight' set to 'fit', a specific height for the container must also be defined for the rows to fit within the container's height.
- ๐ The spacing between tiles in the grid list is controlled by the 'gutterSize' property, which can be adjusted in pixels.
Q & A
What is a material grid list in the context of the video?
-A material grid list is a two-dimensional list view that arranges items into a grid-based layout.
How do you create a grid list in Angular Material?
-To create a grid list in Angular Material, you first import the MatGridListModule from '@angular/material/grid-list' and add it to your NgModule's imports array.
What attribute of the mat-grid-list component specifies the number of columns?
-The cols attribute of the mat-grid-list component specifies the number of columns in the grid.
How many columns did the video tutorial use for the grid list example?
-The video tutorial used two columns for the grid list example.
How does the number of rows in a grid list get determined?
-The number of rows in a grid list is determined by the number of columns specified and the number of tiles. It is calculated based on the division of total tiles by the number of columns.
What happens if you have an odd number of tiles in relation to the number of columns?
-If you have an odd number of tiles, the grid list will create additional rows to accommodate all the tiles, resulting in an uneven number of tiles per row.
How can you specify that a tile should span multiple rows or columns?
-You can use the rowSpan and colSpan attributes on a mat-grid-tile component to specify that it should span multiple rows or columns.
What is the default height of a row in a grid list?
-By default, the height of a row in a grid list is equal to the width of a column.
What are the three ways to specify the row height in a grid list?
-The three ways to specify the row height are: 1) a fixed pixel value, 2) a ratio relative to the column width, and 3) fitting the height based on the container's height.
How do you adjust the spacing between the tiles in a grid list?
-You can adjust the spacing between the tiles using the gutterSize property on the mat-grid-list component.
What is the consequence of setting a colSpan value that exceeds the number of columns specified by the cols attribute?
-If the colSpan value exceeds the number of columns specified by the cols attribute, it will result in an error.
What is the purpose of the rowHeight attribute in a grid list?
-The rowHeight attribute allows you to override the default height of rows in the grid list, providing options to set a fixed height, a ratio relative to column width, or fit the height to the container.
Outlines
๐ Introduction to Material Grid List
This paragraph introduces the concept of a Material Grid List, a two-dimensional list view organized in a grid-based layout. It explains the initial step of importing the required module from Material UI and setting up the grid list with a specified number of columns. The example uses two columns and demonstrates how the grid automatically arranges the tiles into rows based on the number of columns and tiles. It also touches on how to customize the grid by adding background colors to the tiles and how to control the number of rows and columns each tile occupies using 'rowSpan' and 'colSpan' attributes. The paragraph concludes with a discussion on adjusting the height of each row using 'rowHeight' attribute and adding spacing between tiles with 'gutterSize'.
๐ฅ Upcoming Video Content
The paragraph briefly mentions that the next video will continue the series, implying that there is more content to cover following the current video on Material Grid Lists.
Mindmap
Keywords
๐กMaterial Grid List
๐กImport Module
๐กCSS
๐กColumns
๐กRows
๐กGrid Tile
๐กRow Span
๐กCol Span
๐กRow Height
๐กContainer Height
๐กGutter Size
Highlights
The introduction of the material grid list, a two-dimensional list view arranged in a grid-based layout.
Importing the necessary module from the material library and adding it to the material array map grid list module.
Creating a grid list with the 'mat-grid-list' component and specifying the number of columns using the 'cols' attribute.
Adding 'mat-grid-tile' components as children to the grid list and setting up the basic structure with titles.
Applying a background color to the grid tiles for better visibility and aesthetics.
Explanation of how the number of rows is determined by the number of columns and tiles, with a practical example of 4 tiles fitting into 2 rows.
Adjusting the layout by specifying the number of rows or columns a tile should occupy using 'rowSpan' and 'colSpan' attributes.
Demonstration of how 'rowSpan' affects the tile's row occupation, with a tile taking up two rows instead of one.
Illustration of 'colSpan' in action, showing a tile occupying two columns instead of one.
Ensuring that 'colSpan' does not exceed the 'cols' attribute value to avoid errors.
Customizing the height of each row in the grid, with options to set a fixed pixel value, a ratio relative to column width, or fitting to the container's height.
Setting a row height to a fixed pixel value, such as 100 pixels, to uniformly adjust all rows.
Adjusting row height based on a ratio relative to the column width, like 2:1, to create a dynamic height-to-width relationship.
Fitting the row height to the container's height and specifying a container height to evenly distribute rows within the container.
Adding spacing between the tiles using the 'gutterSize' property for improved visual separation.
Conclusion of the grid list discussion in Angular Material, summarizing the key points and inviting viewers to engage with future content.
Transcripts
all right let's take a look at the
material grid list in this video the
grid list is basically a two dimensional
list view that arranged ourselves into
grid-based layout now the first step is
to import the module so in material
Mario Diaz import mat grid list module
and added to the material array map grid
list module now we can create a grid
list the component is mat grid list and
this component requires a calls
attribute which specifies the number of
columns in the grid let's go with two
columns so calls is equal to two as
children to this component we specify
math grid tile components
title 1 and similarly let's create three
more also to be able to clearly see the
grid let's add a background color to the
tiles so in the CSS file Matt grid tile
background color light blue now if we
save this and take a look at the browser
you can see the grid with two columns
and two rows the question is how did it
create the two rows for a grid we always
specify the number of columns and the
number of rows is determined by how many
columns we want and the number of tiles
specified since we have 4 tiles and two
columns it can fit only two tiles in
each row
hence it creates an additional row to
fit the next two tiles if you were to
have five tiles there would be three
rows so the number of rows is determined
by some basic math of course you can
also specify how many rows or columns
each tile should take up that can be
specified using the row span and called
span attributes on tile one if I said
row span is equal to two and take a look
at the browser you can see that it takes
up two rows instead of one similarly if
I said call span is equal to two
you can see that it takes up two columns
instead of one when specifying call span
though you need to make sure that it
does not exceed the calls attribute if
it does it throws an error all right
next let's talk about the height of each
row in the grid by default the height of
a row is equal to the width of a column
however you can override this using the
row height attribute and you can specify
one of the three values the first one is
a straightforward value so row height is
equal to a hundred pixels take a look at
the browser and you can see that each
row will be a hundred pixels tall the
second option is to specify the row
height as a ratio with respect to the
column width
for example row height is equal to 2 is
to 1 this implies that the row height is
1/2 the column width if the column width
is 200 pixels then the row height is a
hundred pixels take a look at the
browser and you can clearly see from
each style that the height looks half
the width the third option is to fit the
height based on the container so row
height is equal to fit but this time we
also need to specify a height for the
container so style height 200 pixels now
if we take a look at the browser the
rows are fit into the container height
of 200 pixels so each row has a height
of 100 pixels if there were four rows
each row would be 50 pixels so as to fit
the total container height of 200 pixels
all right the last attribute I want to
discuss on a good list is the gutter
size that is spacing between the tiles
we can specify gutter size using the
gutter size property let's go with
gutter size
is equal to 10 pixels if you save the
file and take a look at the browser you
should now see additional spacing
between the different tiles all right
that is about the grid list in angular
material thank you guys for watching
feel free to subscribe I'll see you guys
in the next video
5.0 / 5 (0 votes)