Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { DaoMockService } from '../../services/dao/dao-mock.service';
  3. import { MatTableDataSource, } from '@angular/material';
  4.  
  5.  
  6. @Component({
  7. selector: 'app-dynamic-table',
  8. templateUrl: './dynamic-table.component.html',
  9. styleUrls: ['./dynamic-table.component.css']
  10. })
  11. export class DynamicTableComponent implements OnInit {
  12.  
  13. data;
  14.  
  15. model =
  16. {
  17. label: "Table label",
  18. extra: [
  19. "edit",
  20. "select"
  21. ],
  22. columns: [
  23. 'color',
  24. 'desde',
  25. 'nombre'
  26. ]
  27. }
  28.  
  29. dataFields: any[] = this.model.columns
  30. tableColumns: any[] = this.model.columns
  31.  
  32.  
  33. constructor(private dao: DaoMockService) { }
  34.  
  35. ngOnInit() {
  36. this.createTable()
  37. }
  38.  
  39. createTable() {
  40.  
  41. console.log("dataFields --->", this.dataFields)
  42. // output:
  43. // dataFields ---> (3) ["color", "desde", "nombre"]
  44.  
  45. console.log("tableColumns --->",this.tableColumns)
  46. // output:
  47. // tableColumns ---> (3) ["color", "desde", "nombre"]
  48.  
  49. this.tableColumns.unshift("edit")
  50.  
  51. console.log("dataFields --->", this.dataFields)
  52. // output:
  53. // dataFields ---> (4) ["color", "desde", "nombre", "edit"]
  54.  
  55. console.log("tableColumns --->",this.tableColumns)
  56. // output:
  57. // tableColumns ---> (4) ["color", "desde", "nombre", "edit"]
  58.  
  59. this.dao.getAll().subscribe( (res:any) => this.data = new MatTableDataSource(res.data.content))
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement