UNPKG

8.2 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 rowNode_1 = require("../entities/rowNode");
30var utils_1 = require("../utils");
31var context_1 = require("../context/context");
32var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
33var events_1 = require("../events");
34var eventService_1 = require("../eventService");
35var gridApi_1 = require("../gridApi");
36var columnApi_1 = require("../columnController/columnApi");
37var CheckboxSelectionComponent = (function (_super) {
38 __extends(CheckboxSelectionComponent, _super);
39 function CheckboxSelectionComponent() {
40 return _super.call(this, "<span class=\"ag-selection-checkbox\"/>") || this;
41 }
42 CheckboxSelectionComponent.prototype.createAndAddIcons = function () {
43 this.eCheckedIcon = utils_1.Utils.createIconNoSpan('checkboxChecked', this.gridOptionsWrapper, this.column);
44 this.eUncheckedIcon = utils_1.Utils.createIconNoSpan('checkboxUnchecked', this.gridOptionsWrapper, this.column);
45 this.eIndeterminateIcon = utils_1.Utils.createIconNoSpan('checkboxIndeterminate', this.gridOptionsWrapper, this.column);
46 var element = this.getGui();
47 element.appendChild(this.eCheckedIcon);
48 element.appendChild(this.eUncheckedIcon);
49 element.appendChild(this.eIndeterminateIcon);
50 };
51 CheckboxSelectionComponent.prototype.onDataChanged = function () {
52 // when rows are loaded for the second time, this can impact the selection, as a row
53 // could be loaded as already selected (if user scrolls down, and then up again).
54 this.onSelectionChanged();
55 };
56 CheckboxSelectionComponent.prototype.onSelectableChanged = function () {
57 this.showOrHideSelect();
58 };
59 CheckboxSelectionComponent.prototype.onSelectionChanged = function () {
60 var state = this.rowNode.isSelected();
61 utils_1.Utils.setVisible(this.eCheckedIcon, state === true);
62 utils_1.Utils.setVisible(this.eUncheckedIcon, state === false);
63 utils_1.Utils.setVisible(this.eIndeterminateIcon, typeof state !== 'boolean');
64 };
65 CheckboxSelectionComponent.prototype.onCheckedClicked = function () {
66 var groupSelectsFiltered = this.gridOptionsWrapper.isGroupSelectsFiltered();
67 var updatedCount = this.rowNode.setSelectedParams({ newValue: false, groupSelectsFiltered: groupSelectsFiltered });
68 return updatedCount;
69 };
70 CheckboxSelectionComponent.prototype.onUncheckedClicked = function (event) {
71 var groupSelectsFiltered = this.gridOptionsWrapper.isGroupSelectsFiltered();
72 var updatedCount = this.rowNode.setSelectedParams({ newValue: true, rangeSelect: event.shiftKey, groupSelectsFiltered: groupSelectsFiltered });
73 return updatedCount;
74 };
75 CheckboxSelectionComponent.prototype.onIndeterminateClicked = function (event) {
76 var result = this.onUncheckedClicked(event);
77 if (result === 0) {
78 this.onCheckedClicked();
79 }
80 };
81 CheckboxSelectionComponent.prototype.init = function (params) {
82 this.rowNode = params.rowNode;
83 this.column = params.column;
84 this.createAndAddIcons();
85 this.onSelectionChanged();
86 // we don't want the row clicked event to fire when selecting the checkbox, otherwise the row
87 // would possibly get selected twice
88 this.addGuiEventListener('click', function (event) { return utils_1.Utils.stopPropagationForAgGrid(event); });
89 // likewise we don't want double click on this icon to open a group
90 this.addGuiEventListener('dblclick', function (event) { return utils_1.Utils.stopPropagationForAgGrid(event); });
91 this.addDestroyableEventListener(this.eCheckedIcon, 'click', this.onCheckedClicked.bind(this));
92 this.addDestroyableEventListener(this.eUncheckedIcon, 'click', this.onUncheckedClicked.bind(this));
93 this.addDestroyableEventListener(this.eIndeterminateIcon, 'click', this.onIndeterminateClicked.bind(this));
94 this.addDestroyableEventListener(this.rowNode, rowNode_1.RowNode.EVENT_ROW_SELECTED, this.onSelectionChanged.bind(this));
95 this.addDestroyableEventListener(this.rowNode, rowNode_1.RowNode.EVENT_DATA_CHANGED, this.onDataChanged.bind(this));
96 this.addDestroyableEventListener(this.rowNode, rowNode_1.RowNode.EVENT_SELECTABLE_CHANGED, this.onSelectableChanged.bind(this));
97 this.isRowSelectableFunc = this.gridOptionsWrapper.getIsRowSelectableFunc();
98 var checkboxVisibleIsDynamic = this.isRowSelectableFunc || this.checkboxCallbackExists();
99 if (checkboxVisibleIsDynamic) {
100 this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_DISPLAYED_COLUMNS_CHANGED, this.showOrHideSelect.bind(this));
101 this.showOrHideSelect();
102 }
103 };
104 CheckboxSelectionComponent.prototype.showOrHideSelect = function () {
105 // if the isRowSelectable() is not provided the row node is selectable by default
106 var selectable = this.rowNode.selectable;
107 // checkboxSelection callback is deemed a legacy solution however we will still consider it's result.
108 // If selectable, then also check the colDef callback. if not selectable, this it short circuits - no need
109 // to call the colDef callback.
110 if (selectable && this.checkboxCallbackExists()) {
111 selectable = this.column.isCellCheckboxSelection(this.rowNode);
112 }
113 // show checkbox if both conditions are true
114 this.setVisible(selectable);
115 };
116 CheckboxSelectionComponent.prototype.checkboxCallbackExists = function () {
117 // column will be missing if groupUseEntireRow=true
118 var colDef = this.column ? this.column.getColDef() : null;
119 return colDef && typeof colDef.checkboxSelection === 'function';
120 };
121 __decorate([
122 context_1.Autowired('gridOptionsWrapper'),
123 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
124 ], CheckboxSelectionComponent.prototype, "gridOptionsWrapper", void 0);
125 __decorate([
126 context_1.Autowired('eventService'),
127 __metadata("design:type", eventService_1.EventService)
128 ], CheckboxSelectionComponent.prototype, "eventService", void 0);
129 __decorate([
130 context_1.Autowired('gridApi'),
131 __metadata("design:type", gridApi_1.GridApi)
132 ], CheckboxSelectionComponent.prototype, "gridApi", void 0);
133 __decorate([
134 context_1.Autowired('columnApi'),
135 __metadata("design:type", columnApi_1.ColumnApi)
136 ], CheckboxSelectionComponent.prototype, "columnApi", void 0);
137 return CheckboxSelectionComponent;
138}(component_1.Component));
139exports.CheckboxSelectionComponent = CheckboxSelectionComponent;