So here's what my page looks like when you first load it.
After switching, it looks like this.
This is code for this weirdly broken part:
ngOnInit(): void
{
$(document).ready(function() {
(<any>$("#the_table")).DataTable();
(<any>$('#selectpicker')).selectpicker();
}
if ($.isEmptyObject(this.route.snapshot.params) === false)
{
this.id = +(<any>this.route.snapshot.params).id;
}
let pass = {type: "reports"};
this.searchService.searchHttp( {type: "reports"} ).then( (response: any) =>
{
this.reports = response;
console.log(response);
});
}
Here's code for the 'search' which isn't broken.
ngOnInit(): void
{
$(document).ready(function() {
(<any>$('.selectpicker')).selectpicker();
});
this.tags = this.searchService.get_tags();
this.draw_table();
}
draw_table()
{
let json = JSON.stringify(this.tags);
this.table = (<any>$("#ajax_table")).DataTable({
"dom": 'Bfrtip',
"processing": true,
"ajax": {
"url": "app/php/search.php" + "?json=" + encodeURIComponent(json) + "&type=search",
},
"columns": [
{ "data": "id" },
{ "data": "ref" },
{ "data": "date" },
{ "data": "title" },
{ "data": "site" },
{ "data": "location" }
],
"filter": true,
"select": true,
"autoWidth": false,
"buttons": [
{
"text": "test",
action: () =>
{
console.log(table.rows( { selected: true } ).data());
let data = table.rows( { selected: true } ).data()[0];
data = (data) ? data : null;
this.router.navigate(['/main', data ]);
},
enabled: false
}
],
//"destroy": true
});
let table = this.table;
table.on( 'select', function () {
table.button(0).enable(true);
} );
table.on( 'deselect', function () {
table.button(0).enable(false);
});
}
If anyone has any idea, feel free to point it out.
Update Tried NgZone:
ngOnInit(): void
{
if ($.isEmptyObject(this.route.snapshot.params) === false)
{
this.id = +(<any>this.route.snapshot.params).id;
}
let pass = {type: "reports"};
this.searchService.searchHttp( {type: "reports"} ).then( (response: any) =>
{
this.reports = response;
console.log(response);
this.ngZone.onStable.first().subscribe( () => {
(<any>$('#selectpicker')).selectpicker();
(<any>$("#the_table")).DataTable();
});
});
}