This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ngb-pagination | |
[collectionSize]="tableDataSource$.value.length" | |
[pageSize]="pageSize$.value" | |
[page]="currentPage$.value" | |
(pageChange)="currentPage$.next($event)"> | |
</ngb-pagination> | |
<table cdk-table [dataSource]="dataOnPage$" class="table table-hover"> | |
<!-- ... -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
combineLatest(this.tableDataSource$, this.currentPage$, this.pageSize$) | |
.subscribe(([allSources, currentPage, pageSize]) => { | |
const startingIndex = (currentPage - 1) * pageSize; | |
const onPage = allSources.slice(startingIndex, startingIndex + pageSize); | |
this.dataOnPage$.next(onPage); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
currentPage$ = new BehaviorSubject<number>(1); | |
pageSize$ = new BehaviorSubject<number>(5); | |
dataOnPage$ = new BehaviorSubject<any[]>([]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BrowserModule } from '@angular/platform-browser'; | |
import { NgModule } from '@angular/core'; | |
import { AppComponent } from './app.component'; | |
import { TableComponent } from './table/table.component'; | |
import {CdkTableModule} from '@angular/cdk/table'; | |
import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; | |
@NgModule({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
levelUp(heroName: string) { | |
const updatedHero = { ... this.heroes$.value[heroName] }; | |
updatedHero.attack = Math.round(updatedHero.attack * (1 + (Math.random() / 8))); | |
updatedHero.defense = Math.round(updatedHero.defense * (1 + (Math.random() / 8))); | |
updatedHero.speed = Math.round(updatedHero.speed * (1 + (Math.random() / 8))); | |
updatedHero.recovery = Math.round(updatedHero.recovery * (1 + (Math.random() / 8))); | |
updatedHero.healing = Math.round(updatedHero.healing * (1 + (Math.random() / 8))); | |
updatedHero.health = Math.round(updatedHero.health * (1 + (Math.random() / 8))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Hero Name Column --> | |
<ng-container cdkColumnDef="attack"> | |
<th cdk-header-cell *cdkHeaderCellDef> Attack </th> | |
<td cdk-cell | |
*cdkCellDef="let row" | |
[ngClass]="{ | |
'table-success': superlatives$.value['highest-attack'] === row.name, | |
'table-danger': superlatives$.value['lowest-attack'] === row.name | |
}"> | |
{{row.attack}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngOnInit() { | |
this.heroes$.subscribe(changedHeroData => { | |
this.tableDataSource$.next(Object.values(changedHeroData)); | |
const superlatives = { | |
'highest-attack': null, | |
'lowest-attack': null, | |
'highest-defense': null, | |
'lowest-defense': null, | |
'highest-speed': null, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>SimpleTable</title> | |
<base href="/"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="icon" type="image/x-icon" href="favicon.ico"> | |
<link rel="stylesheet" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
levelUp(heroName: string) { | |
const updatedHero = { ... this.heroes$.value[heroName] }; | |
updatedHero.attack++; | |
updatedHero.defense++; | |
updatedHero.speed++; | |
updatedHero.recovery++; | |
updatedHero.healing++; | |
updatedHero.health++; | |
const newHeroData = { ... this.heroes$.value }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngOnInit() { | |
this.heroes$.subscribe(changedHeroData => { | |
this.tableDataSource$.next(Object.values(changedHeroData)); | |
}); | |
} |