UNPKG

9.62 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 gridOptionsWrapper_1 = require("../gridOptionsWrapper");
29var columnController_1 = require("../columnController/columnController");
30var column_1 = require("../entities/column");
31var context_1 = require("../context/context");
32var headerContainer_1 = require("./headerContainer");
33var eventService_1 = require("../eventService");
34var events_1 = require("../events");
35var scrollVisibleService_1 = require("../gridPanel/scrollVisibleService");
36var component_1 = require("../widgets/component");
37var componentAnnotations_1 = require("../widgets/componentAnnotations");
38var utils_1 = require("../utils");
39var gridApi_1 = require("../gridApi");
40var autoWidthCalculator_1 = require("../rendering/autoWidthCalculator");
41var HeaderRootComp = (function (_super) {
42 __extends(HeaderRootComp, _super);
43 function HeaderRootComp() {
44 return _super.call(this, HeaderRootComp.TEMPLATE) || this;
45 }
46 HeaderRootComp.prototype.registerGridComp = function (gridPanel) {
47 this.gridPanel = gridPanel;
48 this.centerContainer.registerGridComp(gridPanel);
49 this.pinnedLeftContainer.registerGridComp(gridPanel);
50 this.pinnedRightContainer.registerGridComp(gridPanel);
51 };
52 HeaderRootComp.prototype.postConstruct = function () {
53 var _this = this;
54 this.gridApi.registerHeaderRootComp(this);
55 this.autoWidthCalculator.registerHeaderRootComp(this);
56 this.centerContainer = new headerContainer_1.HeaderContainer(this.eHeaderContainer, this.eHeaderViewport, null);
57 this.childContainers = [this.centerContainer];
58 this.pinnedLeftContainer = new headerContainer_1.HeaderContainer(this.ePinnedLeftHeader, null, column_1.Column.PINNED_LEFT);
59 this.pinnedRightContainer = new headerContainer_1.HeaderContainer(this.ePinnedRightHeader, null, column_1.Column.PINNED_RIGHT);
60 this.childContainers.push(this.pinnedLeftContainer);
61 this.childContainers.push(this.pinnedRightContainer);
62 this.childContainers.forEach(function (container) { return _this.context.wireBean(container); });
63 // shotgun way to get labels to change, eg from sum(amount) to avg(amount)
64 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_VALUE_CHANGED, this.refreshHeader.bind(this));
65 // for setting ag-pivot-on / ag-pivot-off CSS classes
66 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_PIVOT_MODE_CHANGED, this.onPivotModeChanged.bind(this));
67 this.addPreventHeaderScroll();
68 if (this.columnController.isReady()) {
69 this.refreshHeader();
70 }
71 };
72 HeaderRootComp.prototype.setHorizontalScroll = function (offset) {
73 this.eHeaderContainer.style.left = offset + 'px';
74 };
75 HeaderRootComp.prototype.forEachHeaderElement = function (callback) {
76 this.childContainers.forEach(function (childContainer) { return childContainer.forEachHeaderElement(callback); });
77 };
78 HeaderRootComp.prototype.destroy = function () {
79 this.childContainers.forEach(function (container) { return container.destroy(); });
80 };
81 HeaderRootComp.prototype.refreshHeader = function () {
82 this.childContainers.forEach(function (container) { return container.refresh(); });
83 };
84 HeaderRootComp.prototype.onPivotModeChanged = function () {
85 var pivotMode = this.columnController.isPivotMode();
86 utils_1.Utils.addOrRemoveCssClass(this.getGui(), 'ag-pivot-on', pivotMode);
87 utils_1.Utils.addOrRemoveCssClass(this.getGui(), 'ag-pivot-off', !pivotMode);
88 };
89 HeaderRootComp.prototype.setHeight = function (height) {
90 this.getGui().style.height = height + 'px';
91 this.getGui().style.minHeight = height + 'px';
92 };
93 // if the user is in floating filter and hits tab a few times, the header can
94 // end up scrolling to show items off the screen, leaving the grid and header
95 // and the grid columns no longer in sync.
96 HeaderRootComp.prototype.addPreventHeaderScroll = function () {
97 var _this = this;
98 this.addDestroyableEventListener(this.eHeaderViewport, 'scroll', function () {
99 // if the header scrolls, the header will be out of sync. so we reset the
100 // header scroll, and then scroll the body, which will in turn set the offset
101 // on the header, giving the impression that the header scrolled as expected.
102 var scrollLeft = _this.eHeaderViewport.scrollLeft;
103 if (scrollLeft !== 0) {
104 _this.gridPanel.scrollHorizontally(scrollLeft);
105 _this.eHeaderViewport.scrollLeft = 0;
106 }
107 });
108 };
109 HeaderRootComp.prototype.setLeftVisible = function (visible) {
110 utils_1.Utils.setVisible(this.ePinnedLeftHeader, visible);
111 };
112 HeaderRootComp.prototype.setRightVisible = function (visible) {
113 utils_1.Utils.setVisible(this.ePinnedRightHeader, visible);
114 };
115 HeaderRootComp.TEMPLATE = "<div class=\"ag-header\" role=\"row\">\n <div class=\"ag-pinned-left-header\" ref=\"ePinnedLeftHeader\" role=\"presentation\"></div>\n <div class=\"ag-header-viewport\" ref=\"eHeaderViewport\" role=\"presentation\">\n <div class=\"ag-header-container\" ref=\"eHeaderContainer\" role=\"presentation\"></div>\n </div>\n <div class=\"ag-pinned-right-header\" ref=\"ePinnedRightHeader\" role=\"presentation\"></div>\n </div>";
116 __decorate([
117 componentAnnotations_1.RefSelector('ePinnedLeftHeader'),
118 __metadata("design:type", HTMLElement)
119 ], HeaderRootComp.prototype, "ePinnedLeftHeader", void 0);
120 __decorate([
121 componentAnnotations_1.RefSelector('ePinnedRightHeader'),
122 __metadata("design:type", HTMLElement)
123 ], HeaderRootComp.prototype, "ePinnedRightHeader", void 0);
124 __decorate([
125 componentAnnotations_1.RefSelector('eHeaderContainer'),
126 __metadata("design:type", HTMLElement)
127 ], HeaderRootComp.prototype, "eHeaderContainer", void 0);
128 __decorate([
129 componentAnnotations_1.RefSelector('eHeaderViewport'),
130 __metadata("design:type", HTMLElement)
131 ], HeaderRootComp.prototype, "eHeaderViewport", void 0);
132 __decorate([
133 context_1.Autowired('gridOptionsWrapper'),
134 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
135 ], HeaderRootComp.prototype, "gridOptionsWrapper", void 0);
136 __decorate([
137 context_1.Autowired('columnController'),
138 __metadata("design:type", columnController_1.ColumnController)
139 ], HeaderRootComp.prototype, "columnController", void 0);
140 __decorate([
141 context_1.Autowired('context'),
142 __metadata("design:type", context_1.Context)
143 ], HeaderRootComp.prototype, "context", void 0);
144 __decorate([
145 context_1.Autowired('eventService'),
146 __metadata("design:type", eventService_1.EventService)
147 ], HeaderRootComp.prototype, "eventService", void 0);
148 __decorate([
149 context_1.Autowired('scrollVisibleService'),
150 __metadata("design:type", scrollVisibleService_1.ScrollVisibleService)
151 ], HeaderRootComp.prototype, "scrollVisibleService", void 0);
152 __decorate([
153 context_1.Autowired('gridApi'),
154 __metadata("design:type", gridApi_1.GridApi)
155 ], HeaderRootComp.prototype, "gridApi", void 0);
156 __decorate([
157 context_1.Autowired('autoWidthCalculator'),
158 __metadata("design:type", autoWidthCalculator_1.AutoWidthCalculator)
159 ], HeaderRootComp.prototype, "autoWidthCalculator", void 0);
160 __decorate([
161 context_1.PostConstruct,
162 __metadata("design:type", Function),
163 __metadata("design:paramtypes", []),
164 __metadata("design:returntype", void 0)
165 ], HeaderRootComp.prototype, "postConstruct", null);
166 __decorate([
167 context_1.PreDestroy,
168 __metadata("design:type", Function),
169 __metadata("design:paramtypes", []),
170 __metadata("design:returntype", void 0)
171 ], HeaderRootComp.prototype, "destroy", null);
172 return HeaderRootComp;
173}(component_1.Component));
174exports.HeaderRootComp = HeaderRootComp;