Line 1 - table tag - we are passing a datasource called transactions to the table. This is a class level variable containing a list of transactions.
Line 3 - Mat-header-row is a function that defines the header of the table. *matHeaderRowDef=”displayedColumns”. “displayedColumns” reference a class level variable that contains a list of columns to display..
Line 4 - mat-row is a function that defines the data rows of the table. *matRowDef=”let row; columns: displayedColumns;”
let row; - I think this starts a variable stepping through each row in the Transactions varaible list.
columns: displayedColumns; - this is a list of columns to display.
This defines a header, and mat-cell represents whats displayed in that column for each row in the transactions.
matColumnDef=”description” - this is the name of the column. In theory these ng-container tags can be in any order. But the order of columns displayed in the table is defined in that displayedColumns variable.
Desc is what is shown on the header row of the table.
mat-cell *matCellDef=”let element” - in the Row Definition we said - “let row” which setups a variable to hold the model for a row. “Let Element” - for this particular container, we are calling that object “element”
- this is the value to display in the column. That is the description of the propery of the object being stepped through.
There are other examples sowing buttons, and formatting of columns using the pipe operator.
The code above is part of the html for the component. Lets look at the code of the component.
In this code you can see we initialized the transactions variable with a list of transactions from the database. We also defined the displayedColumns variable and populated it with the properties we wanted to display in the table, and the order we wanted to display them.
In the above example we fixed standard html table tags and tr and td tabs. The next example uses the Material supplied code.