Angular Material Tutorial - 27 - Data table

Codevolution
22 Apr 201908:48

Summary

TLDRفي هذا الفيديو، نستعرض كيفية تنفيذ جدول بيانات أساسي باستخدام Angular Material. نبدأ بإستيراد الوحدة النمطية 'MatTableModule' ضمن 'material.module.ts'. ثم نتبع بنسخ ولصق كود لجدول بيانات أساسي من وثائق Material، شاملاً HTML، TypeScript، وCSS. نوضح كيفية تجهيز مصدر البيانات وربطه بالجدول، تعريف قوالب الأعمدة وأخيرًا، تحديد الصفوف والعناوين. نهدف إلى تزويد المشاهدين بفهم شامل لتنفيذ جدول بيانات في Angular Material، مع التركيز على الخطوات الأساسية من تعريف مصدر البيانات إلى عرض الصفوف والأعمدة.

Takeaways

  • 📌 الخطوة الأولى في إنشاء جدول بيانات أساسية في Angular Material هي استيراد المودول.
  • 🔍 من خلال استيراد مודول mat table وإضافة Material_ARRAY، يمكننا تضمين جدول البيانات في التطبيق.
  • 💡 نقوم بنسخ الشفرة لجدول البيانات الأساسية من وثائق Angular Material لتوفير الوقت والفهم.
  • 📝 يتم تحديد النوع لكل عنصر في جدول البيانات من خلال تصنيف العناصر الدورية.
  • 🔢 يتم تحديد العناصر الأساسية التي سيتم عرضها في الجدول بواسطة صف الرأس والصفوف.
  • 🎨 يتم استخدام ng container لتحديد العناصر التي لن تظهر في DOM ولكنها توفر عنصر لتطبيق mat column def.
  • 🏗️ يتم تكوين الرأس والصفوف في HTML باستخدام mat-header-row و mat-row مع استخدام mat-columnDefs.
  • 🔑 يتم استخدام الربط الوظيفي (property binding) لربط مصدر البيانات مع الجدول في HTML.
  • 📊 يتم استخدام التكرار (iteration) لاسترداد صفوف الجدول من مصدر البيانات وربطها بالتخطيطات المخصصة.
  • 📈 يمكن استخدام التكرار وструктур التوجيه (structural directives) لعرض الرأس والخلايا الأساسية للجدول.
  • 🚀 بمجرد تشغيل الكود، يجب أن نرى الجدول البيانات يعمل كما يتوقع، مع الرأس والصفوف المطلوبين.

Q & A

  • الخطوة الأولى لإنشاء جدول بيانات أساسي في Angular Material ما هي؟

    -الخطوة الأولى لإنشاء جدول بيانات أساسي في Angular Material هي استيراد المودول، حيث نقوم باستيراد mat-table مodule من material dot module dot es.

  • ماذا نقوم به بعد استيراد المودول؟

    -بعد استيراد المودول، ننسخ الشفرة لجدول البيانات الأساسية ونتفهم الأجزاء المختلفة التي تتحمل العمل của جدول البيانات.

  • كيف يمكننا العثور على المثال اللازم؟

    -يمكننا العثور على المثال اللازم في مستند Material، بالانتقال إلى قسم الكونponents ثم إلى قسم الجدول البيانات والنقر على الرابط في علامة التبويب الأمثلة.

  • ما هي الخطوة التالية بعد نسخ الشفرة؟

    -الخطوة التالية بعد نسخ الشفرة هي فهم الأجزاء المختلفة التي تشكل الجدول البيانات وكيف تعمل.

  • ما هي المصادر اللازمة لإنشاء جدول البيانات؟

    -المصادر اللازمة لإنشاء جدول البيانات هي ال数据源، التي تتضمن البيانات التي سيتم عرضها في الجدول.

  • كيف نوفر هذه المصادر اللازمة للجدول؟

    -نحن نوفر هذه المصادر اللازمة للجدول في HTML، من خلال إنشاء جدول بيانات باستخدام mat table component واستخدام صفحة الربط لربط الملكية الموجودة في الفصل العلوي.

  • ماذا تعني ال的定义 ال軒 لجدول البيانات؟

    -تعني التعريف ال軒 للجدول البيانات تعريف ال軒 ال数据، حيث نستخدم الNG container element لتطبيق mat column def directive، وال.directive يحدد ال軒 بشكل فريد.

  • كيف نعرض ال軒 والصفوف في الجدول؟

    -لعرض ال軒 والصفوف في الجدول، نستخدم mat header row component و mat row component، و نستخدم mat header row def و mat row def directives لتحديد ال軒 والصفوف التي سيتم عرضها.

  • كيف نقوم باسترداد البيانات من ال軒 والصفوف؟

    -نستخدم تكرارية لاسترداد الصفوف، ونحصل على مرجع لكل صف، ونستخدم التكسير لربط البيانات مع الرأي.

  • ما هي الخطوات الثلاثة لإنشاء جدول بيانات أساسي في Angular Material؟

    -الخطوات الثلاثة لإنشاء جدول بيانات أساسي في Angular Material هي: تعريف ال数据源 وال軒 المطلوبة، تعريف ال軒 ال軒 التعريفي، وإضافة ال軒 والصفوف.

  • ماذا سنقوم به في الفيديو القادم؟

    -في الفيديو القادم، سنقوم بإجراء بعض التغييرات وسنرى كيف يؤثر ذلك على جدول البيانات، مما سيمنحك فكرة أفضل عن كيفية العملของ الجدول البيانات.

