Commit a361ae9bc10a15961a9ad5ebc77965da47183862
1 parent
bf509b731c
Exists in
master
paginación ok
Showing
2 changed files
with
35 additions
and
22 deletions
Show diff stats
src/app/comprobantes/comprobantes.component.html
| ... | ... | @@ -74,25 +74,27 @@ |
| 74 | 74 | </tr> |
| 75 | 75 | </thead> |
| 76 | 76 | <tbody> |
| 77 | - <tr *ngFor="let articulo of articulosFiltro" [ngClass]="{'bg-success': articulo.done}"> | |
| 77 | + <tr *ngFor="let articulo of getPaginaFiltro()" [ngClass]="{'bg-success': articulo.done}"> | |
| 78 | 78 | <th><button type="button" class="" (click)="articulo.input = true"> |
| 79 | 79 | <i class="fa fa-window-close"></i> |
| 80 | 80 | </button></th> |
| 81 | 81 | <th>{{articulo.LI0}}</th> |
| 82 | - <th *ngIf="!articulo.input">{{articulo.CAN}}</th> | |
| 82 | + <th *ngIf="!articulo.input">{{articulo.CAN}}/{{articulo.CAN}}</th> | |
| 83 | 83 | <th *ngIf="articulo.input"> |
| 84 | 84 | <input class="form-control-sm col-12"/> |
| 85 | 85 | </th> |
| 86 | - <th><button type="button" class="" (click)="articulo.done = true"> | |
| 87 | - <i class="fa fa-check"></i> | |
| 88 | - </button></th> | |
| 86 | + <th> | |
| 87 | + <button type="button" class="" (click)="articulo.done = true"> | |
| 88 | + <i class="fa fa-check"></i> | |
| 89 | + </button> | |
| 90 | + </th> | |
| 89 | 91 | </tr> |
| 90 | 92 | </tbody> |
| 91 | 93 | <tfoot> |
| 92 | 94 | <nav *ngIf="articulosFiltro.length > 0" class="mr-auto"> |
| 93 | 95 | <ul class="pagination pagination-sm justify-content mb-0"> |
| 94 | - <li class="page-item" [ngClass]="{'disabled': pagina == 1}"> | |
| 95 | - <a class="page-link" href="javascript:void();" (click)="paginar(articulosFiltro); pagina - 1"> | |
| 96 | + <li class="page-item" [ngClass]="{'disabled': paginaActiva == 1}"> | |
| 97 | + <a class="page-link" href="javascript:void();" (click)="paginaActiva = paginaActiva - 1"> | |
| 96 | 98 | <span aria-hidden="true">«</span> |
| 97 | 99 | <span class="sr-only">Anterior</span> |
| 98 | 100 | </a> |
| ... | ... | @@ -100,16 +102,16 @@ |
| 100 | 102 | <li |
| 101 | 103 | class="page-item" |
| 102 | 104 | *ngFor="let pagina of paginas; index as i" |
| 103 | - [ngClass]="{'active': pagina == currentPage}" | |
| 105 | + [ngClass]="{'active': pagina == paginaActiva}" | |
| 104 | 106 | > |
| 105 | 107 | <a |
| 106 | 108 | class="page-link" |
| 107 | 109 | href="javascript:void();" |
| 108 | - (click)="selectPage(pagina)" | |
| 110 | + (click)="paginaActiva = pagina" | |
| 109 | 111 | >{{pagina}}</a> |
| 110 | 112 | </li> |
| 111 | - <li class="page-item" [ngClass]="{'disabled': currentPage == lastPage}"> | |
| 112 | - <a class="page-link" href="javascript:void();" (click)="paginar(articulosFiltro); pagina + 1"> | |
| 113 | + <li class="page-item" [ngClass]="{'disabled': paginaActiva == paginas.length}"> | |
| 114 | + <a class="page-link" href="javascript:void();" (click)="paginaActiva = paginaActiva + 1"> | |
| 113 | 115 | <span aria-hidden="true">»</span> |
| 114 | 116 | <span class="sr-only">Siguiente</span> |
| 115 | 117 | </a> |
src/app/comprobantes/comprobantes.component.ts
| ... | ... | @@ -11,7 +11,7 @@ export class ComprobantesComponent implements OnInit { |
| 11 | 11 | |
| 12 | 12 | ngOnInit() { |
| 13 | 13 | |
| 14 | - this.obtenerConsulta() | |
| 14 | + this.obtenerConsulta(); | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | filter = ''; |
| ... | ... | @@ -19,23 +19,33 @@ export class ComprobantesComponent implements OnInit { |
| 19 | 19 | cabecera = {}; |
| 20 | 20 | cuerpo = []; |
| 21 | 21 | articulosFiltro = []; |
| 22 | - pagina = 1; | |
| 22 | + paginaActiva = 1; | |
| 23 | 23 | paginas = []; |
| 24 | 24 | |
| 25 | 25 | fecha = new Date(); |
| 26 | 26 | |
| 27 | 27 | filtrar(event: any) { |
| 28 | - var filtro = this.cuerpo.filter((param)=> { | |
| 29 | - return (param.LI0).toLocaleUpperCase().includes((event.target.value).toLocaleUpperCase()); | |
| 28 | + this.articulosFiltro = this.cuerpo.filter((param)=> { | |
| 29 | + return (param.LI0).toLocaleUpperCase().includes( | |
| 30 | + (event.target.value).toLocaleUpperCase()) || | |
| 31 | + param.codigoBarras == event.target.value; | |
| 30 | 32 | }); |
| 31 | 33 | |
| 32 | - this.paginar(filtro, this.pagina); | |
| 33 | - this.paginas.length = Math.round(filtro.length / 5); | |
| 34 | + this.paginar(); | |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | - paginar(filtro: any, pagina: any) { | |
| 37 | - this.articulosFiltro = filtro.slice( | |
| 38 | - filtro.length - 1 * pagina, filtro.length * this.pagina + 4); | |
| 37 | + paginar() { | |
| 38 | + | |
| 39 | + var cantPaginas = Math.round(this.articulosFiltro.length / 5) + 1; | |
| 40 | + this.paginas = []; | |
| 41 | + for (let i = 0; i < cantPaginas; i++) { | |
| 42 | + this.paginas.push(i + 1); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + getPaginaFiltro() { | |
| 47 | + return this.articulosFiltro.slice( | |
| 48 | + (this.paginaActiva - 1) * 5 , this.paginaActiva * 5); | |
| 39 | 49 | } |
| 40 | 50 | |
| 41 | 51 | obtenerConsulta() { |
| ... | ... | @@ -55,7 +65,8 @@ export class ComprobantesComponent implements OnInit { |
| 55 | 65 | this.cuerpo = [ |
| 56 | 66 | { |
| 57 | 67 | LI0: 'Mantel Combo Bolso CocaCola', |
| 58 | - CAN: 5 | |
| 68 | + CAN: 5, | |
| 69 | + codigoBarras: '7790667006462' | |
| 59 | 70 | }, |
| 60 | 71 | { |
| 61 | 72 | LI0: 'Papas', |
| ... | ... | @@ -85,7 +96,7 @@ export class ComprobantesComponent implements OnInit { |
| 85 | 96 | |
| 86 | 97 | this.articulosFiltro = this.cuerpo; |
| 87 | 98 | |
| 88 | - this.paginar(this.articulosFiltro); | |
| 99 | + this.paginar(); | |
| 89 | 100 | }, 500); |
| 90 | 101 | } |
| 91 | 102 |