nts-ng2-components
Version:
Paquete de componentes para Angular2 desarrollado por NITSNETS.
58 lines (48 loc) • 1.67 kB
text/typescript
import { AfterContentInit, Component, ContentChild, Input, OnChanges, TemplateRef } from '@angular/core';
import { NtsDatagridCellDirective } from '../cell/cell-variables.directive';
import { findByPath } from '../../../../utils';
export class NtsDatagridColumnComponent implements AfterContentInit, OnChanges {
title: string = null;
field: string = null;
cellClass: string = null;
width = 1;
sortable;
sort: 'asc' | 'desc';
highlightCell;
showLabels;
format = 'span';
formatOptions: Object = null;
clickPropagation = true;
customCellDirective: NtsDatagridCellDirective = null;
customCell: TemplateRef<any> = null;
path: string[];
constructor() { }
ngAfterContentInit() {
this.customCell = this.customCellDirective ? this.customCellDirective.templateRef : null;
}
ngOnChanges(changes) {
if (changes.field && this.field) {
this.path = this.field.split('.');
}
}
getValue(obj: any) {
if (this.path && this.path.length) {
return findByPath(obj, this.path);
} else { return obj[this.field]; }
}
/**
*
*
* @param {boolean} defaultValue
* @returns {boolean}
*
* @memberOf NtsDatagridColumnComponent
*/
isSortable(defaultValue: boolean): boolean {
return this.sortable === true || this.sortable === undefined && defaultValue === true ? true : false;
}
}