UNPKG

7.57 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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
9 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11 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;
12 return c > 3 && r && Object.defineProperty(target, key, r), r;
13};
14var __metadata = (this && this.__metadata) || function (k, v) {
15 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16};
17Object.defineProperty(exports, "__esModule", { value: true });
18var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
19var rowNode_1 = require("../entities/rowNode");
20var context_1 = require("../context/context");
21var eventService_1 = require("../eventService");
22var context_2 = require("../context/context");
23var events_1 = require("../events");
24var context_3 = require("../context/context");
25var constants_1 = require("../constants");
26var utils_1 = require("../utils");
27var columnApi_1 = require("../columnController/columnApi");
28var gridApi_1 = require("../gridApi");
29var PinnedRowModel = (function () {
30 function PinnedRowModel() {
31 }
32 PinnedRowModel.prototype.init = function () {
33 this.setPinnedTopRowData(this.gridOptionsWrapper.getPinnedTopRowData());
34 this.setPinnedBottomRowData(this.gridOptionsWrapper.getPinnedBottomRowData());
35 };
36 PinnedRowModel.prototype.isEmpty = function (floating) {
37 var rows = floating === constants_1.Constants.PINNED_TOP ? this.pinnedTopRows : this.pinnedBottomRows;
38 return utils_1.Utils.missingOrEmpty(rows);
39 };
40 PinnedRowModel.prototype.isRowsToRender = function (floating) {
41 return !this.isEmpty(floating);
42 };
43 PinnedRowModel.prototype.getRowAtPixel = function (pixel, floating) {
44 var rows = floating === constants_1.Constants.PINNED_TOP ? this.pinnedTopRows : this.pinnedBottomRows;
45 if (utils_1.Utils.missingOrEmpty(rows)) {
46 return 0; // this should never happen, just in case, 0 is graceful failure
47 }
48 for (var i = 0; i < rows.length; i++) {
49 var rowNode = rows[i];
50 var rowTopPixel = rowNode.rowTop + rowNode.rowHeight - 1;
51 // only need to range check against the top pixel, as we are going through the list
52 // in order, first row to hit the pixel wins
53 if (rowTopPixel >= pixel) {
54 return i;
55 }
56 }
57 return rows.length - 1;
58 };
59 PinnedRowModel.prototype.setPinnedTopRowData = function (rowData) {
60 this.pinnedTopRows = this.createNodesFromData(rowData, true);
61 var event = {
62 type: events_1.Events.EVENT_PINNED_ROW_DATA_CHANGED,
63 api: this.gridApi,
64 columnApi: this.columnApi
65 };
66 this.eventService.dispatchEvent(event);
67 };
68 PinnedRowModel.prototype.setPinnedBottomRowData = function (rowData) {
69 this.pinnedBottomRows = this.createNodesFromData(rowData, false);
70 var event = {
71 type: events_1.Events.EVENT_PINNED_ROW_DATA_CHANGED,
72 api: this.gridApi,
73 columnApi: this.columnApi
74 };
75 this.eventService.dispatchEvent(event);
76 };
77 PinnedRowModel.prototype.createNodesFromData = function (allData, isTop) {
78 var _this = this;
79 var rowNodes = [];
80 if (allData) {
81 var nextRowTop_1 = 0;
82 allData.forEach(function (dataItem, index) {
83 var rowNode = new rowNode_1.RowNode();
84 _this.context.wireBean(rowNode);
85 rowNode.data = dataItem;
86 rowNode.rowPinned = isTop ? constants_1.Constants.PINNED_TOP : constants_1.Constants.PINNED_BOTTOM;
87 rowNode.setRowTop(nextRowTop_1);
88 rowNode.setRowHeight(_this.gridOptionsWrapper.getRowHeightForNode(rowNode));
89 rowNode.setRowIndex(index);
90 nextRowTop_1 += rowNode.rowHeight;
91 rowNodes.push(rowNode);
92 });
93 }
94 return rowNodes;
95 };
96 PinnedRowModel.prototype.getPinnedTopRowData = function () {
97 return this.pinnedTopRows;
98 };
99 PinnedRowModel.prototype.getPinnedBottomRowData = function () {
100 return this.pinnedBottomRows;
101 };
102 PinnedRowModel.prototype.getPinnedTopTotalHeight = function () {
103 return this.getTotalHeight(this.pinnedTopRows);
104 };
105 PinnedRowModel.prototype.getPinnedTopRowCount = function () {
106 return this.pinnedTopRows ? this.pinnedTopRows.length : 0;
107 };
108 PinnedRowModel.prototype.getPinnedBottomRowCount = function () {
109 return this.pinnedBottomRows ? this.pinnedBottomRows.length : 0;
110 };
111 PinnedRowModel.prototype.getPinnedTopRow = function (index) {
112 return this.pinnedTopRows[index];
113 };
114 PinnedRowModel.prototype.getPinnedBottomRow = function (index) {
115 return this.pinnedBottomRows[index];
116 };
117 PinnedRowModel.prototype.forEachPinnedTopRow = function (callback) {
118 if (utils_1.Utils.missingOrEmpty(this.pinnedTopRows)) {
119 return;
120 }
121 this.pinnedTopRows.forEach(callback);
122 };
123 PinnedRowModel.prototype.forEachPinnedBottomRow = function (callback) {
124 if (utils_1.Utils.missingOrEmpty(this.pinnedBottomRows)) {
125 return;
126 }
127 this.pinnedBottomRows.forEach(callback);
128 };
129 PinnedRowModel.prototype.getPinnedBottomTotalHeight = function () {
130 return this.getTotalHeight(this.pinnedBottomRows);
131 };
132 PinnedRowModel.prototype.getTotalHeight = function (rowNodes) {
133 if (!rowNodes || rowNodes.length === 0) {
134 return 0;
135 }
136 else {
137 var lastNode = rowNodes[rowNodes.length - 1];
138 return lastNode.rowTop + lastNode.rowHeight;
139 }
140 };
141 __decorate([
142 context_2.Autowired('gridOptionsWrapper'),
143 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
144 ], PinnedRowModel.prototype, "gridOptionsWrapper", void 0);
145 __decorate([
146 context_2.Autowired('eventService'),
147 __metadata("design:type", eventService_1.EventService)
148 ], PinnedRowModel.prototype, "eventService", void 0);
149 __decorate([
150 context_2.Autowired('context'),
151 __metadata("design:type", context_1.Context)
152 ], PinnedRowModel.prototype, "context", void 0);
153 __decorate([
154 context_2.Autowired('columnApi'),
155 __metadata("design:type", columnApi_1.ColumnApi)
156 ], PinnedRowModel.prototype, "columnApi", void 0);
157 __decorate([
158 context_2.Autowired('gridApi'),
159 __metadata("design:type", gridApi_1.GridApi)
160 ], PinnedRowModel.prototype, "gridApi", void 0);
161 __decorate([
162 context_3.PostConstruct,
163 __metadata("design:type", Function),
164 __metadata("design:paramtypes", []),
165 __metadata("design:returntype", void 0)
166 ], PinnedRowModel.prototype, "init", null);
167 PinnedRowModel = __decorate([
168 context_1.Bean('pinnedRowModel')
169 ], PinnedRowModel);
170 return PinnedRowModel;
171}());
172exports.PinnedRowModel = PinnedRowModel;