UNPKG

ng2-stable-nxtc

Version:

Angular Smart Table neXtCode Version

84 lines 4.1 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'; let TitleComponent = class TitleComponent { constructor() { this.currentDirection = ''; this.sort = new EventEmitter(); } ngOnInit() { this.titleDefaultClass = this.column.isSortable ? "ng2-smart-sort-link sort" : "ng2-smart-sort"; } ngOnChanges(changes) { if (changes.source) { if (!changes.source.firstChange) { this.dataChangedSub.unsubscribe(); } this.dataChangedSub = this.source.onChanged().subscribe((dataChanges) => { const sortConf = this.source.getSort(); if (sortConf.length > 0 && sortConf[0]['field'] === this.column.id) { this.currentDirection = sortConf[0]['direction']; } else { this.currentDirection = ''; } sortConf.forEach((fieldConf) => { }); }); } } _sort(event) { event.preventDefault(); this.changeSortDirection(); this.source.setSort([ { field: this.column.id, direction: this.currentDirection, compare: this.column.getCompareFunction(), }, ]); this.sort.emit(null); } changeSortDirection() { if (this.currentDirection) { const newDirection = this.currentDirection === 'asc' ? 'desc' : 'asc'; this.currentDirection = newDirection; } else { this.currentDirection = this.column.sortDirection; } return this.currentDirection; } }; __decorate([ Input(), __metadata("design:type", Column) ], TitleComponent.prototype, "column", void 0); __decorate([ Input(), __metadata("design:type", DataSource) ], TitleComponent.prototype, "source", void 0); __decorate([ Output(), __metadata("design:type", Object) ], TitleComponent.prototype, "sort", void 0); TitleComponent = __decorate([ Component({ selector: 'ng2-smart-table-title', styles: ["a.sort.asc,a.sort.desc{font-weight:700}a.sort.asc::after,a.sort.desc::after{content:'';display:inline-block;width:0;height:0;border-bottom:4px solid rgba(0,0,0,.3);border-top:4px solid transparent;border-left:4px solid transparent;border-right:4px solid transparent;margin-bottom:2px}a.sort.desc::after{-webkit-transform:rotate(-180deg);transform:rotate(-180deg);margin-bottom:-2px} /*# sourceMappingURL=title.component.css.map */ "], template: "<div *ngIf=\"column.preTitle\" [innerHTML]=\"column.preTitle\"></div><a href=\"#\" *ngIf=\"column.isSortable\" (click)=\"_sort($event, column)\" class=\"{{ this.titleDefaultClass }}\" [ngClass]=\"currentDirection\">{{ column.title }} </a><span class=\"{{ this.titleDefaultClass }}\" *ngIf=\"!column.isSortable\">{{ column.title }}</span><div *ngIf=\"column.posTitle\" [innerHTML]=\"column.posTitle\"></div>", }) ], TitleComponent); export { TitleComponent }; //# sourceMappingURL=title.component.js.map