Outlines

00:00

📝 Implementing a Basic Data Table in Angular Material

This paragraph introduces the process of implementing a basic data table in Angular Material. It begins by emphasizing the importance of importing the necessary module, the MatTableModule, and the MatArray module. The paragraph then suggests copying a basic data table code example from the official documentation to understand the different parts responsible for the functioning of a data table. The example uses display flex and provides a step-by-step guide on copying the HTML, TypeScript, and CSS code snippets into their respective component files. The paragraph also explains the importance of having a data source and how to bind it to the table using property binding in the HTML. It introduces the concept of defining an interface for the data structure and an array of elements that conform to this interface. The paragraph concludes by explaining the role of the data source, interface, and array in the data table implementation process.

05:01

🛠️ Defining Column Templates and Row Definitions

This paragraph delves into the specifics of defining column templates and row definitions for the data table. It explains the purpose of the ng container element and the matColumnDef directive, which uniquely identifies a column with a key. The paragraph highlights the use of the matHeaderCellDef and matCellDef structural directives to define how the header and data cells are displayed, respectively. It also discusses the process of iterating through the data rows, accessing their properties, and binding the data to the view using interpolation. The paragraph further clarifies the role of the matHeaderRow and matRow components in defining the table header row and data rows, and how the displayedColumns property is used to determine which columns are shown in the table. The summary emphasizes the three-step process of implementing a data table in Angular Material: defining the data source and columns, creating column templates, and including header and row definitions. It concludes by mentioning that the next video will explore making changes to the data table to provide a better understanding of its workings.

Mindmap

Keywords

💡Angular Material

Angular Material is a UI framework based on Angular that provides a wide range of pre-built, well-designed UI components. In the video, Angular Material is used to implement a data table, showcasing how it simplifies the development process by providing ready-to-use components like the mat-table for displaying tabular data.

💡Data Table

A data table is a user interface element that presents data in a structured format, typically in rows and columns. In the context of the video, the data table is implemented using Angular Material, and it displays information about periodic elements, highlighting the importance of data tables in presenting complex data in an organized and easily digestible manner.

💡Interface

In programming, an interface is a contract that defines the structure of an object, specifying the methods and properties that an object must have. In the video, an interface is used to define the type of each element in the periodic table data, ensuring that each element has a name, position, rate, and symbol.

💡Data Source

A data source is the provider of data for a particular component or system. In the video, the data source for the data table consists of an array of periodic elements, which is used to populate the table with information. The data source is crucial for the functionality of the data table, as it supplies the actual content to be displayed.

💡Property Binding

Property binding is a technique used in Angular to pass data from a component to a template. It allows for the dynamic display of information based on the data in the component. In the video, property binding is used to associate the data source with the mat-table component, ensuring that the table displays the data from the periodic elements array.

💡Column Templates

Column templates in Angular are used to define the layout and display of data in columns within a table. They specify how each column's header and cells should be rendered. In the video, column templates are defined for the position, name, weight, and symbol of the periodic elements, which dictates how this information is presented in the data table.

