question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datatable not rendered when switch back from another component

See original GitHub issue

What 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kinguy1commented, Jun 6, 2018

try this:

if (this.dtTrigger.observers) { this.dtTrigger.next();}

for me it work

1reaction
awais2080commented, Jun 6, 2018

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:

@GaryBirges https://github.com/GaryBirges: unsubscribing in ngOnDestry didn’t help. error still shows.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/l-lin/angular-datatables/issues/1109#issuecomment-395058093, or mute the thread https://github.com/notifications/unsubscribe-auth/AllvamRgGeKxH0a7k1OozI9RLlDBM5Lyks5t59EmgaJpZM4Pz0T2 .

– arslan

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found