UNPKG

13.6 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 beanStub_1 = require("../context/beanStub");
29var eventService_1 = require("../eventService");
30var events_1 = require("../events");
31var utils_1 = require("../utils");
32var context_1 = require("../context/context");
33var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
34var scrollVisibleService_1 = require("../gridPanel/scrollVisibleService");
35var selectionController_1 = require("../selectionController");
36var columnApi_1 = require("../columnController/columnApi");
37var gridApi_1 = require("../gridApi");
38var PaginationAutoPageSizeService = (function (_super) {
39 __extends(PaginationAutoPageSizeService, _super);
40 function PaginationAutoPageSizeService() {
41 return _super !== null && _super.apply(this, arguments) || this;
42 }
43 PaginationAutoPageSizeService.prototype.registerGridComp = function (gridPanel) {
44 this.gridPanel = gridPanel;
45 this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_BODY_HEIGHT_CHANGED, this.onBodyHeightChanged.bind(this));
46 this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_SCROLL_VISIBILITY_CHANGED, this.onScrollVisibilityChanged.bind(this));
47 this.checkPageSize();
48 };
49 PaginationAutoPageSizeService.prototype.notActive = function () {
50 return !this.gridOptionsWrapper.isPaginationAutoPageSize();
51 };
52 PaginationAutoPageSizeService.prototype.onScrollVisibilityChanged = function () {
53 this.checkPageSize();
54 };
55 PaginationAutoPageSizeService.prototype.onBodyHeightChanged = function () {
56 this.checkPageSize();
57 };
58 PaginationAutoPageSizeService.prototype.checkPageSize = function () {
59 if (this.notActive()) {
60 return;
61 }
62 var rowHeight = this.gridOptionsWrapper.getRowHeightAsNumber();
63 var bodyHeight = this.gridPanel.getBodyHeight();
64 if (this.scrollVisibleService.isBodyHorizontalScrollShowing()) {
65 bodyHeight = bodyHeight - this.gridOptionsWrapper.getScrollbarWidth();
66 }
67 if (bodyHeight > 0) {
68 var newPageSize = Math.floor(bodyHeight / rowHeight);
69 this.gridOptionsWrapper.setProperty('paginationPageSize', newPageSize);
70 }
71 };
72 __decorate([
73 context_1.Autowired('eventService'),
74 __metadata("design:type", eventService_1.EventService)
75 ], PaginationAutoPageSizeService.prototype, "eventService", void 0);
76 __decorate([
77 context_1.Autowired('gridOptionsWrapper'),
78 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
79 ], PaginationAutoPageSizeService.prototype, "gridOptionsWrapper", void 0);
80 __decorate([
81 context_1.Autowired('scrollVisibleService'),
82 __metadata("design:type", scrollVisibleService_1.ScrollVisibleService)
83 ], PaginationAutoPageSizeService.prototype, "scrollVisibleService", void 0);
84 PaginationAutoPageSizeService = __decorate([
85 context_1.Bean('paginationAutoPageSizeService')
86 ], PaginationAutoPageSizeService);
87 return PaginationAutoPageSizeService;
88}(beanStub_1.BeanStub));
89exports.PaginationAutoPageSizeService = PaginationAutoPageSizeService;
90var PaginationProxy = (function (_super) {
91 __extends(PaginationProxy, _super);
92 function PaginationProxy() {
93 var _this = _super !== null && _super.apply(this, arguments) || this;
94 _this.currentPage = 0;
95 _this.topRowIndex = 0;
96 _this.bottomRowIndex = 0;
97 _this.pixelOffset = 0;
98 return _this;
99 }
100 PaginationProxy.prototype.postConstruct = function () {
101 this.active = this.gridOptionsWrapper.isPagination();
102 this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_MODEL_UPDATED, this.onModelUpdated.bind(this));
103 this.addDestroyableEventListener(this.gridOptionsWrapper, 'paginationPageSize', this.onModelUpdated.bind(this));
104 this.onModelUpdated();
105 };
106 PaginationProxy.prototype.isLastRowFound = function () {
107 return this.rowModel.isLastRowFound();
108 };
109 PaginationProxy.prototype.onModelUpdated = function (modelUpdatedEvent) {
110 this.setIndexesAndBounds();
111 var paginationChangedEvent = {
112 type: events_1.Events.EVENT_PAGINATION_CHANGED,
113 animate: modelUpdatedEvent ? modelUpdatedEvent.animate : false,
114 newData: modelUpdatedEvent ? modelUpdatedEvent.newData : false,
115 newPage: modelUpdatedEvent ? modelUpdatedEvent.newPage : false,
116 keepRenderedRows: modelUpdatedEvent ? modelUpdatedEvent.keepRenderedRows : false,
117 api: this.gridApi,
118 columnApi: this.columnApi
119 };
120 this.eventService.dispatchEvent(paginationChangedEvent);
121 };
122 PaginationProxy.prototype.goToPage = function (page) {
123 if (!this.active) {
124 return;
125 }
126 if (this.currentPage === page) {
127 return;
128 }
129 this.currentPage = page;
130 var event = {
131 type: events_1.Events.EVENT_MODEL_UPDATED,
132 animate: false,
133 keepRenderedRows: false,
134 newData: false,
135 newPage: true,
136 api: this.gridApi,
137 columnApi: this.columnApi
138 };
139 this.onModelUpdated(event);
140 };
141 PaginationProxy.prototype.getPixelOffset = function () {
142 return this.pixelOffset;
143 };
144 PaginationProxy.prototype.getRow = function (index) {
145 return this.rowModel.getRow(index);
146 };
147 PaginationProxy.prototype.getRowNode = function (id) {
148 return this.rowModel.getRowNode(id);
149 };
150 PaginationProxy.prototype.getRowIndexAtPixel = function (pixel) {
151 return this.rowModel.getRowIndexAtPixel(pixel);
152 };
153 PaginationProxy.prototype.getCurrentPageHeight = function () {
154 if (utils_1._.missing(this.topRowBounds) || utils_1._.missing(this.bottomRowBounds)) {
155 return 0;
156 }
157 return this.bottomRowBounds.rowTop + this.bottomRowBounds.rowHeight - this.topRowBounds.rowTop;
158 };
159 PaginationProxy.prototype.isRowPresent = function (rowNode) {
160 if (!this.rowModel.isRowPresent(rowNode)) {
161 return false;
162 }
163 var nodeIsInPage = rowNode.rowIndex >= this.topRowIndex && rowNode.rowIndex <= this.bottomRowIndex;
164 return nodeIsInPage;
165 };
166 PaginationProxy.prototype.isEmpty = function () {
167 return this.rowModel.isEmpty();
168 };
169 PaginationProxy.prototype.isRowsToRender = function () {
170 return this.rowModel.isRowsToRender();
171 };
172 PaginationProxy.prototype.getNodesInRangeForSelection = function (firstInRange, lastInRange) {
173 return this.rowModel.getNodesInRangeForSelection(firstInRange, lastInRange);
174 };
175 PaginationProxy.prototype.forEachNode = function (callback) {
176 return this.rowModel.forEachNode(callback);
177 };
178 PaginationProxy.prototype.getType = function () {
179 return this.rowModel.getType();
180 };
181 PaginationProxy.prototype.getRowBounds = function (index) {
182 return this.rowModel.getRowBounds(index);
183 };
184 PaginationProxy.prototype.getPageFirstRow = function () {
185 return this.pageSize * this.currentPage;
186 };
187 PaginationProxy.prototype.getPageLastRow = function () {
188 var totalLastRow = (this.pageSize * (this.currentPage + 1)) - 1;
189 var pageLastRow = this.rowModel.getPageLastRow();
190 if (pageLastRow > totalLastRow) {
191 return totalLastRow;
192 }
193 else {
194 return pageLastRow;
195 }
196 };
197 PaginationProxy.prototype.getRowCount = function () {
198 return this.rowModel.getRowCount();
199 };
200 PaginationProxy.prototype.goToPageWithIndex = function (index) {
201 if (!this.active) {
202 return;
203 }
204 var pageNumber = Math.floor(index / this.pageSize);
205 this.goToPage(pageNumber);
206 };
207 PaginationProxy.prototype.getTotalRowCount = function () {
208 return this.rowModel.getPageLastRow() + 1;
209 };
210 PaginationProxy.prototype.isLastPageFound = function () {
211 return this.rowModel.isLastRowFound();
212 };
213 PaginationProxy.prototype.getCurrentPage = function () {
214 return this.currentPage;
215 };
216 PaginationProxy.prototype.goToNextPage = function () {
217 this.goToPage(this.currentPage + 1);
218 };
219 PaginationProxy.prototype.goToPreviousPage = function () {
220 this.goToPage(this.currentPage - 1);
221 };
222 PaginationProxy.prototype.goToFirstPage = function () {
223 this.goToPage(0);
224 };
225 PaginationProxy.prototype.goToLastPage = function () {
226 var rowCount = this.rowModel.getPageLastRow() + 1;
227 var lastPage = Math.floor(rowCount / this.pageSize);
228 this.goToPage(lastPage);
229 };
230 PaginationProxy.prototype.getPageSize = function () {
231 return this.pageSize;
232 };
233 PaginationProxy.prototype.getTotalPages = function () {
234 return this.totalPages;
235 };
236 PaginationProxy.prototype.setPageSize = function () {
237 // show put this into super class
238 this.pageSize = this.gridOptionsWrapper.getPaginationPageSize();
239 if (!(this.pageSize >= 1)) {
240 this.pageSize = 100;
241 }
242 };
243 PaginationProxy.prototype.setIndexesAndBounds = function () {
244 if (this.active) {
245 this.setPageSize();
246 var totalRowCount = this.getTotalRowCount();
247 this.totalPages = Math.floor((totalRowCount - 1) / this.pageSize) + 1;
248 if (this.currentPage >= this.totalPages) {
249 this.currentPage = this.totalPages - 1;
250 }
251 if (!utils_1._.isNumeric(this.currentPage) || this.currentPage < 0) {
252 this.currentPage = 0;
253 }
254 this.topRowIndex = this.pageSize * this.currentPage;
255 this.bottomRowIndex = (this.pageSize * (this.currentPage + 1)) - 1;
256 var maxRowAllowed = this.rowModel.getPageLastRow();
257 if (this.bottomRowIndex > maxRowAllowed) {
258 this.bottomRowIndex = maxRowAllowed;
259 }
260 }
261 else {
262 this.pageSize = this.rowModel.getPageLastRow() + 1;
263 this.totalPages = 1;
264 this.currentPage = 0;
265 this.topRowIndex = 0;
266 this.bottomRowIndex = this.rowModel.getPageLastRow();
267 }
268 this.topRowBounds = this.rowModel.getRowBounds(this.topRowIndex);
269 this.bottomRowBounds = this.rowModel.getRowBounds(this.bottomRowIndex);
270 this.pixelOffset = utils_1._.exists(this.topRowBounds) ? this.topRowBounds.rowTop : 0;
271 };
272 __decorate([
273 context_1.Autowired('rowModel'),
274 __metadata("design:type", Object)
275 ], PaginationProxy.prototype, "rowModel", void 0);
276 __decorate([
277 context_1.Autowired('eventService'),
278 __metadata("design:type", eventService_1.EventService)
279 ], PaginationProxy.prototype, "eventService", void 0);
280 __decorate([
281 context_1.Autowired('gridOptionsWrapper'),
282 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
283 ], PaginationProxy.prototype, "gridOptionsWrapper", void 0);
284 __decorate([
285 context_1.Autowired('selectionController'),
286 __metadata("design:type", selectionController_1.SelectionController)
287 ], PaginationProxy.prototype, "selectionController", void 0);
288 __decorate([
289 context_1.Autowired('columnApi'),
290 __metadata("design:type", columnApi_1.ColumnApi)
291 ], PaginationProxy.prototype, "columnApi", void 0);
292 __decorate([
293 context_1.Autowired('gridApi'),
294 __metadata("design:type", gridApi_1.GridApi)
295 ], PaginationProxy.prototype, "gridApi", void 0);
296 __decorate([
297 context_1.PostConstruct,
298 __metadata("design:type", Function),
299 __metadata("design:paramtypes", []),
300 __metadata("design:returntype", void 0)
301 ], PaginationProxy.prototype, "postConstruct", null);
302 PaginationProxy = __decorate([
303 context_1.Bean('paginationProxy')
304 ], PaginationProxy);
305 return PaginationProxy;
306}(beanStub_1.BeanStub));
307exports.PaginationProxy = PaginationProxy;