Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. import { Component, OnInit, ViewChild, ChangeDetectorRef } from '@angular/core';
  2. import { CatalogosService } from 'src/app/services/catalogos.service';
  3. import { MatPaginator, MatSort, MatTableDataSource, MatTableModule, MatTable,
  4. MatDialog, MatDialogConfig, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
  5. import { Response } from 'src/app/classes/response';
  6.  
  7. @Component({
  8. selector: 'app-lista-proveedores',
  9. templateUrl: './lista-proveedores.component.html',
  10. styleUrls: ['./lista-proveedores.component.css']
  11. })
  12. export class ListaProveedoresComponent implements OnInit {
  13.  
  14. proveedores: any[];
  15. listData: MatTableDataSource<any>;
  16. displayColumns: string[]=['id','nombre','acciones'];
  17. searchKey: string;
  18. //spinner: SpinnerComponent= new SpinnerComponent;
  19. @ViewChild(MatSort) sort: MatSort;
  20. @ViewChild(MatPaginator) paginator: MatPaginator;
  21.  
  22. constructor(private proveedorService: CatalogosService,
  23. private dialog: MatDialog,
  24. private changeDetectorRefs: ChangeDetectorRef) { }
  25.  
  26. ngOnInit() {
  27. this.getRecords();
  28. }
  29.  
  30. getRecords(): void{
  31. this.proveedorService.getItems()
  32. .subscribe(
  33. (response: Response) => {
  34. //this.proveedores = response.object;
  35. this.listData= new MatTableDataSource(response.object);
  36. this.listData.sort= this.sort;
  37. this.listData.paginator= this.paginator;
  38. console.log("List data: ", this.sort);
  39. });
  40. this.changeDetectorRefs.detectChanges();
  41. }
  42.  
  43. }
  44.  
  45. <div class="col-lg-12">
  46. <div class="row">
  47. <div class="col-lg-9 text-center">
  48. <h3 class="title-divider">
  49. <span>List</span>
  50. </h3>
  51. </div>
  52. <div class="col-lg-3 text-center">
  53. &nbsp;
  54. </div>
  55. </div>
  56. <div class="row">
  57. <div class="col-lg-12">
  58. <div class="mat-elevation-z8">
  59. <mat-table #table [dataSource]="listData" matSort>
  60. <ng-container matColumnDef="id">
  61. <mat-header-cell *matHeaderCellDef mat-sort-header>ID</mat-header-cell>
  62. <mat-cell *matCellDef="let element">{{element.ID}}</mat-cell>
  63. </ng-container>
  64. <ng-container matColumnDef="nombre">
  65. <mat-header-cell *matHeaderCellDef mat-sort-header>Nombre</mat-header-cell>
  66. <mat-cell *matCellDef="let element">{{element.Name}}</mat-cell>
  67. </ng-container>
  68. <ng-container matColumnDef="acciones">
  69. <mat-header-cell *matHeaderCellDef>Acciones</mat-header-cell>
  70. <mat-cell *matCellDef="let row">
  71. <button mat-icon-button (click)="onDetail(row)"><mat-icon>details</mat-icon></button>
  72. <button mat-icon-button (click)="onEdit(row)"><mat-icon>launch</mat-icon></button>
  73. <button mat-icon-button color="warn" (click)="onDelete(row)"><mat-icon>delete_outline</mat-icon></button>
  74. </mat-cell>
  75. </ng-container>
  76. <ng-container matColumnDef="loading">
  77. <mat-footer-cell *matFooterCellDef colspan="6">
  78. Loading data
  79. </mat-footer-cell>
  80. </ng-container>
  81. <ng-container matColumnDef="noData">
  82. <mat-footer-cell *matFooterCellDef colspan="6">
  83. No data
  84. </mat-footer-cell>
  85. </ng-container>
  86. <mat-header-row *matHeaderRowDef="displayColumns; sticky:true "></mat-header-row>
  87. <mat-row *matRowDef="let row; columns: displayColumns"></mat-row>
  88. <mat-footer-row *matFooterRowDef="['loading']" [ngClass]="{'hide':listData!=null}"></mat-footer-row>
  89. <mat-footer-row *matFooterRowDef="['noData']" [ngClass]="{'hide':!(listData!=null && listData.data.length==0)}"></mat-footer-row>
  90. </mat-table>
  91. <mat-paginator [pageSizeOptions]="[5, 10, 15, 25]" [pageSize]="5" showFirstLastButtons></mat-paginator>
  92. </div>
  93. </div>
  94. </div>
  95.  
  96. </div>
  97.  
  98. MatSort {_disabled: false, _isInitialized: true, _pendingSubscribers: null, initialized: Observable, sortables: Map(2), …}
  99. direction: (...)
  100. disableClear: (...)
  101. disabled: (...)
  102. initialized: Observable
  103. _isScalar: false
  104. _subscribe: ƒ (subscriber)
  105. arguments: (...)
  106. caller: (...)
  107. length: 1
  108. name: ""
  109. prototype: {constructor: ƒ}
  110. __proto__: ƒ ()
  111. [[FunctionLocation]]: core.es5.js:474
  112. [[Scopes]]: Scopes[4]
  113. __proto__: Object
  114. sortChange: EventEmitter
  115. closed: false
  116. hasError: false
  117. isStopped: false
  118. observers: (3) [Subscriber, Subscriber, Subscriber]
  119. thrownError: null
  120. __isAsync: false
  121. _isScalar: false
  122. __proto__: Subject
  123. sortables: Map(2)
  124. size: (...)
  125. __proto__: Map
  126. [[Entries]]: Array(2)
  127. 0: {"id" => MatSortHeader}
  128. 1: {"nombre" => MatSortHeader}
  129. length: 2
  130. start: "asc"
  131. _direction: ""
  132. _disabled: false
  133. _isInitialized: true
  134. _pendingSubscribers: null
  135. _stateChanges: Subject {_isScalar: false, observers: Array(2), closed: false, isStopped: false, hasError: false, …}
  136. __proto__: class_1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement