I'm trying to work with Jquery DataTable on angular 2 app, I've installed it successfully but still not work and I don't know why !
here is my component.ts file code:
import {Component, ElementRef, OnInit} from '@angular/core';
import {Injectable } from '@angular/core';
import {Http, Response} from '@angular/http';
const $ = require('jquery');
const dt = require ('datatables.net');
@Component({
selector: 'app-cartographie',
templateUrl: './cartographie.component.html',
styleUrls: ['./cartographie.component.css', '../../../../node_modules/datatables.net-dt/css/jquery.dataTables.css']
})
export class CartographieComponent implements OnInit {
public data;
rootNode: any;
constructor(rootNode: ElementRef, private http: Http) {
this.rootNode = rootNode;
}
ngOnInit() {
this.getData();
const el = $(this.rootNode.nativeElement).find('#example')[0];
$('#example').DataTable();
}
private getData() {
this.http.get('http://localhost/ang.php/')
.subscribe(res => this.data = res.json());
}
}
and here is the component.html file code :
<div class="container">
<div class="panel">
<div class="panel-heading">
<div class="panel-title text-center">
<h3>Cartographie</h3>
</div>
</div>
<div class="panel-body">
</div>
<div class="row">
<div class="col lg-12">
<div class="example ">
<table class="table table-striped display" id="example" >
<thead >
<tr>
<th>Nom du poste</th>
<th>Emploie</th>
<th>Metier</th>
<th>Famile</th>
</tr>
</thead>
<tbody *ngFor="let grid of data">
<tr class="gradeA">
<td>{{ grid.NomDuPoste}}</td>
<td>{{ grid.Emploie}}</td>
<td>{{ grid.Metier }}</td>
<td>{{grid.Famille}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
the search and number of data displayed not working. PS: my data coming from php script.
here is a screenshot : http://hpics.li/efa3c31