UNPKG

11.5 kBJavaScriptView Raw
1/**
2 * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
3 * @version v18.1.2
4 * @link http://www.ag-grid.com/
5 * @license MIT
6 */
7"use strict";
8var __extends = (this && this.__extends) || (function () {
9 var extendStatics = Object.setPrototypeOf ||
10 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
12 return function (d, b) {
13 extendStatics(d, b);
14 function __() { this.constructor = d; }
15 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16 };
17})();
18var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22 return c > 3 && r && Object.defineProperty(target, key, r), r;
23};
24var __metadata = (this && this.__metadata) || function (k, v) {
25 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
26};
27Object.defineProperty(exports, "__esModule", { value: true });
28var component_1 = require("../../widgets/component");
29var context_1 = require("../../context/context");
30var gridOptionsWrapper_1 = require("../../gridOptionsWrapper");
31var componentAnnotations_1 = require("../../widgets/componentAnnotations");
32var utils_1 = require("../../utils");
33var eventService_1 = require("../../eventService");
34var events_1 = require("../../events");
35var rowRenderer_1 = require("../../rendering/rowRenderer");
36var paginationProxy_1 = require("../paginationProxy");
37var PaginationComp = (function (_super) {
38 __extends(PaginationComp, _super);
39 function PaginationComp() {
40 return _super.call(this) || this;
41 }
42 PaginationComp.prototype.postConstruct = function () {
43 this.setTemplate(this.getTemplate());
44 var isPaging = this.gridOptionsWrapper.isPagination();
45 var paginationPanelEnabled = isPaging && !this.gridOptionsWrapper.isSuppressPaginationPanel();
46 if (!paginationPanelEnabled) {
47 this.setVisible(false);
48 return;
49 }
50 this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_PAGINATION_CHANGED, this.onPaginationChanged.bind(this));
51 this.addDestroyableEventListener(this.btFirst, 'click', this.onBtFirst.bind(this));
52 this.addDestroyableEventListener(this.btLast, 'click', this.onBtLast.bind(this));
53 this.addDestroyableEventListener(this.btNext, 'click', this.onBtNext.bind(this));
54 this.addDestroyableEventListener(this.btPrevious, 'click', this.onBtPrevious.bind(this));
55 this.onPaginationChanged();
56 };
57 PaginationComp.prototype.onPaginationChanged = function () {
58 this.enableOrDisableButtons();
59 this.updateRowLabels();
60 this.setCurrentPageLabel();
61 this.setTotalLabels();
62 };
63 PaginationComp.prototype.setCurrentPageLabel = function () {
64 var pagesExist = this.paginationProxy.getTotalPages() > 0;
65 var currentPage = this.paginationProxy.getCurrentPage();
66 var toDisplay = pagesExist ? currentPage + 1 : 0;
67 this.lbCurrent.innerHTML = this.formatNumber(toDisplay);
68 };
69 PaginationComp.prototype.formatNumber = function (value) {
70 var userFunc = this.gridOptionsWrapper.getPaginationNumberFormatterFunc();
71 if (userFunc) {
72 return userFunc({ value: value });
73 }
74 else {
75 return utils_1._.formatNumberCommas(value);
76 }
77 };
78 PaginationComp.prototype.getTemplate = function () {
79 var localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc();
80 var strPage = localeTextFunc('page', 'Page');
81 var strTo = localeTextFunc('to', 'to');
82 var strOf = localeTextFunc('of', 'of');
83 var strFirst = localeTextFunc('first', 'First');
84 var strPrevious = localeTextFunc('previous', 'Previous');
85 var strNext = localeTextFunc('next', 'Next');
86 var strLast = localeTextFunc('last', 'Last');
87 return "<div class=\"ag-paging-panel ag-font-style\">\n <span ref=\"eSummaryPanel\" class=\"ag-paging-row-summary-panel\">\n <span ref=\"lbFirstRowOnPage\"></span> " + strTo + " <span ref=\"lbLastRowOnPage\"></span> " + strOf + " <span ref=\"lbRecordCount\"></span>\n </span>\n <span class=\"ag-paging-page-summary-panel\">\n <button type=\"button\" class=\"ag-paging-button\" ref=\"btFirst\">" + strFirst + "</button>\n <button type=\"button\" class=\"ag-paging-button\" ref=\"btPrevious\">" + strPrevious + "</button>\n " + strPage + " <span ref=\"lbCurrent\"></span> " + strOf + " <span ref=\"lbTotal\"></span>\n <button type=\"button\" class=\"ag-paging-button\" ref=\"btNext\">" + strNext + "</button>\n <button type=\"button\" class=\"ag-paging-button\" ref=\"btLast\">" + strLast + "</button>\n </span>\n </div>";
88 };
89 PaginationComp.prototype.onBtNext = function () {
90 this.paginationProxy.goToNextPage();
91 };
92 PaginationComp.prototype.onBtPrevious = function () {
93 this.paginationProxy.goToPreviousPage();
94 };
95 PaginationComp.prototype.onBtFirst = function () {
96 this.paginationProxy.goToFirstPage();
97 };
98 PaginationComp.prototype.onBtLast = function () {
99 this.paginationProxy.goToLastPage();
100 };
101 PaginationComp.prototype.enableOrDisableButtons = function () {
102 var currentPage = this.paginationProxy.getCurrentPage();
103 var maxRowFound = this.paginationProxy.isLastPageFound();
104 var totalPages = this.paginationProxy.getTotalPages();
105 var disablePreviousAndFirst = currentPage === 0;
106 this.btPrevious.disabled = disablePreviousAndFirst;
107 this.btFirst.disabled = disablePreviousAndFirst;
108 var zeroPagesToDisplay = this.isZeroPagesToDisplay();
109 var onLastPage = maxRowFound && currentPage === (totalPages - 1);
110 var disableNext = onLastPage || zeroPagesToDisplay;
111 this.btNext.disabled = disableNext;
112 var disableLast = !maxRowFound || zeroPagesToDisplay || currentPage === (totalPages - 1);
113 this.btLast.disabled = disableLast;
114 };
115 PaginationComp.prototype.updateRowLabels = function () {
116 var currentPage = this.paginationProxy.getCurrentPage();
117 var pageSize = this.paginationProxy.getPageSize();
118 var maxRowFound = this.paginationProxy.isLastPageFound();
119 var rowCount = this.paginationProxy.isLastPageFound() ?
120 this.paginationProxy.getTotalRowCount() : null;
121 var startRow;
122 var endRow;
123 if (this.isZeroPagesToDisplay()) {
124 startRow = 0;
125 endRow = 0;
126 }
127 else {
128 startRow = (pageSize * currentPage) + 1;
129 endRow = startRow + pageSize - 1;
130 if (maxRowFound && endRow > rowCount) {
131 endRow = rowCount;
132 }
133 }
134 this.lbFirstRowOnPage.innerHTML = this.formatNumber(startRow);
135 this.lbLastRowOnPage.innerHTML = this.formatNumber(endRow);
136 };
137 PaginationComp.prototype.isZeroPagesToDisplay = function () {
138 var maxRowFound = this.paginationProxy.isLastPageFound();
139 var totalPages = this.paginationProxy.getTotalPages();
140 return maxRowFound && totalPages === 0;
141 };
142 PaginationComp.prototype.setTotalLabels = function () {
143 var lastPageFound = this.paginationProxy.isLastPageFound();
144 var totalPages = this.paginationProxy.getTotalPages();
145 var rowCount = this.paginationProxy.isLastPageFound() ?
146 this.paginationProxy.getTotalRowCount() : null;
147 if (lastPageFound) {
148 this.lbTotal.innerHTML = this.formatNumber(totalPages);
149 this.lbRecordCount.innerHTML = this.formatNumber(rowCount);
150 }
151 else {
152 var moreText = this.gridOptionsWrapper.getLocaleTextFunc()('more', 'more');
153 this.lbTotal.innerHTML = moreText;
154 this.lbRecordCount.innerHTML = moreText;
155 }
156 };
157 __decorate([
158 context_1.Autowired('gridOptionsWrapper'),
159 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
160 ], PaginationComp.prototype, "gridOptionsWrapper", void 0);
161 __decorate([
162 context_1.Autowired('eventService'),
163 __metadata("design:type", eventService_1.EventService)
164 ], PaginationComp.prototype, "eventService", void 0);
165 __decorate([
166 context_1.Autowired('paginationProxy'),
167 __metadata("design:type", paginationProxy_1.PaginationProxy)
168 ], PaginationComp.prototype, "paginationProxy", void 0);
169 __decorate([
170 context_1.Autowired('rowRenderer'),
171 __metadata("design:type", rowRenderer_1.RowRenderer)
172 ], PaginationComp.prototype, "rowRenderer", void 0);
173 __decorate([
174 componentAnnotations_1.RefSelector('btFirst'),
175 __metadata("design:type", HTMLButtonElement)
176 ], PaginationComp.prototype, "btFirst", void 0);
177 __decorate([
178 componentAnnotations_1.RefSelector('btPrevious'),
179 __metadata("design:type", HTMLButtonElement)
180 ], PaginationComp.prototype, "btPrevious", void 0);
181 __decorate([
182 componentAnnotations_1.RefSelector('btNext'),
183 __metadata("design:type", HTMLButtonElement)
184 ], PaginationComp.prototype, "btNext", void 0);
185 __decorate([
186 componentAnnotations_1.RefSelector('btLast'),
187 __metadata("design:type", HTMLButtonElement)
188 ], PaginationComp.prototype, "btLast", void 0);
189 __decorate([
190 componentAnnotations_1.RefSelector('lbRecordCount'),
191 __metadata("design:type", Object)
192 ], PaginationComp.prototype, "lbRecordCount", void 0);
193 __decorate([
194 componentAnnotations_1.RefSelector('lbFirstRowOnPage'),
195 __metadata("design:type", Object)
196 ], PaginationComp.prototype, "lbFirstRowOnPage", void 0);
197 __decorate([
198 componentAnnotations_1.RefSelector('lbLastRowOnPage'),
199 __metadata("design:type", Object)
200 ], PaginationComp.prototype, "lbLastRowOnPage", void 0);
201 __decorate([
202 componentAnnotations_1.RefSelector('eSummaryPanel'),
203 __metadata("design:type", Object)
204 ], PaginationComp.prototype, "eSummaryPanel", void 0);
205 __decorate([
206 componentAnnotations_1.RefSelector('lbCurrent'),
207 __metadata("design:type", Object)
208 ], PaginationComp.prototype, "lbCurrent", void 0);
209 __decorate([
210 componentAnnotations_1.RefSelector('lbTotal'),
211 __metadata("design:type", Object)
212 ], PaginationComp.prototype, "lbTotal", void 0);
213 __decorate([
214 context_1.PostConstruct,
215 __metadata("design:type", Function),
216 __metadata("design:paramtypes", []),
217 __metadata("design:returntype", void 0)
218 ], PaginationComp.prototype, "postConstruct", null);
219 return PaginationComp;
220}(component_1.Component));
221exports.PaginationComp = PaginationComp;