💡Structural Directives

Structural directives in Angular are used to manipulate the DOM structure based on the component's logic. They allow developers to add, remove, or modify elements in the template based on certain conditions. In the video, structural directives like *matHeaderRowDef and *matRowDef are used to define the header and row structures of the data table, respectively.

💡Interpolation

Interpolation in Angular is a way to insert data from a component into a template. It is done using the double curly braces {{ }} syntax and allows for dynamic content display. In the video, interpolation is used to bind the properties of each periodic element to the corresponding column templates, enabling the display of each element's data in the data table.

💡Mat Header Cell

Mat Header Cell is a structural directive provided by Angular Material that is used to define the header cells of a table. It is responsible for rendering the header of each column in the data table. In the video, the mat-header-cell directive is used to display the static text for the headers of the data table, such as 'Position', 'Name', 'Weight', and 'Symbol'.

💡Mat Cell

Mat Cell is a structural directive from Angular Material used to define the data cells of a table. It is used to display the data associated with each row in the table. In the video, the mat-cell directive is part of the column templates and is used to display the data for each property of the periodic elements in the data table.

💡Flex Layout

Flex layout is a CSS layout model that allows for the creation of flexible and responsive layouts. It is used in the video to position and size the data table within the component's view. The use of display flex in the video ensures that the data table is properly laid out and responsive to different screen sizes.

Highlights

Importing the Angular Material module to implement a basic data table.

Saving time by copying the code for a basic data table from the Angular Material documentation.

Understanding the different parts responsible for the functioning of a data table.

Creating a data source with an array of periodic elements and an interface defining each element's type.

Declaring the interface and data array outside the component for reusability.

Initializing the data source property with element data array.

Providing the data source to the data table using property binding in the HTML.

Defining column templates for the position, name, weight, and symbol columns using ng-container elements.

Using mat-column-def directive to uniquely identify columns with a key.

Applying mat-header-cell and mat-cell components for styling header and data cells without attaching any styling to the elements themselves.

Accessing each row of the data source and binding the data to the view using interpolation.

Iterating through the rows, accessing properties, and displaying them in the column templates.

Defining the table header row with mat-header-row component and specifying displayed columns.

Displaying data rows with mat-row component and exporting a variable containing the data of each row.

Summarizing the three steps in implementing a data table in Angular Material: defining the data source and columns, column templates, and header and row definitions.

Creating a basic data table without writing any new code, and planning to make changes in the next video for a better understanding of the data table's functionality.

Transcripts

00:00

all right in this video let's take a

00:02

look at implementing a basic data table

00:05

in angular material the first step as

00:08

always is to import the module so in

00:11

material dot module dot es import mat

00:15

table module and added to the material

00:17

array

00:19

now what we are going to do to save us

00:23

some time is copy the code for a basic

00:27

data table and then understand the

00:29

different parts that are responsible for

00:32

the functioning of a data table so in

00:35

the material Doc's go to components and

00:38

then to the data table section and click

00:41

on the table link over here in the

00:45

examples tab we have a basic data table

00:49

now go to the second example

00:51

which is basic use of math table and

00:54

uses display flex and click on the code

00:57

icon now let's copy paste the code first

01:02

the HTML so copy and paste it in AB

01:08

component dot HTML next the typescript

01:13

file so go to TS copy the interface and

01:20

the data in AB component TS paste it

01:26

right after the import statement then go

01:31

back to the documentation and copy the

01:34

two lines of code from the component

01:37

class go back to BS code and in app

01:41

component paste them finally copy the

01:46

CSS so we're here CSS and then copy this

01:51

and paste it in AB component dot CSS now

01:57

if we save all the files and take a look

02:00

at the browser you should be able to see

02:03

a data table now let's understand the

02:07

different parts that make up this data

02:10

table the first part to implementing a

02:14

data table is the data source every data

02:18

table needs a data source that contains

02:21

the data to be displayed in our example

02:24

we have the data of periodic elements we

02:28

have an interface that defines the type

02:32

of

02:33

each element so a periodic element will

02:36

have a name position rate and symbol

02:40

right below the interface is where you

02:43

see the array of periodic elements we

02:46

have ten elements each having properties

