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.

Issues with DtTrigger when rendering multiple tables

See original GitHub issue

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

What versions you are using?


- node version: 6.11.4
- angular version: 5.1.2
- angular-cli version: 1.6.3
- jquery version: 3.2.1
- datatables version: 1.10.16
- angular-datatables version: 5.0.0

Current behavior

I am trying to use multiple tables in a single view and used this Issue for reference on setup https://github.com/l-lin/angular-datatables/issues/1088

I have a dtOptions and dtTrigger in an array, an instance for each table.

@ViewChildren(DataTableDirective)
dtElements: QueryList<DataTableDirective>;
dtOptions: DataTables.Settings[] = [];
dtTrigger: Subject<any>[] = [];

ngOnInit() {
    this.dtTrigger["new"] = new Subject<any>();
    this.dtOptions["new"] = { ... };
}

<table datatable [dtOptions]="dtOptions['new']" [dtTrigger]="dtTrigger['new']"></table>

The table does not render with options. If I remove dtTrigger from the table config then the table renders as expected with options. The issue is then I cannot rerender the table because I need to call

dtTrigger.next()

but dtTrigger does not exist if I don’t include it in the table definition. If I drop the array of dtTriggers and just use a single instance of dtTrigger for testing purposes

dtTrigger: Subject<any> = new Subject<any>();

<table datatable [dtOptions]="dtOptions['new']" [dtTrigger]="dtTrigger"></table>

This also fails to render the table. So it appears there is something not working properly with using dtTrigger when using the recommended method of rendering multiple tables.

Expected behavior

Datatables should function normally, not crash when using DtTrigger

Minimal reproduction of the problem with instructions

This was a template provided from another post and i modified to show the issue. Removing the dtTrigger from the table definition allows for table rendering. Any attempt to use dtTrigger results in the table not rendering.

http://plnkr.co/edit/ntYDaywa9xZ81AQR2obP

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
epiphanizercommented, Jan 4, 2021

Hi @shanmukhateja! I ended up figuring out my issue. I will say this for anybody else who runs into this.

We were using ngOnChanges to watch for changes and update the table. ngOnChanges is pretty active in its change-detection and was responding to way more changes than we needed… I had to make sure we were setting appropriate conditionals to only listen for data changes rather than things like table height changes, etc…

The other thing I did was set a “isDtInitalized” parameter within the component class . Combined with an *ngIf on the component markup, that was also helpful.

Other things — making sure you are running the .next() call within setTimeout()… establishing a valid subscription and then clearing it, etc…

Before destroying, for some reason, i had to also run dtInstance.clear() before dtInstance.destroy() to actually remove the old data… otherwise, sorts on a changed table would sort the initial data.

All of these added up to it working just great!

0reactions
riyas145commented, Jan 30, 2021

there is any solution for render two tables in a single view ? i want to render each tables sepereatly @shanmukhateja @l-lin @epiphanizer @shohag000 @mritunjaybs1510

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is the angular Datatable not rendering? - Stack Overflow
Problem : On adding new row from child component, all rows are shown, datatabble not rendered. Parent HTML <div [hidden]="!showlist"> <table ...
Read more >
A brand new website interface for an even better experience!
Issues with DtTrigger when rendering multiple tables.
Read more >
Using Angular DataTables to build feature-rich tables
But a data table may offer multiple features, including data sorting, data querying, ... Table rendering using the custom function dtTrigger ...
Read more >
Angular 7 | How to Detect Changes And Re-Render DataTables
In this video tutorial, we will lear the process to re- render Datatable after the new product is added to the Database. We...
Read more >
Datatable Server Side in Angular doesn't populate table properly
There are some filters that are passed through the URL, so the issue isn't the data itself, but the rendering of the table....
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