1- import { Component , Inject , forwardRef , Input } from '@angular/core' ;
2- import { DataTable } from './table.component' ;
3- import { PAGINATION_TEMPLATE } from './pagination.template' ;
4- import { PAGINATION_STYLE } from "./pagination.style" ;
1+ import { Component , Inject , forwardRef , Input } from '@angular/core' ;
2+ import { DataTable } from './table.component' ;
3+ import { PAGINATION_TEMPLATE } from './pagination.template' ;
4+ import { PAGINATION_STYLE } from "./pagination.style" ;
55
66
77@Component ( {
88 moduleId : module . id ,
9- selector : 'data-table-pagination' ,
10- template : PAGINATION_TEMPLATE ,
11- styles : [ PAGINATION_STYLE ]
9+ selector : 'data-table-pagination' ,
10+ template : PAGINATION_TEMPLATE ,
11+ styles : [ PAGINATION_STYLE ]
1212} )
1313export class DataTablePagination {
1414
@@ -17,7 +17,8 @@ export class DataTablePagination {
1717 @Input ( ) show_input = false ;
1818 @Input ( ) show_numbers = true ;
1919
20- constructor ( @Inject ( forwardRef ( ( ) => DataTable ) ) public dataTable : DataTable ) { }
20+ constructor ( @Inject ( forwardRef ( ( ) => DataTable ) ) public dataTable : DataTable ) {
21+ }
2122
2223 pageBack ( ) {
2324 this . dataTable . offset -= Math . min ( this . dataTable . limit , this . dataTable . offset ) ;
@@ -55,10 +56,40 @@ export class DataTablePagination {
5556 this . dataTable . page = Number ( < any > value ) ;
5657 }
5758
58- createPageRange ( number ) : any [ ] {
59+ hasPrevious ( number , page ) {
60+ const difference = this . getDifference ( ) ;
61+ if ( ( page - difference ) > 1 ) {
62+ return true ;
63+ }
64+ return false ;
65+ }
66+
67+ hasNext ( number , page ) {
68+ const difference = this . getDifference ( ) ;
69+ if ( ( number - page ) > difference ) {
70+ return true ;
71+ }
72+ return false ;
73+ }
74+
75+ getDifference ( ) {
76+ const difference = 2 ;
77+ return difference ;
78+ }
79+
80+ createPageRange ( number , page ) : any [ ] {
5981 let items : number [ ] = [ ] ;
6082 if ( number > 1 ) {
61- for ( let i = 1 ; i <= number ; i ++ ) {
83+ const difference = this . getDifference ( ) ;
84+ let maxPage = number ;
85+ let minPage = 1 ;
86+ if ( ( number - page ) >= difference ) {
87+ maxPage = page + difference ;
88+ }
89+ if ( ( page - difference ) >= 1 ) {
90+ minPage = page - difference ;
91+ }
92+ for ( let i = minPage ; i <= maxPage ; i ++ ) {
6293 items . push ( i ) ;
6394 }
6495 }
0 commit comments