|
1 | | -import { Component, Inject, forwardRef } 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"; |
5 | 5 |
|
6 | 6 |
|
7 | 7 | @Component({ |
8 | 8 | 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] |
12 | 12 | }) |
13 | 13 | export class DataTablePagination { |
14 | 14 |
|
15 | | - constructor(@Inject(forwardRef(() => DataTable)) public dataTable: DataTable) {} |
| 15 | + @Input() show_range = false; |
| 16 | + @Input() show_limit = false; |
| 17 | + @Input() show_input = false; |
| 18 | + @Input() show_numbers = true; |
| 19 | + |
| 20 | + constructor(@Inject(forwardRef(() => DataTable)) public dataTable: DataTable) { |
| 21 | + } |
16 | 22 |
|
17 | 23 | pageBack() { |
18 | 24 | this.dataTable.offset -= Math.min(this.dataTable.limit, this.dataTable.offset); |
@@ -49,4 +55,44 @@ export class DataTablePagination { |
49 | 55 | set page(value) { |
50 | 56 | this.dataTable.page = Number(<any>value); |
51 | 57 | } |
| 58 | + |
| 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[] { |
| 81 | + let items: number[] = []; |
| 82 | + if (number > 1) { |
| 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++) { |
| 93 | + items.push(i); |
| 94 | + } |
| 95 | + } |
| 96 | + return items; |
| 97 | + } |
52 | 98 | } |
0 commit comments