import { Component , OnInit , ViewChild } from '@angular/core' ; import { DataTableDirective } from 'angular-datatables' ; @ Component ( { selector : 'app-dt-instance' , templateUrl : 'dt-instance.component.html' } ) export class DtInstanceComponent implements OnInit { pageTitle = 'Getting the DataTable instance' ; mdIntro = 'assets/docs/advanced/dt-instance/intro.md' ; mdHTML = 'assets/docs/advanced/dt-instance/source-html.md' ; mdTS = 'assets/docs/advanced/dt-instance/source-ts.md' ; @ ViewChild ( DataTableDirective , { static : false } ) datatableElement : DataTableDirective ; dtOptions : DataTables . Settings = { } ; displayToConsole ( datatableElement ) { datatableElement . dtInstance . then ( ( dtInstance ) => console . log ( dtInstance ) ) ; } ngOnInit ( ) { this . dtOptions = { ajax : 'data/data.json' , columns : [ { title : 'ID' , data : 'id' } , { title : 'First name' , data : 'firstName' } , { title : 'Last name' , data : 'lastName' } ] } ; } }