UNPKG

5.26 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 context_1 = require("../context/context");
19var filterManager_1 = require("../filter/filterManager");
20var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
21var FilterService = (function () {
22 function FilterService() {
23 }
24 FilterService.prototype.postConstruct = function () {
25 this.doingTreeData = this.gridOptionsWrapper.isTreeData();
26 };
27 FilterService.prototype.filterAccordingToColumnState = function (rowNode) {
28 var filterActive = this.filterManager.isAnyFilterPresent();
29 this.filter(rowNode, filterActive);
30 };
31 FilterService.prototype.filter = function (rowNode, filterActive) {
32 var _this = this;
33 // recursively get all children that are groups to also filter
34 if (rowNode.hasChildren()) {
35 rowNode.childrenAfterGroup.forEach(function (node) { return _this.filter(node, filterActive); });
36 // result of filter for this node
37 if (filterActive) {
38 rowNode.childrenAfterFilter = rowNode.childrenAfterGroup.filter(function (childNode) {
39 // a group is included in the result if it has any children of it's own.
40 // by this stage, the child groups are already filtered
41 var passBecauseChildren = childNode.childrenAfterFilter && childNode.childrenAfterFilter.length > 0;
42 // both leaf level nodes and tree data nodes have data. these get added if
43 // the data passes the filter
44 var passBecauseDataPasses = childNode.data && _this.filterManager.doesRowPassFilter(childNode);
45 // note - tree data nodes pass either if a) they pass themselves or b) any children of that node pass
46 return passBecauseChildren || passBecauseDataPasses;
47 });
48 }
49 else {
50 // if not filtering, the result is the original list
51 rowNode.childrenAfterFilter = rowNode.childrenAfterGroup;
52 }
53 this.setAllChildrenCount(rowNode);
54 }
55 else {
56 rowNode.childrenAfterFilter = rowNode.childrenAfterGroup;
57 rowNode.setAllChildrenCount(null);
58 }
59 };
60 FilterService.prototype.setAllChildrenCountTreeData = function (rowNode) {
61 // for tree data, we include all children, groups and leafs
62 var allChildrenCount = 0;
63 rowNode.childrenAfterFilter.forEach(function (child) {
64 // include child itself
65 allChildrenCount++;
66 // include children of children
67 allChildrenCount += child.allChildrenCount;
68 });
69 rowNode.setAllChildrenCount(allChildrenCount);
70 };
71 FilterService.prototype.setAllChildrenCountGridGrouping = function (rowNode) {
72 // for grid data, we only count the leafs
73 var allChildrenCount = 0;
74 rowNode.childrenAfterFilter.forEach(function (child) {
75 if (child.group) {
76 allChildrenCount += child.allChildrenCount;
77 }
78 else {
79 allChildrenCount++;
80 }
81 });
82 rowNode.setAllChildrenCount(allChildrenCount);
83 };
84 FilterService.prototype.setAllChildrenCount = function (rowNode) {
85 if (this.doingTreeData) {
86 this.setAllChildrenCountTreeData(rowNode);
87 }
88 else {
89 this.setAllChildrenCountGridGrouping(rowNode);
90 }
91 };
92 __decorate([
93 context_1.Autowired('filterManager'),
94 __metadata("design:type", filterManager_1.FilterManager)
95 ], FilterService.prototype, "filterManager", void 0);
96 __decorate([
97 context_1.Autowired('gridOptionsWrapper'),
98 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
99 ], FilterService.prototype, "gridOptionsWrapper", void 0);
100 __decorate([
101 context_1.PostConstruct,
102 __metadata("design:type", Function),
103 __metadata("design:paramtypes", []),
104 __metadata("design:returntype", void 0)
105 ], FilterService.prototype, "postConstruct", null);
106 FilterService = __decorate([
107 context_1.Bean("filterService")
108 ], FilterService);
109 return FilterService;
110}());
111exports.FilterService = FilterService;