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.

dt-instance directive not working for controllerAs

See original GitHub issue

vm.dtInstance is not set after the table is rendered – all other vm.<whatever’> work

html

<div class="vers1 v1-booklets-booklets" ng-controller="BookletsBookletsListCtrl as vm">
    <table id="v1-booklets-booklets" datatable="" dt-options="vm.dtOptions" dt-columns="vm.dtColumns" class="{{vm.dtClasses}}" dt-instance="vm.dtInstance"></table>
    <div class="hide-remove"><action-icon-set id="TAB-Booklets" class="dataTables_actionIcons" data-entity-id="41" data-entity-type="booklet" actions="refreshTable,newBooklet"/></div>
</div>

javascript

            vm.dtInstance.reloadData();

TypeError: Cannot read property ‘reloadData’ of undefined at booklets-booklets-list.js:94 at Scope.parent.$get.Scope.$emit (angular.js:14793) at angular-action-icons.js:117

I have to use the old method – and I get warned

angular.js:11699 “DTInstances.getLast()” and “DTInstances.getList()” are deprecated! Use the “dt-instance” to provide the datatables instance. See https://l-lin.github.com/angular-datatables/#/manipulatingDTInstances for more information.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
dashawkcommented, Jul 6, 2015

Try to use Fetching DataTable Instances.

You can implement it:

angular.module('myApp', []).controller('myController', [function () {
    vm.dtInstance = {};

    vm.dtOptions = ...;
    vm.dtColumns = ...;

    vm.dtIntanceCallback = function (instance) {
        vm.dtInstance = instance;
    }

    // You should be able to get the table instance
    console.log(vm.dtInstance);
}]);

And in your html…

<table
    datatable
    dt-options="vm.dtOptions"
    dt-columns="vm.dtColumns"
    dt-instance="vm.dtInstanceCallback"
    class="row-border hover">
</table>

Hope this helps…

1reaction
alessandroasqcommented, May 29, 2016

This is the solution:

js: vm.dtInstance = {};

vm.dtInstanceCallback = function(_dtInstance) { vm.dtInstance = _dtInstance; vm.dtInstance.reloadData(); //or something else… }

html: dt-instance=“vm.dtInstanceCallback”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular DataTable not populating DTInstance - Stack Overflow
I was able to fix it by this https://github.com/l-lin/angular-datatables/issues/365. The problem was due to I initialized the dataHolder ...
Read more >
angular-datatables - npm
Start using angular-datatables in your project by running `npm i ... You can use the directive dt-instance where you provide a variable that ......
Read more >
Server side processing and sending additional params
I'm initially loading the table below with some default data. ... I've sent back to it and then reload datatable, but this isn't...
Read more >
fb-angular-datatables - NPM Package Overview - Socket - Socket.dev
Angular module that provides a datatable directive along with datatable options ... Socket installs a Github app to automatically flag issues on every...
Read more >
DataTables, AngularJS, and Django | Stacks & Q's - Qualtrics
You can introduce the White Noise module into your code to solve this problem. First, import it in your wsgi.py file, by adding...
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