import { Component , OnInit , Input , Output , EventEmitter , ViewChild , ElementRef , ViewContainerRef , ComponentFactoryResolver , ReflectiveInjector , OnChanges } from '@angular/core' ; import * as _ from "lodash" ; @ Component ( { selector : 'app-data-table' , templateUrl : './data-table.component.html' , styleUrls : [ './data-table.component.scss' ] } ) export class DataTableComponent { constructor ( ) { } @ Input ( ) config = { rowClickable : false , selectable : false , selection : [ ] , headers : [ ] , actionsComponent : null } ; @ Input ( ) data = [ ] ; @ Input ( ) parentData = { } ; @ Output ( ) onRowClick = new EventEmitter ( ) ; onRowClickInner ( $event , item , i ) { this . onRowClick . emit ( item ) ; } clickCheckbox ( $event , item ) { if ( $event . target . checked ) { this . config . selection . push ( item ) ; } else { _ . remove ( this . config . selection , ( el , index , array ) => { return el . id === item . id ; } ) ; } } clickSelectAll ( $event ) { if ( $event . target . checked ) { this . config . selection = _ . clone ( this . data ) ; } else { this . config . selection = [ ] ; } } checkboxInList ( item ) { return _ . find ( this . config . selection , { id : item . id } ) ; } }