Datatable not rendered when switch back from another component
See original GitHub issueWhat versions you are using?
- node version: 6.11.3
- npm version: 3.10.10
- angular version: 4.2.4
- jquery version: 3.2.1
- datatables version: 1.10.16
- angular-datatables version: 4.2.0
- angular-cli version: 1.4.1
What’s the problem?
Hi, I am using Angular4 with angular-datatable and face the problem. That is when I am at page ‘A’ (PageACompanent) the data table is shown correctly. Then I click the routerLink to navigate to page ‘B’ (PageBComponent), and then click the routerLink to navigate back to page ‘A’ again, but this time the data table is not draw anymore.
Can you share your code?
template.html
<table datatable
[dtOptions]="dtOptions"
[dtTrigger]="dtTrigger"
class="row-border hover">
<thead>
<tr>
<th style="width: 100px; text-align:center;">No.</th>
<th>Company Name</th>
<th style="text-align:center; width: 200px;">Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let company of companyList; let i = index">
<th scope="row" style=" text-align:center;">{{ i + 1 }}</th>
<td>{{ company.companyName }}</td>
<td style="text-align: center">
<a role="button" class="btn btn-info btn-sm" routerLink="/companies/edit/{{company.$key}}">
<i class="fa fa-list align-middle" aria-hidden="true"></i>
</a>
<a role="button" class="btn btn-danger btn-sm ml-3" routerLink="/staffs">
<i class="fa fa-trash-o align-middle" aria-hidden="true"></i>
</a>
</td>
</tr>
</tbody>
</table>
myfile.ts
ngOnInit() {
this.companyObserver = this.db.list('/companies-info');
this.companyObserver.subscribe(companies => {
this.companyList = companies;
this.dtTrigger.next();
});
}
public ngOnDestroy(): void {
this.dtElement.dtInstance.then( (dtInstance: DataTables.Api) => {
console.log('destroy table');
dtInstance.destroy();
});
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:14 (1 by maintainers)
Top Results From Across the Web
How to get Datatable components rerendered upon state ...
The Datatable Component uses the redux store for rendering the table. When I add a new Customer using the AddCustomerForm I update Redux...
Read more >Google Visualization API Reference | Charts
If you change values in a DataTable after it is passed into a visualization's draw() method, the changes will not immediately change the...
Read more >Angular Material Data Table: A Complete Example
A complete example of an Angular Material Data Table with server-side pagination, sorting, filtering, as well as a loading indicator.
Read more >State saving - DataTables example
DataTables saves the state of a table (its paging position, ordering state etc). When the stateSave option is enabled, it can be restored...
Read more >Six common mistakes to avoid when using React - TinyMCE
Button'; // Import a component from another file class ... is that React can't observe and trigger re-rendering from that change because the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
try this:
if (this.dtTrigger.observers) { this.dtTrigger.next();}
for me it work
yes it did show 😦 believe me this datatable is nightmare to me
On 6 June 2018 at 17:55, Guy Gazit notifications@github.com wrote:
– arslan