UNPKG

ng2-smart-table-custom

Version:

Angular Smart Table with inline-validations support

75 lines 4.81 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Component, Input, Output, EventEmitter } from '@angular/core'; import { DataSource } from '../../lib/data-source/data-source'; import { Column } from '../../lib/data-set/column'; var FilterComponent = (function () { function FilterComponent() { this.inputClass = ''; this.filter = new EventEmitter(); this.query = ''; } FilterComponent.prototype.ngOnChanges = function (changes) { var _this = this; if (changes.source) { if (!changes.source.firstChange) { this.dataChangedSub.unsubscribe(); } this.dataChangedSub = this.source.onChanged().subscribe(function (dataChanges) { var filterConf = _this.source.getFilter(); if (filterConf && filterConf.filters && filterConf.filters.length === 0) { _this.query = ''; // add a check for existing filters an set the query if one exists for this column // this covers instances where the filter is set by user code while maintaining existing functionality } else if (filterConf && filterConf.filters && filterConf.filters.length > 0) { filterConf.filters.forEach(function (k, v) { if (k.field == _this.column.id) { _this.query = k.search; } }); } }); } }; FilterComponent.prototype.onFilter = function (query) { this.source.addFilter({ field: this.column.id, search: query, filter: this.column.getFilterFunction(), }); }; return FilterComponent; }()); __decorate([ Input(), __metadata("design:type", Column) ], FilterComponent.prototype, "column", void 0); __decorate([ Input(), __metadata("design:type", DataSource) ], FilterComponent.prototype, "source", void 0); __decorate([ Input(), __metadata("design:type", String) ], FilterComponent.prototype, "inputClass", void 0); __decorate([ Output(), __metadata("design:type", Object) ], FilterComponent.prototype, "filter", void 0); FilterComponent = __decorate([ Component({ selector: 'ng2-smart-table-filter', styles: [":host .ng2-smart-filter /deep/ input,:host .ng2-smart-filter /deep/ select{width:100%;line-height:normal;padding:.375em .75em;font-weight:400}:host .ng2-smart-filter /deep/ input[type=search]{box-sizing:inherit}:host .ng2-smart-filter /deep/ .completer-dropdown-holder{font-weight:400}:host .ng2-smart-filter /deep/ a{font-weight:400} /*# sourceMappingURL=filter.component.css.map */ "], template: "\n <div class=\"ng2-smart-filter\" *ngIf=\"column.isFilterable\" [ngSwitch]=\"column.getFilterType()\">\n <select-filter *ngSwitchCase=\"'list'\"\n [query]=\"query\"\n [ngClass]=\"inputClass\"\n [column]=\"column\"\n (filter)=\"onFilter($event)\">\n </select-filter>\n <checkbox-filter *ngSwitchCase=\"'checkbox'\"\n [query]=\"query\"\n [ngClass]=\"inputClass\"\n [column]=\"column\"\n (filter)=\"onFilter($event)\">\n </checkbox-filter>\n <completer-filter *ngSwitchCase=\"'completer'\"\n [query]=\"query\"\n [ngClass]=\"inputClass\"\n [column]=\"column\"\n (filter)=\"onFilter($event)\">\n </completer-filter>\n <input-filter *ngSwitchDefault\n [query]=\"query\"\n [ngClass]=\"inputClass\"\n [column]=\"column\"\n (filter)=\"onFilter($event)\">\n </input-filter>\n </div>\n ", }) ], FilterComponent); export { FilterComponent }; //# sourceMappingURL=filter.component.js.map