Commit 5570c2fa3ec91516d4d74d8bac7e34b73b4e8799
1 parent
7794aa6f38
Exists in
master
and in
1 other branch
Paginacion
Showing
2 changed files
with
19 additions
and
21 deletions
Show diff stats
src/js/controller.js
... | ... | @@ -9,10 +9,7 @@ angular.module('focaBusquedaCliente') |
9 | 9 | $scope.filters = ''; |
10 | 10 | $scope.primerBusqueda = false; |
11 | 11 | // pagination |
12 | - $scope.numPerPage = 10; | |
13 | 12 | $scope.currentPage = 1; |
14 | - $scope.filteredClientes = []; | |
15 | - $scope.currentPageClientes = []; | |
16 | 13 | $scope.selectedClientes = -1; |
17 | 14 | $scope.ingreso = false; |
18 | 15 | $scope.regexCuit = new RegExp(/\b(20|23|24|27|30|33|34)(\D)?[0-9]{8}(\D)?[0-9]/g); |
... | ... | @@ -60,8 +57,11 @@ angular.module('focaBusquedaCliente') |
60 | 57 | [funcion]($scope.filters, $scope.vendedor.id) |
61 | 58 | .then( |
62 | 59 | function(res) { |
60 | + console.log(res); | |
63 | 61 | $scope.primerBusqueda = true; |
64 | - $scope.clientes = res.data; | |
62 | + $scope.clientes = res.data.clientes; | |
63 | + $scope.lastPage = res.data.cantidadPaginas; | |
64 | + calcularPages(); | |
65 | 65 | $scope.search(true); |
66 | 66 | primera(); |
67 | 67 | $scope.searchLoading = false; |
... | ... | @@ -81,11 +81,6 @@ angular.module('focaBusquedaCliente') |
81 | 81 | $scope.filters = ''; |
82 | 82 | }); |
83 | 83 | } |
84 | - | |
85 | - $scope.lastPage = Math.ceil( | |
86 | - $scope.filteredClientes.length / $scope.numPerPage | |
87 | - ); | |
88 | - | |
89 | 84 | $scope.resetPage(); |
90 | 85 | } |
91 | 86 | }; |
... | ... | @@ -99,7 +94,7 @@ angular.module('focaBusquedaCliente') |
99 | 94 | var start = (page - 1) * $scope.numPerPage; |
100 | 95 | var end = start + $scope.numPerPage; |
101 | 96 | $scope.paginas = []; |
102 | - $scope.paginas = calcularPages(page); | |
97 | + $scope.paginas = calcularPages(); | |
103 | 98 | $scope.currentPageClientes = $scope.filteredClientes.slice(start, end); |
104 | 99 | $scope.currentPage = page; |
105 | 100 | }; |
... | ... | @@ -498,9 +493,12 @@ angular.module('focaBusquedaCliente') |
498 | 493 | }); |
499 | 494 | }; |
500 | 495 | |
501 | - function calcularPages(paginaActual) { | |
496 | + | |
497 | + | |
498 | + function calcularPages() { | |
502 | 499 | var paginas = []; |
503 | - paginas.push(paginaActual); | |
500 | + var paginaActual = $scope.currentPage; | |
501 | + paginas.push(paginaActual); | |
504 | 502 | |
505 | 503 | if (paginaActual - 1 > 1) { |
506 | 504 | |
... | ... | @@ -529,7 +527,7 @@ angular.module('focaBusquedaCliente') |
529 | 527 | } |
530 | 528 | |
531 | 529 | function primera() { |
532 | - $scope.selectedClientes = 0; | |
530 | + $scope.selectedClientes = 0; | |
533 | 531 | } |
534 | 532 | |
535 | 533 | function anterior() { |
... | ... | @@ -540,11 +538,11 @@ angular.module('focaBusquedaCliente') |
540 | 538 | } |
541 | 539 | } |
542 | 540 | |
543 | - function siguiente() { | |
541 | + function siguiente() { | |
544 | 542 | if ($scope.selectedClientes < $scope.currentPageClientes.length - 1 ) { |
545 | 543 | $scope.selectedClientes++; |
546 | 544 | } else { |
547 | - avanzarPagina(); | |
545 | + avanzarPagina(); | |
548 | 546 | } |
549 | 547 | } |
550 | 548 |
src/views/foca-busqueda-cliente-modal.html
... | ... | @@ -66,18 +66,18 @@ |
66 | 66 | </tr> |
67 | 67 | </thead> |
68 | 68 | <tbody> |
69 | - <tr ng-show="currentPageClientes.length == 0 && primerBusqueda"> | |
69 | + <tr ng-show="clientes.length == 0 && primerBusqueda"> | |
70 | 70 | <td colspan="4"> |
71 | 71 | No se encontraron resultados. |
72 | 72 | </td> |
73 | 73 | </tr> |
74 | 74 | <tr |
75 | 75 | class="selectable" |
76 | - ng-repeat="(key, cliente) in currentPageClientes" | |
76 | + ng-repeat="(key, cliente) in clientes" | |
77 | 77 | ng-click="select(cliente)"> |
78 | - <td ng-bind="('00000'+cliente.cod).slice(-5)"></td> | |
79 | - <td ng-bind="cliente.nom"></td> | |
80 | - <td ng-bind="cliente.cuit"></td> | |
78 | + <td ng-bind="('00000'+cliente.COD).slice(-5)"></td> | |
79 | + <td ng-bind="cliente.NOM"></td> | |
80 | + <td ng-bind="cliente.CUIT"></td> | |
81 | 81 | <td> |
82 | 82 | <button |
83 | 83 | type="button" |
... | ... | @@ -444,7 +444,7 @@ |
444 | 444 | </form> |
445 | 445 | </div> |
446 | 446 | <div class="modal-footer py-1"> |
447 | - <nav ng-show="currentPageClientes.length > 0 && primerBusqueda && !ingreso" class="mr-auto"> | |
447 | + <nav ng-show="clientes.length > 0 && primerBusqueda && !ingreso" class="mr-auto"> | |
448 | 448 | <ul class="pagination pagination-sm mb-0"> |
449 | 449 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> |
450 | 450 | <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage - 1)"> |