02:48

mentioned in the interface what you have

02:52

to notice here is that the interface and

02:54

the data array is declared outside the

02:56

component to be able to use it in the

02:59

component we need to create a property

03:01

and initialize it for that purpose we

03:04

have data source which is initialized to

03:07

element data this array right here

03:12

alright the next thing to do is to

03:15

provide this data source to the data

03:17

table and we do that in the HTML so in

03:22

am dot component dot HTML we create a

03:25

data table with mat table component and

03:29

to provide the data source they make use

03:32

of the data source attribute we use

03:35

property binding to bind the property

03:38

defined in the component class so data

03:41

source is equal to element data which is

03:44

provided here so that is the first step

03:49

to implementing a data table creating

03:52

the data source and binding it to the

03:54

table the second step is to define the

03:59

column templates in the browser you can

04:04

see that we have four columns the

04:07

position number name weight and symbol

04:11

in the code we define the four columns

04:14

each inside its own ng container element

04:18

physician name weight and symbol the ng

04:25

container element will not be rendered

04:28

to the Dom but it will provide an

04:30

element for applying this mat column def

04:34

directive the mat column death directive

04:38

is what uniquely identifies a given

04:41

column with a key physician named way

04:46

and symbol inside the ng container

04:51

element we will have all the

04:53

configuration for a given column you can

04:57

see that we have the template that

04:58

defines how to display the header for a

05:00

given column identified using the map

05:04

header cell death structural directive

05:06

we also have another template that

05:09

defines how to display the data cells of

05:12

a given column using the mat cell def

05:15

structural directive the to structural

05:19

directives do not attach any styling to

05:21

the elements the styling is taken care

05:24

of by mat header cell and mat cell

05:29

components next let's talk about the

05:33

content of the heading and the data

05:35

cells for the heading you can see that

05:37

we just have static text number name

05:41

weight and symbol but for the data cell

05:46

we get access to each row of the data

05:50

source we obtain a reference to each row

05:54

and then access the different properties

05:57

of each row we then use interpolation to

06:01

bind the data to the view so in our data

06:04

source we have ten rows we iterate

06:07

through the rows get a reference to each

06:10

row and store it in the element variable

06:13

and then we access the appropriate

06:15

property in the column template so

06:18

element dot position dot name dot weight

06:21

in dot symbol these are the different

06:24

properties for each element

06:28

all right now what we have done so far

06:31

is just define the column template how

06:34

it's supposed to look the final step is

06:37

to define the rows in the data table and

06:40

for that we make use of two more

06:42

components to define the table header

06:46

row we make use of the mat header row

06:49

component and to determine which columns

06:52

have to be displayed in the table mat

06:55

header row death structural directive is

06:58

used to this we assign displayed columns

07:02

property which is an array of columns we

07:06

have mentioned in the component class so

07:08

display columns is an array of strings

07:11

with positioned name weight and symbol

07:17

similarly to display the data rows we

07:20

make use of the mat rope component now

07:24

with mat Perot death structural

07:26

directive we also have a variable

07:28

exported that we have named as row

07:32

containing the data of that given row

07:35

and we have to specify the columns

07:38

property which contains the order in

07:41

which the data cells should be rendered

07:43

again this is displayed columns property

07:47

so when you run this code we should have

07:50

the data table working as expected

07:53

position name weight and symbol and then

07:56

the different rows corresponding to each

07:59

entry or each item in the element array

08:03

so to summarize there are three steps in

08:06

implementing a data table in angular

08:09

material first up define the data source

08:12

and the columns to be displayed second

08:15

step define the column templates and

08:18

finally the third step include the

08:20

header and the row definitions so we are

08:25

able to create a very basic data table

08:27

we copy pasted the code and did not

08:30

really code anything as such so in the

08:33

next video let's also try to make some

08:36

changes and see how that impacts the

08:39

data table that will give you guys a

08:41

much better idea of how the data table

08:44

works I will see you guys in the next

08:46

video

Rate This

5.0 / 5 (0 votes)

العلامات ذات الصلة
تطوير_ويبأングولار_ماتيريالجدول_بياناتبرمجة_وебمستخدم_مبتدئتعليم_تطويرتطوير_أزرارالبيانات_الأساسيةالتصميم_الرسومي