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.

Add the possibility to provide an object or a callback function to fetch the DT instance

See original GitHub issue

Instead of using DTInstances service (which caused more headaches than expected 😞 ), one solution is to create another directive dt-instance in which it will be possible to provide a variable that angular-datatables will populate with the DT directive instance. One example:

<div ng-controller="ShowCaseCtrl as showCase">
    <table datatable
           dt-options="showCase.dtOptions"
           dt-instance="showCase.dtInstance">
    </table>
</div>
angular.controller('ShowCaseCtrl ', ShowCaseCtrl );
function ShowCaseCtrl(DTOptionsBuilder) {
    var vm = this;
    vm.dtInstance = {}; // This will be set automatically with the two-way data binding
    vm.dtOptions = DTOptionsBuilder.fromSource('data.json');
}

The user should also have the possibility to set a callback function instead of a variable:

<div ng-controller="ShowCaseCtrl as showCase">
    <table datatable
           dt-options="showCase.dtOptions" 
           dt-instance="showCase.dtInstanceCallback">
    </table>
</div>
angular.controller('ShowCaseCtrl ', ShowCaseCtrl );
function ShowCaseCtrl(DTOptionsBuilder) {
    var vm = this;
    vm.dtInstances = [];
    vm.dtOptions = DTOptionsBuilder.fromSource('data.json');
    vm.dtInstanceCallback = dtInstanceCallback;

    function dtInstanceCallback(dtInstance) {
        vm.dtInstances.push(dtInstance);
    }
}

Note: This enhancement will completely replace the DTInstances service. So expect the removal of the DTInstances service in the v0.5.0+ versions!!!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Rocky-Lcommented, May 8, 2017

I followed lin’s code and trying to use

vm.dtInstace.reloadData()

I’ve got this warning and the data is not reloaded.

The Angular Renderer does not support reloading data. You need to do it directly on your model

0reactions
iscluisecommented, Nov 23, 2016
  • Error add datatable, is error message

angular.js:13920 TypeError: $elem.hide is not a function at Object.showLoading (http://localhost:3000/bower_components/angular-datatables/dist/angular-datatables.js:1318:15) at ControllerDirective.showLoading (http://localhost:3000/bower_components/angular-datatables/dist/angular-datatables.js:496:31) at Object.postLink (http://localhost:3000/bower_components/angular-datatables/dist/angular-datatables.js:482:18) at http://localhost:3000/bower_components/angular/angular.js:1247:18 at http://localhost:3000/bower_components/angular/angular.js:9928:44 at invokeLinkFn (http://localhost:3000/bower_components/angular/angular.js:9934:9) at nodeLinkFn (http://localhost:3000/bower_components/angular/angular.js:9335:11) at compositeLinkFn (http://localhost:3000/bower_components/angular/angular.js:8620:13) at compositeLinkFn (http://localhost:3000/bower_components/angular/angular.js:8623:13) at compositeLinkFn (http://localhost:3000/bower_components/angular/angular.js:8623:13)

Read more comments on GitHub >

github_iconTop Results From Across the Web

drawCallback - DataTables
This callback is designed for exactly that purpose and will execute on every draw. Type. function drawCallback( settings ). Parameters: Name, Type, Optional ......
Read more >
Part 3. Basic Callbacks | Dash for Python Documentation | Plotly
Dash apps are made interactive through Dash Callbacks: chainable functions that are automatically called whenever a UI element is changed.
Read more >
Rendering Datatable from callback function - Dash
For instance, my callback functions return plots, charts and I am looking to return Datatable. I am able to do render pandas dataframe...
Read more >
Create Callbacks for Graphics Objects - MATLAB & Simulink
To create a callback, first define a callback function with the required input arguments. Then, assign a handle to the function to the...
Read more >
DT: An R interface to the DataTables library - GitHub Pages
The R package DT provides an R interface to the JavaScript library DataTables. R data objects (matrices or data frames) can be displayed...
Read more >

github_iconTop Related Medium Post

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