27.3K view s 1.3K fork s Files src app index.html Thats why we equals the .data attribute to the .pokemons and .badges of the trainer. To use the accordion, we need to import this module in our app.module.ts: As you can see in the html template, we use two flags that controls our panels: f_firstPanel and f_secondPanel. 33.1K view s 326 fork s. I dont want to go deep in this concept because Im sure there are other articles that will explain it better, I let you one here and please give it a check if you dont know this concept yet: http://www.syntaxsuccess.com/viewarticle/javascript-variable-assignment-explained. Angular 10|9|8 Edit/ Add/ Delete Rows in Material Table with using { kdex: 33, name: 'Nidorino', type: 'Poison' }. We will use also the Expansion Panel in our html template, so when a user edit one trainer the panel of trainer collapse and the panel for editing get expanded. Dont forget to define this new variables: So now, when a user click in the edit, the first panel will collapse and some variables will fill with data of the selected trainer. Open in New Tab Close Sign in Project Info neilnikkunilesh Inline editing in the Angular Material data table Implemented the Mat-Table with the form array in the row. When the event of (click) happen, it will trigger a funtion that we define in our .ts file. Create a new Angular app using Angular CLI and install the latest Angular Material. Lets highlight the important words in the code above. { kdex: 1, name: 'Bulbasaur', type: 'Grass' }. addBadge(): Function that push a new badge and also updates the table of badges. Using FormArray and ngIf on the input field Using FormGroup and Dynamic Component 1) Create a new Angular Project 2) Install Material Package 3) Update App Module 4) Create Material Table 4.1) # Update HTML Template 4.2) # Update App Component Class 5) Create a Dialog Component 5.1) # Update the Dialog Component 6) Also, check 7) Conclusion Create a new Angular Project Why this happens? { name: 'Boulder Badge', giverName: 'Brock', description: 'It is a simple gray octagon' }. And also, we add two buttons at the bottom to cancel the edit and dont save changes and to finish the edit and save it. ng new angular-editable-table ng add @angular/material Create a basic read-only Material table. { kdex: 79, name: 'Slowpoke', type: 'Water' }. import {MatExpansionModule} from '@angular/material/expansion'; . badges: Array of Bage that we use in our select option. New File. link 1. We need to import also this module in the app.module.ts: So, lets check some of the new variables and new functions that we add for this purpose: pokemons: Array of Pokemon that we use in our select option. Tables with dynamic data using Angular and Material - Medium To this point I like to say that you could find all the code for this example in the next link of StackBlitz: https://stackblitz.com/edit/angular-kj6g7p. Our .ts file will look like this until now: Its quite simple, each time we add a pokemon or badge to our trainer, we push the element to the the respective array of the selectedTrainer that will save temporarily the data. import {MatTabsModule} from '@angular/material/tabs'; import { Component, OnInit } from '@angular/core'; import { MatTableDataSource, MatIconRegistry } from '@angular/material'; import { DomSanitizer } from '@angular/platform-browser'; import { PokemonTrainer } from './pokemonTrainer'; // Flags that control the expansion panel. { name: 'Cascade Badge', giverName: 'Misty', description: 'It is in the shape of a light blue raindrop' }. { kdex: 4, name: 'Charmander', type: 'Fire' }. How many of us spent hours in our Game Boys looking for these friends and collecting badges to get to the tournament. The dsTrainers will be a variable that we define in our .ts file, this variable could be an Array of objects or a MatTableDataSource class. Each of us as trainers had a list of pokemon that we were trapping and also a list of badges we got. Dec 23, 2018 -- 3 This article aims to explain one of the best components of Angular Material. Each of them will be used for two tables that will show the list of pokemons and badges per each trainer. Angular Minimal Material Table Action Buttons (forked) Starter project for Angular apps that exports to the Angular CLI. [Part 1] Create an Editable Dynamic Table using Angular Material Clear on reload. this.dsPokemons.data = this.selectedTrainer.pokemons; this.dsBadges.data = this.selectedTrainer.badges; dcPokemons: string[] = ['kdex', 'name', 'type']; dcBadges: string[] = ['name', 'giver', 'description']; this.dsPokemons = new MatTableDataSource(); this.dsBadges = new MatTableDataSource(); , , ,