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.

dtInstance doesn't exist on dtElement [the angular way]

See original GitHub issue

I’m submitting a…


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

What versions you are using?


- angular version: 4.4.6
- angular-datatables version: 4.4.1

Hi there, I’m trying to reproduce the behavior shown in this example. The issue that I’m dealing with is located here:

      this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
         dtInstance.destroy();
         this.dtTrigger.next();
      });

Where dtInstance doesn’t exist on dtElement. Any idea of what I could be missing?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
l-lincommented, Dec 16, 2017

The annotation @ViewChild(DataTableDirective) must be just above your variable…

@ViewChild(DataTableDirective)
dtElement: DataTableDirective;

It’s a metadata for you variable. Its placement is important…

2reactions
bmdatlcommented, Jan 7, 2018

@l-lin Thank you for the reply. I actually figured that out a couple days ago after a lot of experimenting. Ultimately, instead of using @ViewChild, since I had two datatables in my component, I had to do the following to get access to both of the tables:

@ViewChildren(DataTableDirective)
    tables: QueryList<DataTableDirective>;

Then, because only one of the tables needs to be rerendered, I only put the [dtTrigger] attribute on that table and called this in my controller function:

getSetCards(code: string, name: string) {
    this.cardService.getCardsBySet(code)
      .subscribe(cards => {
        let retrievedCards = [];
        for (let card of cards) {
            retrievedCards.push(new Card(card));
        }

        if (!this.setCards) {
          this.setCards = retrievedCards;
          this.setCards['currentSet'] = name;
          setTimeout(() => {
            this.trigger.next();
          });
        } else {
          this.tables.forEach(table => {
            if (table.dtTrigger) {
              table.dtInstance.then((dt: DataTables.Api) => {
                dt.destroy();
                this.setCards = retrievedCards;
                this.setCards['currentSet'] = name;
                setTimeout(() => {
                  this.trigger.next();
                });
              });
            }
          });
        }
      });
    return false;
  }

I ended up having to use setTimeout() because my data is asynchronous. Now it works as expected

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Dtinstance Doesnt Exist On Dtelement (forked)
example for dtInstance doesn't exist on dtElement in angular-datatables.
Read more >
re-initialize angular 6 datatable shows this.dtElement undefined
Here is my solution, the order of ViewChild/dtElement/... is ... dtElement: DataTableDirective; dtOptions: any = {}; dtInstance: DataTables.
Read more >
Error on api.rows().select() method angular datatables
i execute the next code: dtInstance.clear(); console.log("--Limpiando tabla--") //Destroying the table dtInstance.destroy(); //Calling dtTrigger ...
Read more >
cannot read properties of undefined (reading 'dtinstance')
I am trying to add a new button to datatable DOM in angular using renderer2. But its triggering an error in runtime saying....
Read more >
Datatable Server Side in Angular doesn't populate table properly
dtElement.dtInstance.then((dtInstance: DataTables.Api) => { dtInstance.destroy(); this.dtTrigger.next(); }); } catch (err) { console.log(err); } }.
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